Spaces:
Sleeping
Sleeping
SreedeviBDP
commited on
Commit
•
af81c66
1
Parent(s):
c0aebae
Upload 2 files
Browse files- app.py +62 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from llama_index.llms.llama_api import LlamaAPI
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import requests
|
5 |
+
import streamlit as st
|
6 |
+
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
def get_blogcontent_response(topic):
|
10 |
+
llm = LlamaAPI(model="llama-70b-chat",api_key=os.environ["LLAMA_API_Key"])
|
11 |
+
resp = llm.complete(f"use this phrase {topic} identify the top 5 keywords,search queries with rank high on Google search and Extract five keywords from the list in the format of keyword1,keyword2,keyword3,keyword4,keyword5")
|
12 |
+
print(resp.text)
|
13 |
+
#respfinal = llm.complete(f"craft a blog on {inputPromt} get the information from various sources,frame the title,Introduction, using the {resp.text},elaborate on the topic about 500 words,conclusion and website links of sources included as references")
|
14 |
+
respfinal = llm.complete(f"Create a blog post about {topic}. Use transition words. Use active voice. Write over 1000 words. The blog post should be in a beginners guide style. Add title,Introduction and subtitle for each section. It should have a minimum of 6 sections.Include the following keywords: {resp.text}. Create a good slug for this post and a meta description with a maximum of 100 words. and add it to the end of the blog post, add reference website links")
|
15 |
+
# respfinal = llm.complete(f"I want you to become a famous blog writer and craft a blog on {inputPromt} get the information from various sources,frame the title,Introduction, using the {resp.text},elaborate on the topic about 500 words,conclusion and website links of sources included as references")
|
16 |
+
title = respfinal.text.split('Title:')[1].split('Introduction:')[0]
|
17 |
+
introduction = respfinal.text.split('Introduction:')[1]
|
18 |
+
# Replace these values with your own
|
19 |
+
title = title
|
20 |
+
content = introduction
|
21 |
+
response = create_medium_post(title, content,os.environ["Medium_Access_Token"])
|
22 |
+
return response
|
23 |
+
|
24 |
+
|
25 |
+
def create_medium_post(title, content, integration_token):
|
26 |
+
userid = os.environ["UserId"]
|
27 |
+
endpoint = f"https://api.medium.com/v1/users/{userid}/posts"
|
28 |
+
|
29 |
+
headers = {
|
30 |
+
"Content-Type": "application/json",
|
31 |
+
"Authorization": f"Bearer {integration_token}",
|
32 |
+
}
|
33 |
+
|
34 |
+
data = {
|
35 |
+
"title": title,
|
36 |
+
"contentFormat": "markdown",
|
37 |
+
"content": content,
|
38 |
+
"publishStatus": "public", # Change to "public" when ready to publish
|
39 |
+
}
|
40 |
+
|
41 |
+
try:
|
42 |
+
response = requests.post(endpoint, headers=headers, json=data)
|
43 |
+
response.raise_for_status()
|
44 |
+
print("Post created successfully!")
|
45 |
+
except requests.exceptions.HTTPError as err:
|
46 |
+
print(f"Error creating post: {err}")
|
47 |
+
print(response.text)
|
48 |
+
|
49 |
+
return response.text
|
50 |
+
|
51 |
+
st.set_page_config(page_title="Auto Blog Posting")
|
52 |
+
st.header("Auto Blog Posting Application")
|
53 |
+
input = st.text_input("Topic: ",key="topic")
|
54 |
+
submit = st.button("Enter the topic")
|
55 |
+
|
56 |
+
if submit:
|
57 |
+
response = get_blogcontent_response(input)
|
58 |
+
st.write(response)
|
59 |
+
|
60 |
+
|
61 |
+
|
62 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
llama-index-program-openai
|
2 |
+
llama-index-llms-llama-api
|
3 |
+
llama_index
|
4 |
+
huggingface_hub
|
5 |
+
python-dotenv
|
6 |
+
streamlit
|