Spaces:
Sleeping
Sleeping
Clean up launch (remove diagnostics); document CPU-for-stub / ZeroGPU-for-real-model
Browse files
server.py
CHANGED
|
@@ -24,6 +24,7 @@ from __future__ import annotations
|
|
| 24 |
|
| 25 |
import os
|
| 26 |
import tempfile
|
|
|
|
| 27 |
import time
|
| 28 |
import uuid
|
| 29 |
from collections import OrderedDict
|
|
@@ -338,36 +339,18 @@ async def index():
|
|
| 338 |
|
| 339 |
|
| 340 |
# HF runs `python server.py` (README app_file) and proxies port 7860. `gradio.Server`
|
| 341 |
-
# launches at MODULE TOP LEVEL; on a Space gradio binds 0.0.0.0:7860 automatically
|
| 342 |
-
#
|
| 343 |
-
#
|
| 344 |
-
# (Locally, set GRADIO_SERVER_PORT to use a different port.)
|
| 345 |
#
|
| 346 |
-
#
|
| 347 |
-
#
|
| 348 |
-
#
|
| 349 |
-
#
|
| 350 |
-
#
|
| 351 |
-
#
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
_sys.stderr.flush()
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
_log("before launch")
|
| 361 |
-
try:
|
| 362 |
-
_ret = app.launch(show_error=True, prevent_thread_lock=True)
|
| 363 |
-
_log(f"launch returned: {type(_ret)}")
|
| 364 |
-
except Exception as _e: # noqa: BLE001
|
| 365 |
-
import traceback
|
| 366 |
-
|
| 367 |
-
traceback.print_exc()
|
| 368 |
-
_log(f"launch raised: {type(_e).__name__}: {_e}")
|
| 369 |
-
|
| 370 |
-
_log("holding main thread open")
|
| 371 |
-
import threading as _threading
|
| 372 |
-
|
| 373 |
-
_threading.Event().wait()
|
|
|
|
| 24 |
|
| 25 |
import os
|
| 26 |
import tempfile
|
| 27 |
+
import threading
|
| 28 |
import time
|
| 29 |
import uuid
|
| 30 |
from collections import OrderedDict
|
|
|
|
| 339 |
|
| 340 |
|
| 341 |
# HF runs `python server.py` (README app_file) and proxies port 7860. `gradio.Server`
|
| 342 |
+
# launches at MODULE TOP LEVEL; on a Space gradio binds 0.0.0.0:7860 automatically.
|
| 343 |
+
# We launch non-blocking and hold the main thread ourselves so the (daemon) uvicorn
|
| 344 |
+
# server keeps serving. (Locally, set GRADIO_SERVER_PORT to use a different port.)
|
|
|
|
| 345 |
#
|
| 346 |
+
# Two deploy gotchas, both learned the hard way:
|
| 347 |
+
# * gradio is pinned to 6.10.0. On 6.17.x a custom gradio.Server doesn't stay up
|
| 348 |
+
# under the Space runtime. 6.10.0 is the version gradio's own `Server` example
|
| 349 |
+
# ships, and it still allows huggingface-hub<1.0 (needed by the real model).
|
| 350 |
+
# * Stub mode registers no `@spaces.GPU` function, which makes a ZeroGPU Space's
|
| 351 |
+
# `spaces` reload server error out and flip the Space to RUNTIME_ERROR even
|
| 352 |
+
# though uvicorn serves fine. So the stub demo runs on CPU-basic hardware. Once
|
| 353 |
+
# the real model (with `@spaces.GPU`) is wired, switch hardware back to ZeroGPU.
|
| 354 |
+
# Keep the README sdk_version and requirements*.txt gradio pins in lockstep.
|
| 355 |
+
app.launch(show_error=True, prevent_thread_lock=True)
|
| 356 |
+
threading.Event().wait()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|