File size: 1,881 Bytes
cac9eab 24b72ba 1813aa1 3bab3d6 207613f 3bab3d6 f2703c6 3bab3d6 5ebf920 3bab3d6 bb837d7 1813aa1 3bab3d6 1813aa1 3bab3d6 1c8ff11 3bab3d6 207613f 3bab3d6 889c3ab 3bab3d6 1c8ff11 5ebf920 1c8ff11 0469b37 5ebf920 862456a 1813aa1 3bab3d6 |
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 |
import streamlit as st
import openai
def main():
st.title("Blog Post Idea and Outline Generator")
openai.api_key = st.secrets["OPENAI_API_KEY"]
blog_topic = st.text_input("Enter your blog topic:", value="", placeholder="e.g., Artificial Intelligence in Healthcare")
target_audience = st.text_input("Describe your target audience:", value="", placeholder="e.g., healthcare professionals")
post_length = st.selectbox("Choose the length of your blog post:", ['Short (500 words)', 'Medium (1000 words)', 'Long (1500+ words)'])
if st.button('Generate Blog Post Ideas and Outlines'):
response = generate_blog_ideas_and_outlines(blog_topic, target_audience, post_length)
if response:
st.subheader("Suggested Blog Post Ideas and Outlines:")
st.write(response)
else:
st.error("Failed to generate blog post ideas and outlines. Please check the inputs and try again.")
def generate_blog_ideas_and_outlines(topic, audience, length):
try:
prompt_text = f"""As an expert content strategist and writer, create 5 unique blog post ideas on the topic of {topic} for {audience}. For each idea, provide a brief outline suitable for a {length} post. Each outline should include:
1. An attention-grabbing title
2. 3-5 main sections with brief descriptions
3. A concluding thought or call-to-action
Ensure that each idea is distinct and tailored to the interests and needs of the target audience."""
response = openai.ChatCompletion.create(
model="gpt-4",
messages=[{"role": "system", "content": prompt_text}],
max_tokens=1000
)
return response.choices[0].message['content']
except Exception as e:
st.error(f"An error occurred: {str(e)}")
return None
if __name__ == "__main__":
main() |