Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import helium
|
|
6 |
from selenium import webdriver
|
7 |
from selenium.webdriver.common.by import By
|
8 |
from selenium.webdriver.common.keys import Keys
|
9 |
-
from selenium.webdriver.chrome.service import Service
|
10 |
from io import BytesIO
|
11 |
from PIL import Image
|
12 |
from datetime import datetime
|
@@ -31,6 +30,13 @@ if not gemini_api_key:
|
|
31 |
|
32 |
login(hf_token, add_to_git_credential=False)
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# Define tools
|
35 |
@tool
|
36 |
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
@@ -62,7 +68,7 @@ def close_popups() -> str:
|
|
62 |
"""
|
63 |
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
64 |
|
65 |
-
# Initialize Chrome driver
|
66 |
try:
|
67 |
chrome_options = webdriver.ChromeOptions()
|
68 |
chrome_options.add_argument("--force-device-scale-factor=1")
|
@@ -72,8 +78,7 @@ try:
|
|
72 |
chrome_options.add_argument("--disable-dev-shm-usage")
|
73 |
chrome_options.add_argument("--window-position=0,0")
|
74 |
chrome_options.add_argument("--headless=new")
|
75 |
-
|
76 |
-
driver = webdriver.Chrome(service=service, options=chrome_options)
|
77 |
helium.set_driver(driver)
|
78 |
logger.info("Chrome driver initialized successfully.")
|
79 |
except Exception as e:
|
@@ -123,32 +128,26 @@ Then you can go to pages!
|
|
123 |
Code:
|
124 |
go_to('github.com/trending')
|
125 |
```<end_code>
|
126 |
-
|
127 |
You can directly click clickable elements by inputting the text that appears on them.
|
128 |
Code:
|
129 |
click("Top products")
|
130 |
```<end_code>
|
131 |
-
|
132 |
If it's a link:
|
133 |
Code:
|
134 |
click(Link("Top products"))
|
135 |
```<end_code>
|
136 |
-
|
137 |
If you try to interact with an element and it's not found, you'll get a LookupError.
|
138 |
In general stop your action after each button click to see what happens on your screenshot.
|
139 |
Never try to login in a page.
|
140 |
-
|
141 |
To scroll up or down, use scroll_down or scroll_up with as an argument the number of pixels to scroll from.
|
142 |
Code:
|
143 |
scroll_down(num_pixels=1200) # This will scroll one viewport down
|
144 |
```<end_code>
|
145 |
-
|
146 |
When you have pop-ups with a cross icon to close, don't try to click the close icon by finding its element or targeting an 'X' element (this most often fails).
|
147 |
Just use your built-in tool `close_popups` to close them:
|
148 |
Code:
|
149 |
close_popups()
|
150 |
```<end_code>
|
151 |
-
|
152 |
You can use .exists() to check for the existence of an element. For example:
|
153 |
Code:
|
154 |
if Text('Accept cookies?').exists():
|
|
|
6 |
from selenium import webdriver
|
7 |
from selenium.webdriver.common.by import By
|
8 |
from selenium.webdriver.common.keys import Keys
|
|
|
9 |
from io import BytesIO
|
10 |
from PIL import Image
|
11 |
from datetime import datetime
|
|
|
30 |
|
31 |
login(hf_token, add_to_git_credential=False)
|
32 |
|
33 |
+
# Debug ChromeDriver path
|
34 |
+
chromedriver_path = '/usr/bin/chromedriver' # Expected path for chromium-driver
|
35 |
+
logger.info(f"Checking ChromeDriver at: {chromedriver_path}")
|
36 |
+
logger.info(f"ChromeDriver exists: {os.path.exists(chromedriver_path)}")
|
37 |
+
logger.info(f"ChromeDriver executable: {os.access(chromedriver_path, os.X_OK)}")
|
38 |
+
logger.info(f"System PATH: {os.environ.get('PATH')}")
|
39 |
+
|
40 |
# Define tools
|
41 |
@tool
|
42 |
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
|
|
68 |
"""
|
69 |
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
70 |
|
71 |
+
# Initialize Chrome driver
|
72 |
try:
|
73 |
chrome_options = webdriver.ChromeOptions()
|
74 |
chrome_options.add_argument("--force-device-scale-factor=1")
|
|
|
78 |
chrome_options.add_argument("--disable-dev-shm-usage")
|
79 |
chrome_options.add_argument("--window-position=0,0")
|
80 |
chrome_options.add_argument("--headless=new")
|
81 |
+
driver = webdriver.Chrome(options=chrome_options)
|
|
|
82 |
helium.set_driver(driver)
|
83 |
logger.info("Chrome driver initialized successfully.")
|
84 |
except Exception as e:
|
|
|
128 |
Code:
|
129 |
go_to('github.com/trending')
|
130 |
```<end_code>
|
|
|
131 |
You can directly click clickable elements by inputting the text that appears on them.
|
132 |
Code:
|
133 |
click("Top products")
|
134 |
```<end_code>
|
|
|
135 |
If it's a link:
|
136 |
Code:
|
137 |
click(Link("Top products"))
|
138 |
```<end_code>
|
|
|
139 |
If you try to interact with an element and it's not found, you'll get a LookupError.
|
140 |
In general stop your action after each button click to see what happens on your screenshot.
|
141 |
Never try to login in a page.
|
|
|
142 |
To scroll up or down, use scroll_down or scroll_up with as an argument the number of pixels to scroll from.
|
143 |
Code:
|
144 |
scroll_down(num_pixels=1200) # This will scroll one viewport down
|
145 |
```<end_code>
|
|
|
146 |
When you have pop-ups with a cross icon to close, don't try to click the close icon by finding its element or targeting an 'X' element (this most often fails).
|
147 |
Just use your built-in tool `close_popups` to close them:
|
148 |
Code:
|
149 |
close_popups()
|
150 |
```<end_code>
|
|
|
151 |
You can use .exists() to check for the existence of an element. For example:
|
152 |
Code:
|
153 |
if Text('Accept cookies?').exists():
|