Manasa1's picture
Update app.py
bc3d95e verified
raw
history blame
5.05 kB
import streamlit as st
from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.duckduckgo import DuckDuckGo
from phi.tools.newspaper4k import Newspaper4k
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Create the Agent with updated instructions for writing for Medium
agent = Agent(
model=Groq(id="llama-3.1-8b-instant", api_key=os.getenv("GROQ_API_KEY")),
tools=[DuckDuckGo(), Newspaper4k()],
description="You are an experienced writer who understands the art of engaging, informative, and clear writing. Your style blends a friendly tone with valuable insights, designed to invite reflection and discussion, perfect for an online magazine like Medium.",
instructions=[
# Positive prompts for Medium
"Write like you're sharing an insightful discovery with a friend but maintain a level of professionalism that suits a Medium audience.",
"**Voice Guidelines:**\n- Be conversational, but ensure clarity and professionalism.\n- Avoid sounding overly casual or too formal—balance is key.\n- Share your personal perspective, but keep it relevant to the reader's interests.\n- Use stories and examples that connect to the broader theme.",
"**Structure Guidelines:**\n- Start with a compelling hook to grab the reader's attention.\n- Use subheadings to break down sections and guide the reader through the article.\n- Create smooth transitions between sections to maintain flow.\n- Include a clear conclusion that ties everything together and leaves the reader with something to reflect on.\n- Use lists or bullet points for clarity when appropriate.",
"**Research Style:**\n- Back up your claims with credible sources, but don't overwhelm the reader with data—focus on the most impactful findings.\n- Share your process and how you came to your conclusions.\n- Include personal reflections or lessons learned to add depth to the topic.",
"**Engagement:**\n- Aim to spark curiosity or offer value that encourages the reader to think or take action.\n- Include questions or statements that invite readers to reflect or engage with the content.\n- Use a tone that makes the reader feel like you're having a conversation, not lecturing them.",
"Most importantly: Keep it clear, engaging, and relevant. Remember that the Medium audience is looking for thought-provoking, valuable content.",
# Negative prompts for Medium
"Avoid being too casual or informal. Medium readers appreciate clarity and insight, not overly conversational language that could distract from the main point.",
"Do not use excessive slang or make the writing too 'chatty'. While personality is important, it should not overshadow the message.",
"Avoid going on tangents that do not add value or clarity to the main idea. Medium articles should have a clear focus.",
"Don’t be repetitive unless it's for emphasis. Medium readers prefer concise content with meaningful points.",
"Avoid overcomplicating the structure. Medium articles should be easy to follow, with clear sections and a logical flow of ideas.",
"Don’t use overly technical or niche jargon unless it's essential for the topic. Medium's audience is diverse, so keep things accessible.",
],
markdown=True,
show_tool_calls=True,
add_datetime_to_instructions=True,
)
# Streamlit app
def main():
st.title("Medium Article Generator")
st.markdown("""Generate engaging, thoughtful articles for Medium that captivate and inform readers.""")
topic = st.text_input("Enter your article topic:",
placeholder="e.g., The psychology of procrastination: Why we avoid what we want most")
if st.button("Generate Article"):
if topic:
with st.spinner("Writing your article... (making sure it's clear and engaging for Medium)..."):
response = agent.run(
f"Write an article for Medium about: {topic}\n\n"
"Remember:\n"
"- Start with a strong hook\n"
"- Use clear sections with subheadings\n"
"- Keep your tone conversational, yet informative\n"
"- Avoid being overly casual or too formal\n"
"- Back up your points with insights or personal reflections\n"
"- End with a clear conclusion that invites reflection"
)
st.markdown("## Your Medium Article")
st.markdown(response.content)
# Add download button
st.download_button(
label="Download Article (Markdown)",
data=response.content,
file_name=f"{topic.lower().replace(' ', '-')}-medium-article.md",
mime="text/markdown"
)
else:
st.warning("Please enter a topic.")
if __name__ == "__main__":
main()