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) format = """Title: Introduction: """ respfinal = llm.complete(f"Create a blog post about {topic}.Add {format} 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") print(respfinal.text) 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}", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" } 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)