Firoj112 commited on
Commit
784a322
·
verified ·
1 Parent(s): 82f34df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -3
app.py CHANGED
@@ -30,6 +30,27 @@ if not gemini_api_key:
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,9 +82,6 @@ def close_popups() -> str:
61
  """
62
  webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
63
 
64
- # Set ChromeDriver path
65
- os.environ['webdriver.chrome.driver'] = '/usr/local/bin/chromedriver'
66
-
67
  # Initialize Chrome driver with error handling
68
  try:
69
  chrome_options = webdriver.ChromeOptions()
 
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
  """
83
  webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
84
 
 
 
 
85
  # Initialize Chrome driver with error handling
86
  try:
87
  chrome_options = webdriver.ChromeOptions()