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 import time # 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 the latest AI news def fetch_latest_ai_news(): # Simulating some processing delay time.sleep(3) query = "Find the latest news about Artificial Intelligence and summarize it." response = web_agent.ask(query) raw_response = str(response) # Simulating raw data for terminal-like output processed_response = response.get('response', 'No summary available.') # Cleaned summary return raw_response, processed_response # Return raw and processed data for side-by-side display # Streamlit App Interface def create_streamlit_app(): st.title("AI News Fetcher") # Title of the app st.markdown("This app fetches and summarizes the latest AI news using AI models.") # Add a button for triggering the process if st.button("Generate AI News"): with st.spinner("Fetching AI news..."): # Get the raw and processed AI news raw_response, processed_response = fetch_latest_ai_news() # Display raw response (Terminal-like view) st.subheader("Raw Data") st.text_area("Raw Data", value=raw_response, height=300) # Display processed (summarized) response st.subheader("Processed Data") st.markdown(processed_response) # Running the Streamlit app if __name__ == "__main__": create_streamlit_app()