Spaces:
Running
Running
Update app/lens_images_core.py
Browse files- app/lens_images_core.py +7 -15
app/lens_images_core.py
CHANGED
|
@@ -14,7 +14,7 @@ if not LOGGER.handlers:
|
|
| 14 |
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
|
| 15 |
)
|
| 16 |
|
| 17 |
-
COOKIE_JSON_URL = os.getenv("COOKIE_JSON_URL", "")
|
| 18 |
UA = "Mozilla/5.0 (Lens OCR Images)"
|
| 19 |
|
| 20 |
_COMMON_CHROME_PATHS = [
|
|
@@ -47,12 +47,11 @@ def _find_chrome_binary() -> str | None:
|
|
| 47 |
return None
|
| 48 |
|
| 49 |
def _build_chrome() -> webdriver.Chrome:
|
|
|
|
|
|
|
| 50 |
opts = ChromeOptions()
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
if bin_loc and shutil.which(bin_loc):
|
| 54 |
-
opts.binary_location = bin_loc
|
| 55 |
-
|
| 56 |
extra = os.getenv(
|
| 57 |
"CHROME_EXTRA_ARGS",
|
| 58 |
"--disable-gpu --no-sandbox --disable-dev-shm-usage --window-size=1920,1080 --headless=new",
|
|
@@ -60,15 +59,8 @@ def _build_chrome() -> webdriver.Chrome:
|
|
| 60 |
for a in extra:
|
| 61 |
if a:
|
| 62 |
opts.add_argument(a)
|
| 63 |
-
|
| 64 |
-
|
| 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 |
|
| 73 |
_cached_cookie_obj: Dict[str, Any] | None = None
|
| 74 |
_cached_cookie_fetched_at: float = 0.0
|
|
|
|
| 14 |
format="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
|
| 15 |
)
|
| 16 |
|
| 17 |
+
COOKIE_JSON_URL = os.getenv("COOKIE_JSON_URL", "")
|
| 18 |
UA = "Mozilla/5.0 (Lens OCR Images)"
|
| 19 |
|
| 20 |
_COMMON_CHROME_PATHS = [
|
|
|
|
| 47 |
return None
|
| 48 |
|
| 49 |
def _build_chrome() -> webdriver.Chrome:
|
| 50 |
+
bin_loc = _find_chrome_binary() or "/usr/bin/chromium"
|
| 51 |
+
drv_path = os.getenv("CHROMEDRIVER", "/usr/bin/chromedriver")
|
| 52 |
opts = ChromeOptions()
|
| 53 |
+
opts.binary_location = bin_loc
|
| 54 |
+
|
|
|
|
|
|
|
|
|
|
| 55 |
extra = os.getenv(
|
| 56 |
"CHROME_EXTRA_ARGS",
|
| 57 |
"--disable-gpu --no-sandbox --disable-dev-shm-usage --window-size=1920,1080 --headless=new",
|
|
|
|
| 59 |
for a in extra:
|
| 60 |
if a:
|
| 61 |
opts.add_argument(a)
|
| 62 |
+
service = ChromeService(executable_path=drv_path)
|
| 63 |
+
return webdriver.Chrome(service=service, options=opts)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
_cached_cookie_obj: Dict[str, Any] | None = None
|
| 66 |
_cached_cookie_fetched_at: float = 0.0
|