Manasa1's picture
Update app.py
47c0f46 verified
raw
history blame
2.48 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 a senior NYT researcher writing an article on a topic.",
instructions=[
"Conduct a deep search on the given topic, retrieving the top 8 most relevant and credible sources.",
"Extract and summarize key insights from each article, prioritizing depth, credibility, and originality.",
"Begin the article with a compelling hook—an intriguing fact, a question, or a short anecdote to engage the reader.",
"Provide historical or market context to frame the discussion and establish relevance.",
"Dive into a well-structured analysis using storytelling techniques, technical breakdowns, and engaging comparisons.",
"Maintain a conversational yet professional tone, making complex ideas accessible while retaining depth.",
"Incorporate nuanced perspectives, expert insights, statistics, and real-world case studies.",
"Cite sources explicitly and include links where relevant to enhance credibility.",
"Ensure the article follows a structured format: Introduction, Context, Technical Breakdown, Implications, and Conclusion.",
"The article should be **at least 1,500-2,000 words long**, with in-depth analysis and engaging storytelling elements.",
"Use Markdown formatting with subheadings, bullet points, citations, and quotes to improve readability.",
"End with a thought-provoking conclusion, summarizing key findings and leaving the reader with an open-ended insight or question."
],
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()