Manasa1's picture
Update app.py
05a27bf verified
raw
history blame
2.56 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 comprehensive search on the given topic, retrieving the top 8 most relevant sources.",
"Extract and summarize key points from each article, prioritizing credibility and depth of information.",
"Analyze the gathered insights, identifying common themes, differing perspectives, and any critical gaps.",
"Synthesize the information into a well-structured NYT-quality article with a clear introduction, body, and conclusion.",
"Maintain a journalistic tone, ensuring factual accuracy, neutrality, and a compelling narrative flow.",
"Ensure the article is **at least 1,500-2,000 words long**, incorporating detailed analysis and expert insights.",
"Include relevant statistics, expert opinions, historical context, and real-world examples to enhance credibility.",
"Expand the article by adding background information, case studies, recent developments, and potential future implications.",
"If conflicting viewpoints exist, present them objectively, providing arguments for and against while highlighting key takeaways.",
"Ensure readability by using engaging storytelling techniques, well-structured paragraphs, and natural transitions.",
"Format the article using Markdown for readability, incorporating subheadings, bullet points, citations, and quotes from sources.",
"Include a summary at the end, recapping key findings and offering potential action points or takeaways."
],
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()