Spaces:
Sleeping
Sleeping
Let Gradio own its port on Spaces so frontend assets load
Browse files
app.py
CHANGED
|
@@ -446,12 +446,19 @@ def serve_via_gradio() -> None:
|
|
| 446 |
with _launch_lock:
|
| 447 |
rt = build_runtime()
|
| 448 |
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 455 |
|
| 456 |
# demo.app only exists once launched.
|
| 457 |
demo.app.state.rt = rt
|
|
|
|
| 446 |
with _launch_lock:
|
| 447 |
rt = build_runtime()
|
| 448 |
|
| 449 |
+
# On a Space, let Gradio use its own env-driven defaults (GRADIO_SERVER_PORT
|
| 450 |
+
# and the Space root path). Forcing a port breaks the frontend asset URLs
|
| 451 |
+
# behind HF's proxy: the CSS/JS 404, no JavaScript runs, and the page never
|
| 452 |
+
# leaves its initial server-rendered state. That looks exactly like "the
|
| 453 |
+
# dashboard shows nothing" -- demo.load never fires, so the sign-in token in
|
| 454 |
+
# the query string is never read.
|
| 455 |
+
launch_kwargs: dict = {"prevent_thread_lock": True, "show_api": False}
|
| 456 |
+
if port := os.environ.get("APP_PORT"):
|
| 457 |
+
# Self-hosting / local dev, where nothing sets GRADIO_SERVER_PORT.
|
| 458 |
+
launch_kwargs["server_name"] = "0.0.0.0"
|
| 459 |
+
launch_kwargs["server_port"] = int(port)
|
| 460 |
+
|
| 461 |
+
demo.launch(**launch_kwargs) # returns so we can attach routes
|
| 462 |
|
| 463 |
# demo.app only exists once launched.
|
| 464 |
demo.app.state.rt = rt
|