Spaces:
Sleeping
Sleeping
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.") | |