Manasa1's picture
Update app.py
2dc84b0 verified
raw
history blame
3.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()
# Access the Groq API key
groq_api_key = os.getenv("GROQ_API_KEY")
# Create the Agent
agent = Agent(
model=Groq(id="llama-3.1-8b-instant", api_key=groq_api_key),
tools=[DuckDuckGo(), Newspaper4k()],
description="You are an experienced long Article writer crafting a compelling, insightful article for an engaged audience.",
instructions=[
"Dive deep into the topic, gathering **12-15 high-quality sources**—not just mainstream news, but also research papers, expert blogs, and niche discussions.",
"Start with a **gripping hook**—a bold statement, surprising fact, or thought-provoking anecdote to immediately pull the reader in.",
"Write **with a human touch**—use natural phrasing, contractions (e.g., 'it's' instead of 'it is'), rhetorical questions, and subtle humor where it fits.",
"Move beyond summarization—offer **unique insights**, make unexpected connections, and challenge mainstream narratives where applicable.",
"Maintain a **conversational yet authoritative** tone—explain concepts as if discussing with an informed but curious reader, avoiding robotic phrasing.",
"Weave in **storytelling elements**: real-world examples, case studies, and expert quotes to make the topic relatable and engaging.",
"Break down complex ideas **clearly and vividly**—use analogies, step-by-step explanations, and comparisons to simplify technical concepts.",
"Vary your sentence structure—blend short, impactful lines with longer, more nuanced ones to create an engaging flow.",
"Avoid generic transitions. Instead of 'In conclusion,' try: 'So, where does this leave us?' or 'The real question now is...'.",
"Offer **thoughtful analysis and subtle opinions**—not just raw facts, but well-reasoned takes, much like a seasoned journalist or analyst would.",
"Follow a structured format, but allow **organic flow**—let the article develop naturally rather than forcing rigid sections.",
"Use **real quotes** from industry experts where possible, with proper citations and embedded links for credibility.",
"Conclude with a **strong takeaway**—leave the reader with a compelling question, a bold prediction, or a clear next step for deeper exploration."
],
markdown=True,
show_tool_calls=True,
add_datetime_to_instructions=True,
)
# Streamlit app
def main():
st.title("NYT Article Generator")
topic = st.text_input("Enter a topic:")
if st.button("Generate Article"):
if topic:
with st.spinner("Generating article..."):
response = agent.run(topic)
st.markdown(response.content)
else:
st.warning("Please enter a topic.")
if __name__ == "__main__":
main()