File size: 1,918 Bytes
93b26a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80dcc88
 
 
6d4ac71
 
 
 
 
 
80dcc88
6d4ac71
 
 
 
80dcc88
 
 
 
 
 
 
 
 
 
 
 
 
6d4ac71
80dcc88
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import streamlit as st
from phi.agent import Agent
from phi.model.groq import Groq
from phi.tools.duckduckgo import DuckDuckGo
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Groq API Key (Replace with your actual API key)
GROQ_API_KEY = "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"

# Web agent to fetch and summarize news
web_agent = Agent(
    name="Web Agent",
    model=Groq(id="llama-3.3-70b-versatile", api_key=GROQ_API_KEY),
    tools=[DuckDuckGo()],  # Use DuckDuckGo for web searches
    instructions=[
        "Search for the latest AI news.",
        "Summarize the main points clearly and concisely.",
        "Always include sources for all information.",
        "Format the response in Markdown for clarity."
    ],
    show_tool_calls=True,  # Enable logging of tool usage
    markdown=True  # Format the output in Markdown
)

# Function to fetch news based on user query
def fetch_news(query):
    response = web_agent.execute(query)  # Fetch and summarize news using 'execute' method
    return response

# Streamlit App
st.title("AI News Fetcher")

st.markdown("""
Welcome to the **AI News Fetcher** app! Enter your query to find the latest summaries of AI-related news or any topic of interest.

---
""")

# User input for query
user_query = st.text_input("Enter your query:", placeholder="Find the latest news about AI, summarize advancements in robotics, etc.")

if st.button("Fetch News"):
    if user_query.strip():
        st.info("Fetching the news. This may take a few seconds...")
        try:
            news_summary = fetch_news(user_query)
            st.markdown(news_summary)  # Display the news summary in Markdown format
        except Exception as e:
            st.error(f"An error occurred: {str(e)}")
    else:
        st.warning("Please enter a valid query.")
else:
    st.write("Enter a query and click the button to fetch news.")