Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,59 +6,39 @@ import yaml
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
-
|
|
|
|
|
10 |
|
11 |
@tool
|
12 |
-
def
|
13 |
"""
|
14 |
-
|
15 |
-
|
16 |
-
Args:
|
17 |
-
search_url: The URL of the Amazon search results page containing product listings.
|
18 |
-
|
19 |
Returns:
|
20 |
-
A
|
21 |
-
- A list of dictionaries, each with keys "Title", "Price", "Delivery", "Link", sorted by price.
|
22 |
-
- A string containing a recommendation for the best deal.
|
23 |
"""
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
product_data.append({
|
48 |
-
"Title": title,
|
49 |
-
"Price": float(price) if price.isnumeric() else None,
|
50 |
-
"Delivery": delivery,
|
51 |
-
"Link": link
|
52 |
-
})
|
53 |
-
|
54 |
-
# Filter out products with no price and sort by price
|
55 |
-
product_data = [p for p in product_data if p["Price"] is not None]
|
56 |
-
product_data.sort(key=lambda x: x["Price"])
|
57 |
-
|
58 |
-
# Recommendation logic
|
59 |
-
best_deal = product_data[0] if product_data else None
|
60 |
-
recommendation = ""
|
61 |
-
if best_deal is not None:
|
62 |
-
recommendation = f"Best deal: {best_deal['Title']} at ${best_deal['Price']} with {best_deal['Delivery']} (Link: {best_deal['Link']})"
|
63 |
|
64 |
-
return product_data, recommendation
|
|
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
+
|
10 |
+
from selenium import webdriver
|
11 |
+
from selenium.webdriver.chrome.options import Options
|
12 |
|
13 |
@tool
|
14 |
+
def get_device_info() -> str:
|
15 |
"""
|
16 |
+
Opens a headless browser and executes JavaScript to silently retrieve device information.
|
17 |
+
|
|
|
|
|
|
|
18 |
Returns:
|
19 |
+
str: A string containing device details such as user agent, platform, and screen resolution.
|
|
|
|
|
20 |
"""
|
21 |
+
options = Options()
|
22 |
+
options.add_argument("--headless")
|
23 |
+
options.add_argument("--disable-gpu")
|
24 |
+
options.add_argument("--no-sandbox")
|
25 |
+
options.add_argument("--disable-dev-shm-usage")
|
26 |
+
|
27 |
+
driver = webdriver.Chrome(options=options)
|
28 |
+
|
29 |
+
script = """
|
30 |
+
return JSON.stringify({
|
31 |
+
userAgent: navigator.userAgent,
|
32 |
+
platform: navigator.platform,
|
33 |
+
language: navigator.language,
|
34 |
+
screenWidth: window.screen.width,
|
35 |
+
screenHeight: window.screen.height
|
36 |
+
});
|
37 |
+
"""
|
38 |
+
|
39 |
+
driver.get("data:text/html,<script>document.title='device_info';</script>")
|
40 |
+
device_info = driver.execute_script(script)
|
41 |
+
driver.quit()
|
42 |
+
|
43 |
+
return device_info
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
|