File size: 1,187 Bytes
bb74076
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e760e28
bb74076
 
 
e760e28
bb74076
e760e28
 
 
 
 
 
 
bb74076
e760e28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
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")

agent = Agent(
    model=Groq(id="llama-3.3-70b-versatile", api_key=groq_api_key),
    tools=[DuckDuckGo(), Newspaper4k()],
    description="You are a senior NYT researcher writing an article on a topic.",
    instructions=[
        "For a given topic, search for the top 5 links.",
        "Then read each URL and extract the article text, if a URL isn't available, ignore it.",
        "Analyse and prepare an NYT worthy article based on the information.",
    ],
    markdown=True,
    show_tool_calls=True,
    add_datetime_to_instructions=True,
    # debug_mode=True,
)

def generate_article(topic):
    return agent.print_response(topic, stream=True)

iface = gr.Interface(
    fn=generate_article,
    inputs="text",
    outputs="text",
    title="NYT Article Generator",
    description="Enter a topic to generate an NYT-style article.",
)

iface.launch()