fdaudens HF Staff commited on
Commit
07aae2e
Β·
verified Β·
1 Parent(s): b1787bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -23,8 +23,8 @@ from llama_index.core.memory import ChatMemoryBuffer
23
  from llama_index.readers.web import RssReader, SimpleWebPageReader
24
  from llama_index.core import SummaryIndex
25
 
26
- # import subprocess
27
- # subprocess.run(["playwright", "install"])
28
 
29
  # allow nested loops in Spaces
30
  nest_asyncio.apply()
@@ -129,7 +129,9 @@ def fetch_news_headlines() -> str:
129
 
130
  # Format the news articles into a readable string
131
  formatted_news = []
132
- for item in root.findall('.//item'):
 
 
133
  title = item.find('title').text if item.find('title') is not None else 'N/A'
134
  link = item.find('link').text if item.find('link') is not None else 'N/A'
135
  pub_date = item.find('pubDate').text if item.find('pubDate') is not None else 'N/A'
@@ -184,7 +186,9 @@ def fetch_news_topics(query: str) -> str:
184
 
185
  # Format the news articles into a readable string
186
  formatted_news = []
187
- for article in news_data.get('news', []):
 
 
188
  formatted_news.append(f"Title: {article.get('title', 'N/A')}")
189
  formatted_news.append(f"Source: {article.get('source', 'N/A')}")
190
  formatted_news.append(f"Link: {article.get('link', 'N/A')}")
@@ -278,7 +282,7 @@ with grb:
278
  "This bot can check the news, tell you the weather, and even browse websites to answer follow-up questions β€” all powered by a team of tiny AI tools working behind the scenes.\n\n"
279
  "πŸ§ͺ Built for fun during the [AI Agents course](https://huggingface.co/learn/agents-course/unit0/introduction) β€” it's just a demo to show what agents can do. \n"
280
  "πŸ™Œ Got ideas or improvements? PRs welcome! \n\n"
281
- "πŸ‘‰ _Try asking β€œWhat’s the weather in Montreal?” or β€œWhat’s in the news today?”_"
282
  )
283
  chatbot = gr.Chatbot(type="messages")
284
  txt = gr.Textbox(placeholder="Ask me anything...", show_label=False)
 
23
  from llama_index.readers.web import RssReader, SimpleWebPageReader
24
  from llama_index.core import SummaryIndex
25
 
26
+ import subprocess
27
+ subprocess.run(["playwright", "install"])
28
 
29
  # allow nested loops in Spaces
30
  nest_asyncio.apply()
 
129
 
130
  # Format the news articles into a readable string
131
  formatted_news = []
132
+ for i, item in enumerate(root.findall('.//item')):
133
+ if i >= 5:
134
+ break
135
  title = item.find('title').text if item.find('title') is not None else 'N/A'
136
  link = item.find('link').text if item.find('link') is not None else 'N/A'
137
  pub_date = item.find('pubDate').text if item.find('pubDate') is not None else 'N/A'
 
186
 
187
  # Format the news articles into a readable string
188
  formatted_news = []
189
+ for i, article in enumerate(news_data.get('news', [])):
190
+ if i >= 5:
191
+ break
192
  formatted_news.append(f"Title: {article.get('title', 'N/A')}")
193
  formatted_news.append(f"Source: {article.get('source', 'N/A')}")
194
  formatted_news.append(f"Link: {article.get('link', 'N/A')}")
 
282
  "This bot can check the news, tell you the weather, and even browse websites to answer follow-up questions β€” all powered by a team of tiny AI tools working behind the scenes.\n\n"
283
  "πŸ§ͺ Built for fun during the [AI Agents course](https://huggingface.co/learn/agents-course/unit0/introduction) β€” it's just a demo to show what agents can do. \n"
284
  "πŸ™Œ Got ideas or improvements? PRs welcome! \n\n"
285
+ "πŸ‘‰ _Try asking "What's the weather in Montreal?" or "What's in the news today?"_"
286
  )
287
  chatbot = gr.Chatbot(type="messages")
288
  txt = gr.Textbox(placeholder="Ask me anything...", show_label=False)