Akshayram1 commited on
Commit
93b26a0
·
verified ·
1 Parent(s): 329ea4a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from phi.agent import Agent
3
+ from phi.model.groq import Groq
4
+ from phi.tools.duckduckgo import DuckDuckGo
5
+ from dotenv import load_dotenv
6
+ import time
7
+
8
+ # Load environment variables
9
+ load_dotenv()
10
+
11
+ # Groq API Key (Replace with your actual API key)
12
+ GROQ_API_KEY = "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"
13
+
14
+ # Web agent to fetch and summarize news
15
+ web_agent = Agent(
16
+ name="Web Agent",
17
+ model=Groq(id="llama-3.3-70b-versatile", api_key=GROQ_API_KEY),
18
+ tools=[DuckDuckGo()], # Use DuckDuckGo for web searches
19
+ instructions=[
20
+ "Search for the latest AI news.",
21
+ "Summarize the main points clearly and concisely.",
22
+ "Always include sources for all information.",
23
+ "Format the response in Markdown for clarity."
24
+ ],
25
+ show_tool_calls=True, # Enable logging of tool usage
26
+ markdown=True # Format the output in Markdown
27
+ )
28
+
29
+ # Function to fetch the latest AI news
30
+ def fetch_latest_ai_news():
31
+ # Simulating some processing delay
32
+ time.sleep(3)
33
+
34
+ query = "Find the latest news about Artificial Intelligence and summarize it."
35
+ response = web_agent.ask(query)
36
+
37
+ raw_response = str(response) # Simulating raw data for terminal-like output
38
+ processed_response = response.get('response', 'No summary available.') # Cleaned summary
39
+
40
+ return raw_response, processed_response # Return raw and processed data for side-by-side display
41
+
42
+ # Streamlit App Interface
43
+ def create_streamlit_app():
44
+ st.title("AI News Fetcher") # Title of the app
45
+ st.markdown("This app fetches and summarizes the latest AI news using AI models.")
46
+
47
+ # Add a button for triggering the process
48
+ if st.button("Generate AI News"):
49
+ with st.spinner("Fetching AI news..."):
50
+ # Get the raw and processed AI news
51
+ raw_response, processed_response = fetch_latest_ai_news()
52
+
53
+ # Display raw response (Terminal-like view)
54
+ st.subheader("Raw Data")
55
+ st.text_area("Raw Data", value=raw_response, height=300)
56
+
57
+ # Display processed (summarized) response
58
+ st.subheader("Processed Data")
59
+ st.markdown(processed_response)
60
+
61
+ # Running the Streamlit app
62
+ if __name__ == "__main__":
63
+ create_streamlit_app()