Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -30,27 +30,6 @@ if not gemini_api_key:
|
|
30 |
|
31 |
login(hf_token, add_to_git_credential=False)
|
32 |
|
33 |
-
# Patch Helium to use system-installed ChromeDriver
|
34 |
-
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
35 |
-
from selenium.webdriver.chrome.webdriver import WebDriver as Chrome
|
36 |
-
from helium._impl import _APIImpl
|
37 |
-
|
38 |
-
def _start_chrome_driver(self, headless, options):
|
39 |
-
chrome_options = options or ChromeOptions()
|
40 |
-
if headless:
|
41 |
-
chrome_options.add_argument('--headless')
|
42 |
-
# Do not set executable_path; let Selenium use the environment variable
|
43 |
-
result = Chrome(options=chrome_options)
|
44 |
-
return result
|
45 |
-
|
46 |
-
# Save the original method
|
47 |
-
original_start_chrome_driver = _APIImpl._start_chrome_driver
|
48 |
-
# Override it with our custom function
|
49 |
-
_APIImpl._start_chrome_driver = _start_chrome_driver
|
50 |
-
|
51 |
-
# Set the environment variable for Selenium to use
|
52 |
-
os.environ['webdriver.chrome.driver'] = '/usr/local/bin/chromedriver'
|
53 |
-
|
54 |
# Define tools
|
55 |
@tool
|
56 |
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
@@ -82,7 +61,7 @@ def close_popups() -> str:
|
|
82 |
"""
|
83 |
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
84 |
|
85 |
-
# Initialize Chrome driver with
|
86 |
try:
|
87 |
chrome_options = webdriver.ChromeOptions()
|
88 |
chrome_options.add_argument("--force-device-scale-factor=1")
|
@@ -92,7 +71,11 @@ try:
|
|
92 |
chrome_options.add_argument("--disable-dev-shm-usage")
|
93 |
chrome_options.add_argument("--window-position=0,0")
|
94 |
chrome_options.add_argument("--headless=new")
|
95 |
-
driver =
|
|
|
|
|
|
|
|
|
96 |
logger.info("Chrome driver initialized successfully.")
|
97 |
except Exception as e:
|
98 |
logger.error(f"Failed to initialize Chrome driver: {str(e)}")
|
|
|
30 |
|
31 |
login(hf_token, add_to_git_credential=False)
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
# Define tools
|
34 |
@tool
|
35 |
def search_item_ctrl_f(text: str, nth_result: int = 1) -> str:
|
|
|
61 |
"""
|
62 |
webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
|
63 |
|
64 |
+
# Initialize Chrome driver with Selenium directly
|
65 |
try:
|
66 |
chrome_options = webdriver.ChromeOptions()
|
67 |
chrome_options.add_argument("--force-device-scale-factor=1")
|
|
|
71 |
chrome_options.add_argument("--disable-dev-shm-usage")
|
72 |
chrome_options.add_argument("--window-position=0,0")
|
73 |
chrome_options.add_argument("--headless=new")
|
74 |
+
driver = webdriver.Chrome(
|
75 |
+
executable_path='/usr/local/bin/chromedriver',
|
76 |
+
options=chrome_options
|
77 |
+
)
|
78 |
+
helium.set_driver(driver)
|
79 |
logger.info("Chrome driver initialized successfully.")
|
80 |
except Exception as e:
|
81 |
logger.error(f"Failed to initialize Chrome driver: {str(e)}")
|