Spaces:
Sleeping
Sleeping
File size: 2,979 Bytes
af81c66 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import os
from llama_index.llms.llama_api import LlamaAPI
from dotenv import load_dotenv
import requests
import streamlit as st
load_dotenv()
def get_blogcontent_response(topic):
llm = LlamaAPI(model="llama-70b-chat",api_key=os.environ["LLAMA_API_Key"])
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")
print(resp.text)
#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")
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")
# 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")
title = respfinal.text.split('Title:')[1].split('Introduction:')[0]
introduction = respfinal.text.split('Introduction:')[1]
# Replace these values with your own
title = title
content = introduction
response = create_medium_post(title, content,os.environ["Medium_Access_Token"])
return response
def create_medium_post(title, content, integration_token):
userid = os.environ["UserId"]
endpoint = f"https://api.medium.com/v1/users/{userid}/posts"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {integration_token}",
}
data = {
"title": title,
"contentFormat": "markdown",
"content": content,
"publishStatus": "public", # Change to "public" when ready to publish
}
try:
response = requests.post(endpoint, headers=headers, json=data)
response.raise_for_status()
print("Post created successfully!")
except requests.exceptions.HTTPError as err:
print(f"Error creating post: {err}")
print(response.text)
return response.text
st.set_page_config(page_title="Auto Blog Posting")
st.header("Auto Blog Posting Application")
input = st.text_input("Topic: ",key="topic")
submit = st.button("Enter the topic")
if submit:
response = get_blogcontent_response(input)
st.write(response)
|