Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ from selenium.webdriver.common.by import By
|
|
| 8 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 9 |
from selenium.webdriver.support import expected_conditions as EC
|
| 10 |
from selenium.common.exceptions import TimeoutException, WebDriverException
|
| 11 |
-
from webdriver_manager.chrome import ChromeDriverManager
|
| 12 |
import time
|
| 13 |
import logging
|
| 14 |
import os
|
|
@@ -46,10 +45,13 @@ def init_driver():
|
|
| 46 |
options.binary_location = "/usr/bin/google-chrome"
|
| 47 |
|
| 48 |
try:
|
| 49 |
-
# Use
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
return driver
|
| 52 |
except Exception as e:
|
|
|
|
| 53 |
raise Exception(f"Driver initialization failed: {str(e)}")
|
| 54 |
|
| 55 |
@app.post("/transcript", response_model=TranscriptResponse)
|
|
@@ -140,7 +142,7 @@ async def get_transcript(request: VideoRequest):
|
|
| 140 |
async def health_check():
|
| 141 |
paths = {
|
| 142 |
"chrome": "/usr/bin/google-chrome",
|
| 143 |
-
"chromedriver": "/usr/bin/chromedriver"
|
| 144 |
}
|
| 145 |
exists = {name: os.path.exists(path) for name, path in paths.items()}
|
| 146 |
|
|
@@ -152,14 +154,14 @@ async def health_check():
|
|
| 152 |
chrome_version = os.popen("/usr/bin/google-chrome --version").read().strip()
|
| 153 |
except Exception as e:
|
| 154 |
logger.error(f"Failed to get Chrome version: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
-
|
| 157 |
-
try:
|
| 158 |
-
chromedriver_version = os.popen("/usr/bin/chromedriver --version").read().strip() or "Managed by WebDriver Manager"
|
| 159 |
-
except Exception as e:
|
| 160 |
-
logger.info("ChromeDriver version check skipped (likely managed by WebDriver Manager)")
|
| 161 |
-
|
| 162 |
-
status = "OK" if exists["chrome"] else "ERROR"
|
| 163 |
logger.info(f"Health check: Chrome={chrome_version}, ChromeDriver={chromedriver_version}, Paths={exists}")
|
| 164 |
|
| 165 |
return {
|
|
@@ -167,7 +169,7 @@ async def health_check():
|
|
| 167 |
"paths": exists,
|
| 168 |
"chrome_version": chrome_version,
|
| 169 |
"chromedriver_version": chromedriver_version,
|
| 170 |
-
"working": exists
|
| 171 |
}
|
| 172 |
|
| 173 |
@app.get("/")
|
|
|
|
| 8 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 9 |
from selenium.webdriver.support import expected_conditions as EC
|
| 10 |
from selenium.common.exceptions import TimeoutException, WebDriverException
|
|
|
|
| 11 |
import time
|
| 12 |
import logging
|
| 13 |
import os
|
|
|
|
| 45 |
options.binary_location = "/usr/bin/google-chrome"
|
| 46 |
|
| 47 |
try:
|
| 48 |
+
# Use explicit ChromeDriver path
|
| 49 |
+
service = Service(executable_path="/usr/bin/chromedriver")
|
| 50 |
+
driver = webdriver.Chrome(service=service, options=options)
|
| 51 |
+
logger.info("ChromeDriver initialized successfully")
|
| 52 |
return driver
|
| 53 |
except Exception as e:
|
| 54 |
+
logger.error(f"Driver initialization failed: {str(e)}")
|
| 55 |
raise Exception(f"Driver initialization failed: {str(e)}")
|
| 56 |
|
| 57 |
@app.post("/transcript", response_model=TranscriptResponse)
|
|
|
|
| 142 |
async def health_check():
|
| 143 |
paths = {
|
| 144 |
"chrome": "/usr/bin/google-chrome",
|
| 145 |
+
"chromedriver": "/usr/bin/chromedriver"
|
| 146 |
}
|
| 147 |
exists = {name: os.path.exists(path) for name, path in paths.items()}
|
| 148 |
|
|
|
|
| 154 |
chrome_version = os.popen("/usr/bin/google-chrome --version").read().strip()
|
| 155 |
except Exception as e:
|
| 156 |
logger.error(f"Failed to get Chrome version: {str(e)}")
|
| 157 |
+
|
| 158 |
+
if exists["chromedriver"]:
|
| 159 |
+
try:
|
| 160 |
+
chromedriver_version = os.popen("/usr/bin/chromedriver --version").read().strip()
|
| 161 |
+
except Exception as e:
|
| 162 |
+
logger.error(f"Failed to get ChromeDriver version: {str(e)}")
|
| 163 |
|
| 164 |
+
status = "OK" if all(exists.values()) else "ERROR"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
logger.info(f"Health check: Chrome={chrome_version}, ChromeDriver={chromedriver_version}, Paths={exists}")
|
| 166 |
|
| 167 |
return {
|
|
|
|
| 169 |
"paths": exists,
|
| 170 |
"chrome_version": chrome_version,
|
| 171 |
"chromedriver_version": chromedriver_version,
|
| 172 |
+
"working": all(exists.values())
|
| 173 |
}
|
| 174 |
|
| 175 |
@app.get("/")
|