Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -351,23 +351,37 @@ app.mount("/static", StaticFiles(directory=tempfile.gettempdir()), name="static"
|
|
| 351 |
|
| 352 |
# Mount Gradio's static assets to fix UI rendering issue
|
| 353 |
gradio_base_path = gr.__path__[0]
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
# Health check endpoint to verify static asset availability
|
| 368 |
@app.get("/health")
|
| 369 |
async def health_check():
|
| 370 |
-
if os.path.exists(gradio_static_path):
|
| 371 |
return {"status": "healthy", "gradio_static": "available"}
|
| 372 |
return {"status": "unhealthy", "gradio_static": "missing"}
|
| 373 |
|
|
|
|
| 351 |
|
| 352 |
# Mount Gradio's static assets to fix UI rendering issue
|
| 353 |
gradio_base_path = gr.__path__[0]
|
| 354 |
+
possible_static_paths = [
|
| 355 |
+
os.path.join(gradio_base_path, "templates", "frontend", "dist"),
|
| 356 |
+
os.path.join(gradio_base_path, "templates", "frontend", "build"),
|
| 357 |
+
os.path.join(gradio_base_path, "static"),
|
| 358 |
+
]
|
| 359 |
+
|
| 360 |
+
gradio_static_path = None
|
| 361 |
+
for path in possible_static_paths:
|
| 362 |
+
if os.path.exists(path) and os.path.exists(os.path.join(path, "_app")):
|
| 363 |
+
gradio_static_path = path
|
| 364 |
+
break
|
| 365 |
+
|
| 366 |
+
if gradio_static_path:
|
| 367 |
+
app.mount("/_app", StaticFiles(directory=gradio_static_path), name="gradio_static")
|
| 368 |
+
logger.info(f"Mounted Gradio static assets at {gradio_static_path}")
|
| 369 |
+
else:
|
| 370 |
+
logger.warning(
|
| 371 |
+
"Gradio static assets not found in any expected paths: " +
|
| 372 |
+
", ".join(possible_static_paths) +
|
| 373 |
+
". Falling back to Gradio's built-in server for UI rendering."
|
| 374 |
+
)
|
| 375 |
+
# Run Gradio directly if assets cannot be found
|
| 376 |
+
if __name__ == "__main__":
|
| 377 |
+
logger.info("Starting Gradio's built-in server...")
|
| 378 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 379 |
+
exit(0)
|
| 380 |
|
| 381 |
# Health check endpoint to verify static asset availability
|
| 382 |
@app.get("/health")
|
| 383 |
async def health_check():
|
| 384 |
+
if gradio_static_path and os.path.exists(gradio_static_path):
|
| 385 |
return {"status": "healthy", "gradio_static": "available"}
|
| 386 |
return {"status": "unhealthy", "gradio_static": "missing"}
|
| 387 |
|