Akshayram1 commited on
Commit
6d4ac71
·
verified ·
1 Parent(s): eecba1c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -36
app.py CHANGED
@@ -3,7 +3,6 @@ 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()
@@ -26,40 +25,27 @@ web_agent = Agent(
26
  markdown=True # Format the output in Markdown
27
  )
28
 
29
- # Function to fetch the latest AI news using the correct method
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
-
36
- # Use the correct method on the Agent, likely 'run' or 'execute' instead of 'ask'
37
- response = web_agent.execute(query) # Using 'execute' or any other valid method
38
-
39
- raw_response = str(response) # Simulating raw data for terminal-like output
40
- processed_response = response.get('response', 'No summary available.') # Cleaned summary
41
-
42
- return raw_response, processed_response # Return raw and processed data for side-by-side display
43
-
44
- # Streamlit App Interface
45
- def create_streamlit_app():
46
- st.title("AI News Fetcher") # Title of the app
47
- st.markdown("This app fetches and summarizes the latest AI news using AI models.")
48
-
49
- # Add a button for triggering the process
50
- if st.button("Generate AI News"):
51
- with st.spinner("Fetching AI news..."):
52
- # Get the raw and processed AI news
53
- raw_response, processed_response = fetch_latest_ai_news()
54
-
55
- # Display raw response (Terminal-like view)
56
- st.subheader("Raw Data")
57
- st.text_area("Raw Data", value=raw_response, height=300)
58
-
59
- # Display processed (summarized) response
60
- st.subheader("Processed Data")
61
- st.markdown(processed_response)
62
-
63
- # Running the Streamlit app
64
- if __name__ == "__main__":
65
- create_streamlit_app()
 
3
  from phi.model.groq import Groq
4
  from phi.tools.duckduckgo import DuckDuckGo
5
  from dotenv import load_dotenv
 
6
 
7
  # Load environment variables
8
  load_dotenv()
 
25
  markdown=True # Format the output in Markdown
26
  )
27
 
28
+ # Function to fetch the latest AI news
29
  def fetch_latest_ai_news():
 
 
 
30
  query = "Find the latest news about Artificial Intelligence and summarize it."
31
+ response = web_agent.query(query, stream=False) # Fetch and summarize AI news
32
+ return response
33
+
34
+ # Streamlit App
35
+ st.title("AI News Fetcher")
36
+
37
+ st.markdown("""
38
+ Welcome to the **AI News Fetcher** app! This tool provides the latest summaries of AI-related news from the web.
39
+
40
+ ---
41
+ """)
42
+
43
+ if st.button("Fetch Latest AI News"):
44
+ st.info("Fetching the latest AI news. This may take a few seconds...")
45
+ try:
46
+ news_summary = fetch_latest_ai_news()
47
+ st.markdown(news_summary) # Display the news summary in Markdown format
48
+ except Exception as e:
49
+ st.error(f"An error occurred: {str(e)}")
50
+ else:
51
+ st.write("Click the button above to fetch the latest AI news.")