Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
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 |
+
)
|
29 |
+
|
30 |
+
# Function to process input and generate an article
|
31 |
+
def generate_article(topic):
|
32 |
+
response = agent.get_response(topic)
|
33 |
+
return response
|
34 |
+
|
35 |
+
# Gradio interface
|
36 |
+
with gr.Blocks() as app:
|
37 |
+
gr.Markdown("# 📰 NYT-Style Article Generator")
|
38 |
+
gr.Markdown(
|
39 |
+
"Enter a topic below, and the app will generate an NYT-style article by searching, extracting, and summarizing information from the web."
|
40 |
+
)
|
41 |
+
|
42 |
+
with gr.Row():
|
43 |
+
topic_input = gr.Textbox(
|
44 |
+
label="Enter Topic", placeholder="e.g., Simulation Theory", lines=1
|
45 |
+
)
|
46 |
+
generate_button = gr.Button("Generate Article")
|
47 |
+
|
48 |
+
output_text = gr.Markdown(label="Generated Article")
|
49 |
+
|
50 |
+
generate_button.click(fn=generate_article, inputs=topic_input, outputs=output_text)
|
51 |
+
|
52 |
+
# Run the app
|
53 |
+
if __name__ == "__main__":
|
54 |
+
app.launch()
|