Sarvarbek13 commited on
Commit
83803ef
·
verified ·
1 Parent(s): 7497a2e

Restore known-good launch structure; GPU probe for provisioning only

Browse files
Files changed (2) hide show
  1. app/__pycache__/app.cpython-312.pyc +0 -0
  2. app/app.py +40 -57
app/__pycache__/app.cpython-312.pyc CHANGED
Binary files a/app/__pycache__/app.cpython-312.pyc and b/app/__pycache__/app.cpython-312.pyc differ
 
app/app.py CHANGED
@@ -64,23 +64,37 @@ from app import panels, theme
64
  # ZeroGPU runs limit" while every local test passed, because locally the
65
  # decorator is documented as effect-free.
66
  #
67
- # Un-decorated code runs normally on a ZeroGPU Space, on CPU, with no quota
68
- # consumed. That is exactly what this workload wants. The decorator is for
69
- # functions that genuinely need the GPU; applying it to CPU work buys nothing
70
- # and spends a scarce shared resource to do so.
 
 
71
  #
72
- # THE IMPORT, HOWEVER, IS REQUIRED -- also learned from a failed deploy. Having
73
- # removed the decorator, removing `import spaces` with it left the Space stuck
74
- # at `hardware: None` against `requested_hardware: zero-a10g`: the process ran
75
- # and bound its port, but the ZeroGPU container was never provisioned and every
76
- # request returned 503. Importing the module is what registers the app with the
77
- # ZeroGPU scheduler, and HuggingFace lists it as a required step independently
78
- # of decorating anything. So: import it, decorate nothing.
79
  try: # pragma: no cover - the Hub runtime always provides this
80
- import spaces # noqa: F401 -- registers the app with the ZeroGPU scheduler
81
  except ImportError: # local development, CI, the test suite
82
  spaces = None
83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  ROOT = Path(__file__).resolve().parent.parent
85
  ASSETS = ROOT / "app" / "assets"
86
  MODELS = ROOT / "outputs" / "models"
@@ -877,55 +891,24 @@ def build_interface() -> gr.Blocks:
877
  return demo
878
 
879
 
880
- #: Module-level, and named `demo`, because the Spaces runner IMPORTS this module
881
- #: and looks for exactly that name -- with the interface built only inside
882
- #: main(), the Space started a server, found no `demo`, and exited with
883
- #: RUNTIME_ERROR while `python app/app.py` worked perfectly on a laptop.
884
- demo = build_interface()
885
-
886
-
887
- # Gradio 6 moved `theme` and `css` off Blocks and onto launch(), and the Spaces
888
- # runner calls demo.launch() ITSELF with its own arguments. Passing styling only
889
- # inside main() therefore deploys a completely unstyled console -- the theme is
890
- # silently dropped, and nothing fails loudly enough to notice. Binding the
891
- # defaults onto the object makes the styling survive whichever process launches
892
- # it, locally or on the Hub.
893
- _raw_launch = demo.launch
894
-
895
-
896
- def _styled_launch(*args, **kwargs):
897
- kwargs.setdefault("theme", theme.build_theme())
898
- kwargs.setdefault("css", theme.CSS)
899
- return _raw_launch(*args, **kwargs)
900
-
901
-
902
- demo.launch = _styled_launch
903
-
904
-
905
  def main() -> None:
906
  """Launch the console.
907
 
908
- HOST AND PORT ARE SET ONLY OFF-PLATFORM. Gradio 6 serves through an SSR
909
- Node proxy that takes the public port and puts Python behind it on the
910
- next one (`Node proxy -> Python :7861`). Hard-coding 7860 fought that
911
- arrangement on the Space and the process exited immediately after binding.
912
- On a Space, `SPACE_ID` is set and Gradio reads its own `GRADIO_SERVER_*`
913
- configuration, which is the platform's business, not ours.
 
 
914
  """
915
- options = {} if os.environ.get("SPACE_ID") else {
916
- "server_name": "0.0.0.0", "server_port": 7860,
917
- }
918
- demo.launch(**options)
919
-
920
- # THEN BLOCK, EXPLICITLY. Gradio's launch() returns immediately when it is
921
- # already running under a reload manager -- `if self._is_running_in_reload_thread:
922
- # return` -- which is how the Spaces runner serves the app. Locally there is
923
- # no reload thread, so launch() blocks and the script stays up; on the Space
924
- # it fell straight through, __main__ ended, and the process exited taking the
925
- # SSR Node server with it ("Stopping Node.js server..."). The Space reported
926
- # RUNTIME_ERROR seconds after a successful bind, and no local run could
927
- # reproduce it. If launch() did block, this line is simply never reached.
928
- demo.block_thread()
929
 
930
 
931
  if __name__ == "__main__":
 
64
  # ZeroGPU runs limit" while every local test passed, because locally the
65
  # decorator is documented as effect-free.
66
  #
67
+ # SO THE INFERENCE PATH IS NOT DECORATED. What the platform still needs is a
68
+ # GPU entry point to exist at all: with no `@spaces.GPU` anywhere the Space sat
69
+ # at `hardware: None` against `requested_hardware: zero-a10g`, bound its port,
70
+ # and served 503 on every request -- the ZeroGPU container was never
71
+ # provisioned. HuggingFace's own instructions list importing `spaces` and
72
+ # decorating a GPU function as the steps that make a ZeroGPU Space work.
73
  #
74
+ # The resolution is to declare ONE minimal GPU entry point that the console
75
+ # never calls on any user path. It satisfies provisioning; it consumes no quota
76
+ # because it is never invoked. This is a platform accommodation, stated plainly
77
+ # rather than dressed up as a computational need: nothing in this project uses
78
+ # a GPU, and no model was changed to pretend otherwise.
 
 
79
  try: # pragma: no cover - the Hub runtime always provides this
80
+ import spaces
81
  except ImportError: # local development, CI, the test suite
82
  spaces = None
83
 
84
+
85
+ if spaces is not None: # pragma: no cover - only meaningful on ZeroGPU
86
+
87
+ @spaces.GPU(duration=1)
88
+ def _zerogpu_provisioning_probe() -> str:
89
+ """Declared so ZeroGPU provisions the Space. Never called by the UI.
90
+
91
+ Every user-facing path -- prediction, grading, the shift check --
92
+ deliberately avoids this function. See the note above on why decorating
93
+ the real inference path exhausted a 5-minute daily quota in one page
94
+ load.
95
+ """
96
+ return "cpu-bound console; no GPU work is performed"
97
+
98
  ROOT = Path(__file__).resolve().parent.parent
99
  ASSETS = ROOT / "app" / "assets"
100
  MODELS = ROOT / "outputs" / "models"
 
891
  return demo
892
 
893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
894
  def main() -> None:
895
  """Launch the console.
896
 
897
+ Theme and CSS are passed to launch() rather than to Blocks: Gradio 6 moved
898
+ them there, and `show_api` was removed in the same release.
899
+
900
+ DELIBERATELY PLAIN. Successive attempts to out-guess the Spaces runner --
901
+ exposing a module-level `demo`, wrapping `launch` to re-inject styling,
902
+ ceding the port, forcing `block_thread()` -- each fixed an imagined problem
903
+ and left the Space unprovisioned at `hardware: None`. The structure below is
904
+ the one that actually reached RUNNING on ZeroGPU with the theme intact.
905
  """
906
+ build_interface().launch(
907
+ server_name="0.0.0.0",
908
+ server_port=7860,
909
+ theme=theme.build_theme(),
910
+ css=theme.CSS,
911
+ )
 
 
 
 
 
 
 
 
912
 
913
 
914
  if __name__ == "__main__":