Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,11 +42,34 @@ def init_driver():
|
|
| 42 |
options.add_argument("--no-sandbox")
|
| 43 |
options.add_argument("--disable-dev-shm-usage")
|
| 44 |
options.add_argument("--disable-gpu")
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
try:
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
driver = webdriver.Chrome(service=service, options=options)
|
| 51 |
logger.info("ChromeDriver initialized successfully")
|
| 52 |
return driver
|
|
@@ -141,20 +164,30 @@ async def get_transcript(request: VideoRequest):
|
|
| 141 |
@app.get("/health")
|
| 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 |
|
| 149 |
chrome_version = "Not found"
|
| 150 |
chromedriver_version = "Not found"
|
| 151 |
|
| 152 |
if exists["chrome"]:
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
if exists["chromedriver"]:
|
| 159 |
try:
|
| 160 |
chromedriver_version = os.popen("/usr/bin/chromedriver --version").read().strip()
|
|
@@ -162,11 +195,12 @@ async def health_check():
|
|
| 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 {
|
| 168 |
"status": status,
|
| 169 |
-
"
|
|
|
|
| 170 |
"chrome_version": chrome_version,
|
| 171 |
"chromedriver_version": chromedriver_version,
|
| 172 |
"working": all(exists.values())
|
|
|
|
| 42 |
options.add_argument("--no-sandbox")
|
| 43 |
options.add_argument("--disable-dev-shm-usage")
|
| 44 |
options.add_argument("--disable-gpu")
|
| 45 |
+
|
| 46 |
+
# Try multiple possible Chrome binary locations
|
| 47 |
+
possible_chrome_paths = [
|
| 48 |
+
"/usr/bin/google-chrome",
|
| 49 |
+
"/usr/bin/google-chrome-stable",
|
| 50 |
+
"/usr/lib/chromium-browser/chrome",
|
| 51 |
+
"/usr/bin/chromium"
|
| 52 |
+
]
|
| 53 |
+
chrome_path = None
|
| 54 |
+
for path in possible_chrome_paths:
|
| 55 |
+
if os.path.exists(path):
|
| 56 |
+
chrome_path = path
|
| 57 |
+
break
|
| 58 |
+
|
| 59 |
+
if not chrome_path:
|
| 60 |
+
logger.error(f"No Chrome binary found in paths: {possible_chrome_paths}")
|
| 61 |
+
raise Exception(f"No Chrome binary found in paths: {possible_chrome_paths}")
|
| 62 |
+
|
| 63 |
+
options.binary_location = chrome_path
|
| 64 |
+
logger.info(f"Using Chrome binary: {chrome_path}")
|
| 65 |
|
| 66 |
try:
|
| 67 |
+
chromedriver_path = "/usr/bin/chromedriver"
|
| 68 |
+
if not os.path.exists(chromedriver_path):
|
| 69 |
+
logger.error(f"ChromeDriver not found at {chromedriver_path}")
|
| 70 |
+
raise Exception(f"ChromeDriver not found at {chromedriver_path}")
|
| 71 |
+
|
| 72 |
+
service = Service(executable_path=chromedriver_path)
|
| 73 |
driver = webdriver.Chrome(service=service, options=options)
|
| 74 |
logger.info("ChromeDriver initialized successfully")
|
| 75 |
return driver
|
|
|
|
| 164 |
@app.get("/health")
|
| 165 |
async def health_check():
|
| 166 |
paths = {
|
| 167 |
+
"chrome": ["/usr/bin/google-chrome", "/usr/bin/google-chrome-stable", "/usr/lib/chromium-browser/chrome", "/usr/bin/chromium"],
|
| 168 |
+
"chromedriver": ["/usr/bin/chromedriver"]
|
| 169 |
+
}
|
| 170 |
+
exists = {
|
| 171 |
+
"chrome": any(os.path.exists(path) for path in paths["chrome"]),
|
| 172 |
+
"chromedriver": any(os.path.exists(path) for path in paths["chromedriver"])
|
| 173 |
+
}
|
| 174 |
+
found_paths = {
|
| 175 |
+
"chrome": [path for path in paths["chrome"] if os.path.exists(path)],
|
| 176 |
+
"chromedriver": [path for path in paths["chromedriver"] if os.path.exists(path)]
|
| 177 |
}
|
|
|
|
| 178 |
|
| 179 |
chrome_version = "Not found"
|
| 180 |
chromedriver_version = "Not found"
|
| 181 |
|
| 182 |
if exists["chrome"]:
|
| 183 |
+
for path in paths["chrome"]:
|
| 184 |
+
try:
|
| 185 |
+
chrome_version = os.popen(f"{path} --version").read().strip()
|
| 186 |
+
if chrome_version:
|
| 187 |
+
break
|
| 188 |
+
except Exception as e:
|
| 189 |
+
logger.error(f"Failed to get Chrome version for {path}: {str(e)}")
|
| 190 |
+
|
| 191 |
if exists["chromedriver"]:
|
| 192 |
try:
|
| 193 |
chromedriver_version = os.popen("/usr/bin/chromedriver --version").read().strip()
|
|
|
|
| 195 |
logger.error(f"Failed to get ChromeDriver version: {str(e)}")
|
| 196 |
|
| 197 |
status = "OK" if all(exists.values()) else "ERROR"
|
| 198 |
+
logger.info(f"Health check: Chrome={chrome_version}, ChromeDriver={chromedriver_version}, Paths={found_paths}, Exists={exists}")
|
| 199 |
|
| 200 |
return {
|
| 201 |
"status": status,
|
| 202 |
+
"paths_checked": paths,
|
| 203 |
+
"paths_found": found_paths,
|
| 204 |
"chrome_version": chrome_version,
|
| 205 |
"chromedriver_version": chromedriver_version,
|
| 206 |
"working": all(exists.values())
|