linas-p commited on
Commit
edcfa9e
·
verified ·
1 Parent(s): 836aaed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -4,7 +4,8 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
-
 
8
  from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
@@ -42,7 +43,19 @@ def get_recent_news(description: str) -> str:
42
  try:
43
  search_tool = DuckDuckGoSearchTool()
44
  search_results = search_tool(description)
45
- return search_results
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  except Exception as e:
48
  return f"Error fetching the news '{timezone}': {str(e)}"
 
4
  import pytz
5
  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 !
 
43
  try:
44
  search_tool = DuckDuckGoSearchTool()
45
  search_results = search_tool(description)
46
+ url_pattern = r'\[.*?\]\((https?://[^\s)]+)\)'
47
+ match = re.search(url_pattern, search_results)
48
+
49
+ if not match:
50
+ return "Error: Could not parse URL from search results."
51
+
52
+ url = match.group(1)
53
+ try:
54
+ response = requests.get(url, timeout=1)
55
+ response.raise_for_status() # Raise an exception for bad status codes
56
+ return response.text # Return the HTML content as a string
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 '{timezone}': {str(e)}"