Spaces:
Running
Running
Update app/lens_images_core.py
Browse files- app/lens_images_core.py +4 -12
app/lens_images_core.py
CHANGED
|
@@ -3,13 +3,10 @@ import os, json, time, hashlib, httpx, base64, re, asyncio, threading, shutil, l
|
|
| 3 |
from typing import Dict, Any
|
| 4 |
from urllib.parse import urlparse
|
| 5 |
|
| 6 |
-
import chromedriver_autoinstaller
|
| 7 |
from selenium import webdriver
|
| 8 |
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
| 9 |
from selenium.webdriver.chrome.service import Service as ChromeService
|
| 10 |
|
| 11 |
-
chromedriver_autoinstaller.install()
|
| 12 |
-
|
| 13 |
LOGGER = logging.getLogger("lens_images_core")
|
| 14 |
if not LOGGER.handlers:
|
| 15 |
logging.basicConfig(
|
|
@@ -52,8 +49,8 @@ def _find_chrome_binary() -> str | None:
|
|
| 52 |
def _build_chrome() -> webdriver.Chrome:
|
| 53 |
opts = ChromeOptions()
|
| 54 |
|
| 55 |
-
bin_loc =
|
| 56 |
-
if bin_loc:
|
| 57 |
opts.binary_location = bin_loc
|
| 58 |
|
| 59 |
extra = os.getenv(
|
|
@@ -66,15 +63,10 @@ def _build_chrome() -> webdriver.Chrome:
|
|
| 66 |
|
| 67 |
drv_path = os.getenv("CHROMEDRIVER")
|
| 68 |
if drv_path and os.path.exists(drv_path):
|
|
|
|
| 69 |
return webdriver.Chrome(service=ChromeService(executable_path=drv_path), options=opts)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
installed_path = chromedriver_autoinstaller.install()
|
| 73 |
-
if installed_path and os.path.exists(installed_path):
|
| 74 |
-
return webdriver.Chrome(service=ChromeService(executable_path=installed_path), options=opts)
|
| 75 |
-
except Exception as e:
|
| 76 |
-
LOGGER.warning("chromedriver_autoinstaller failed: %s; will try Selenium Manager", e)
|
| 77 |
-
|
| 78 |
return webdriver.Chrome(options=opts)
|
| 79 |
|
| 80 |
|
|
|
|
| 3 |
from typing import Dict, Any
|
| 4 |
from urllib.parse import urlparse
|
| 5 |
|
|
|
|
| 6 |
from selenium import webdriver
|
| 7 |
from selenium.webdriver.chrome.options import Options as ChromeOptions
|
| 8 |
from selenium.webdriver.chrome.service import Service as ChromeService
|
| 9 |
|
|
|
|
|
|
|
| 10 |
LOGGER = logging.getLogger("lens_images_core")
|
| 11 |
if not LOGGER.handlers:
|
| 12 |
logging.basicConfig(
|
|
|
|
| 49 |
def _build_chrome() -> webdriver.Chrome:
|
| 50 |
opts = ChromeOptions()
|
| 51 |
|
| 52 |
+
bin_loc = os.getenv("CHROME_BINARY")
|
| 53 |
+
if bin_loc and shutil.which(bin_loc):
|
| 54 |
opts.binary_location = bin_loc
|
| 55 |
|
| 56 |
extra = os.getenv(
|
|
|
|
| 63 |
|
| 64 |
drv_path = os.getenv("CHROMEDRIVER")
|
| 65 |
if drv_path and os.path.exists(drv_path):
|
| 66 |
+
LOG.warning("Using CHROMEDRIVER at %s", drv_path)
|
| 67 |
return webdriver.Chrome(service=ChromeService(executable_path=drv_path), options=opts)
|
| 68 |
|
| 69 |
+
LOG.warning("No CHROMEDRIVER provided; deferring to Selenium Manager (will fetch Chrome for Testing).")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
return webdriver.Chrome(options=opts)
|
| 71 |
|
| 72 |
|