Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,6 +6,8 @@ import yaml
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
import requests
|
| 8 |
import re
|
|
|
|
|
|
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
@@ -36,9 +38,13 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 36 |
|
| 37 |
@tool
|
| 38 |
def get_recent_news(description: str) -> str:
|
| 39 |
-
"""
|
|
|
|
| 40 |
Args:
|
| 41 |
-
description: A string representing a valid recent news (e.g., 'news/sports').
|
|
|
|
|
|
|
|
|
|
| 42 |
"""
|
| 43 |
try:
|
| 44 |
search_tool = DuckDuckGoSearchTool()
|
|
@@ -53,12 +59,18 @@ def get_recent_news(description: str) -> str:
|
|
| 53 |
try:
|
| 54 |
response = requests.get(url, timeout=1)
|
| 55 |
response.raise_for_status() # Raise an exception for bad status codes
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
except requests.RequestException as e:
|
| 58 |
return f"Error fetching HTML: {str(e)}"
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
-
return f"Error fetching the news '{
|
| 62 |
|
| 63 |
final_answer = FinalAnswerTool()
|
| 64 |
|
|
|
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
import requests
|
| 8 |
import re
|
| 9 |
+
from bs4 import BeautifulSoup
|
| 10 |
+
|
| 11 |
from Gradio_UI import GradioUI
|
| 12 |
|
| 13 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
|
|
|
| 38 |
|
| 39 |
@tool
|
| 40 |
def get_recent_news(description: str) -> str:
|
| 41 |
+
"""Fetches the recent news on a given topic and returns its plain text.
|
| 42 |
+
|
| 43 |
Args:
|
| 44 |
+
description: A string representing a valid recent news topic (e.g., 'news/sports').
|
| 45 |
+
|
| 46 |
+
Returns:
|
| 47 |
+
A plain text string containing the content of the fetched news article.
|
| 48 |
"""
|
| 49 |
try:
|
| 50 |
search_tool = DuckDuckGoSearchTool()
|
|
|
|
| 59 |
try:
|
| 60 |
response = requests.get(url, timeout=1)
|
| 61 |
response.raise_for_status() # Raise an exception for bad status codes
|
| 62 |
+
html_content = response.text # Get the HTML content as a string
|
| 63 |
+
|
| 64 |
+
# Parse the HTML content to extract plain text
|
| 65 |
+
soup = BeautifulSoup(html_content, "html.parser")
|
| 66 |
+
plain_text = soup.get_text(separator="\n", strip=True)
|
| 67 |
+
return plain_text
|
| 68 |
+
|
| 69 |
except requests.RequestException as e:
|
| 70 |
return f"Error fetching HTML: {str(e)}"
|
| 71 |
|
| 72 |
except Exception as e:
|
| 73 |
+
return f"Error fetching the news '{description}': {str(e)}"
|
| 74 |
|
| 75 |
final_answer = FinalAnswerTool()
|
| 76 |
|