Spaces:
Sleeping
Sleeping
reverting tool and adding chrome browser
Browse files
app.py
CHANGED
@@ -13,12 +13,12 @@ from selenium.webdriver.chrome.service import Service
|
|
13 |
from webdriver_manager.chrome import ChromeDriverManager
|
14 |
|
15 |
@tool
|
16 |
-
def get_zh_top_news() -> str:
|
17 |
"""A tool that retrieves the current top news article's title and URL from www.zerohedge.com.
|
18 |
|
19 |
Returns:
|
20 |
-
str: the article title (str)
|
21 |
-
|
22 |
Raises:
|
23 |
Exception: If the page fails to load or the expected element is not found.
|
24 |
"""
|
@@ -26,11 +26,14 @@ def get_zh_top_news() -> str:
|
|
26 |
chrome_options = Options()
|
27 |
chrome_options.add_argument("--headless") # Run without opening a browser window
|
28 |
chrome_options.add_argument("--disable-gpu") # Disable GPU for headless mode
|
29 |
-
chrome_options.add_argument("--no-sandbox") # Required for
|
30 |
chrome_options.add_argument("--disable-dev-shm-usage") # Avoid memory issues in containers
|
31 |
|
32 |
-
#
|
33 |
-
|
|
|
|
|
|
|
34 |
|
35 |
try:
|
36 |
# Navigate to ZeroHedge homepage
|
@@ -51,7 +54,7 @@ def get_zh_top_news() -> str:
|
|
51 |
if not article_link.startswith("http"):
|
52 |
article_link = f"https://www.zerohedge.com{article_link}"
|
53 |
|
54 |
-
return article_title
|
55 |
|
56 |
except Exception as e:
|
57 |
print(f"Error retrieving top headline: {e}")
|
|
|
13 |
from webdriver_manager.chrome import ChromeDriverManager
|
14 |
|
15 |
@tool
|
16 |
+
def get_zh_top_news() -> tuple[str, str]:
|
17 |
"""A tool that retrieves the current top news article's title and URL from www.zerohedge.com.
|
18 |
|
19 |
Returns:
|
20 |
+
tuple[str, str]: A tuple containing the article title (str) and its URL (str).
|
21 |
+
|
22 |
Raises:
|
23 |
Exception: If the page fails to load or the expected element is not found.
|
24 |
"""
|
|
|
26 |
chrome_options = Options()
|
27 |
chrome_options.add_argument("--headless") # Run without opening a browser window
|
28 |
chrome_options.add_argument("--disable-gpu") # Disable GPU for headless mode
|
29 |
+
chrome_options.add_argument("--no-sandbox") # Required for Docker environments
|
30 |
chrome_options.add_argument("--disable-dev-shm-usage") # Avoid memory issues in containers
|
31 |
|
32 |
+
# Specify ChromeDriver path (installed via Dockerfile)
|
33 |
+
service = Service(executable_path="/usr/local/bin/chromedriver")
|
34 |
+
|
35 |
+
# Initialize the WebDriver
|
36 |
+
driver = webdriver.Chrome(service=service, options=chrome_options)
|
37 |
|
38 |
try:
|
39 |
# Navigate to ZeroHedge homepage
|
|
|
54 |
if not article_link.startswith("http"):
|
55 |
article_link = f"https://www.zerohedge.com{article_link}"
|
56 |
|
57 |
+
return article_title, article_link
|
58 |
|
59 |
except Exception as e:
|
60 |
print(f"Error retrieving top headline: {e}")
|