Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from phi.agent import Agent
|
3 |
+
from phi.model.groq import Groq
|
4 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
5 |
+
from phi.tools.newspaper4k import Newspaper4k
|
6 |
+
import os
|
7 |
+
from dotenv import load_dotenv
|
8 |
+
|
9 |
+
# Load environment variables
|
10 |
+
load_dotenv()
|
11 |
+
|
12 |
+
# Access the Groq API key
|
13 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
14 |
+
|
15 |
+
# Create the Agent
|
16 |
+
agent = Agent(
|
17 |
+
model=Groq(id="llama-3.3-70b-versatile", api_key=groq_api_key),
|
18 |
+
tools=[DuckDuckGo(), Newspaper4k()],
|
19 |
+
description="You are a senior NYT researcher writing an article on a topic.",
|
20 |
+
instructions=[
|
21 |
+
"For a given topic, search for the top 5 links.",
|
22 |
+
"Then read each URL and extract the article text, if a URL isn't available, ignore it.",
|
23 |
+
"Analyse and prepare an NYT worthy article based on the information.",
|
24 |
+
],
|
25 |
+
markdown=True,
|
26 |
+
show_tool_calls=True,
|
27 |
+
add_datetime_to_instructions=True,
|
28 |
+
# debug_mode=True,
|
29 |
+
)
|
30 |
+
|
31 |
+
# Streamlit app
|
32 |
+
def main():
|
33 |
+
st.title("NYT Article Generator")
|
34 |
+
topic = st.text_input("Enter a topic:")
|
35 |
+
|
36 |
+
if st.button("Generate Article"):
|
37 |
+
if topic:
|
38 |
+
with st.spinner("Generating article..."):
|
39 |
+
response = agent.run(topic)
|
40 |
+
st.markdown(response)
|
41 |
+
else:
|
42 |
+
st.warning("Please enter a topic.")
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
main()
|