Spaces:
Running on Zero
Running on Zero
fix(01-05): expose a module-level `demo` for the Space runner
Browse filesThird deploy (e3ebc72) built, imported and printed "Running on local URL", then
stopped the Node server and exited with RUNTIME_ERROR and no traceback. The Space
launches under gradio.utils.SpacesReloader, whose postrun() calls
`getattr(watch_module, demo_name)` on every reload check; with the Blocks living
only inside build_app() the module had no such attribute, which the log announced
as `GRADIO_HOT_RELOAD: Launching demo not found in __main__. Using 'demo'`.
build_app() stays, so tests keep building an independent app.
app.py
CHANGED
|
@@ -72,7 +72,7 @@ def _echo(text: str, slower: bool, history: str) -> tuple[str, str]:
|
|
| 72 |
|
| 73 |
def build_app() -> gr.Blocks:
|
| 74 |
"""Build the Blocks app. Importable and callable from tests without launching."""
|
| 75 |
-
with gr.Blocks(title="Japanese Learning Avatar", fill_height=True) as
|
| 76 |
with gr.Row(equal_height=True):
|
| 77 |
with gr.Column(scale=3, min_width=320):
|
| 78 |
VrmStage()
|
|
@@ -96,8 +96,20 @@ def build_app() -> gr.Blocks:
|
|
| 96 |
|
| 97 |
send.click(_echo, [text_in, slower, transcript], [transcript, text_in])
|
| 98 |
text_in.submit(_echo, [text_in, slower, transcript], [transcript, text_in])
|
| 99 |
-
return
|
| 100 |
|
| 101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
if __name__ == "__main__":
|
| 103 |
-
|
|
|
|
| 72 |
|
| 73 |
def build_app() -> gr.Blocks:
|
| 74 |
"""Build the Blocks app. Importable and callable from tests without launching."""
|
| 75 |
+
with gr.Blocks(title="Japanese Learning Avatar", fill_height=True) as blocks:
|
| 76 |
with gr.Row(equal_height=True):
|
| 77 |
with gr.Column(scale=3, min_width=320):
|
| 78 |
VrmStage()
|
|
|
|
| 96 |
|
| 97 |
send.click(_echo, [text_in, slower, transcript], [transcript, text_in])
|
| 98 |
text_in.submit(_echo, [text_in, slower, transcript], [transcript, text_in])
|
| 99 |
+
return blocks
|
| 100 |
|
| 101 |
|
| 102 |
+
# Module level, and named `demo`, because that is what the Space runner requires.
|
| 103 |
+
# Hugging Face launches the app under gradio.utils.SpacesReloader, whose postrun() does
|
| 104 |
+
# `getattr(watch_module, self.demo_name)` on every reload check. With the Blocks living
|
| 105 |
+
# only inside build_app() there was no such attribute: the third deploy (e3ebc72) logged
|
| 106 |
+
# `GRADIO_HOT_RELOAD: Launching demo not found in __main__. Using 'demo'`, printed its
|
| 107 |
+
# "Running on local URL" line, and then stopped the Node server and exited - RUNTIME_ERROR
|
| 108 |
+
# with no traceback. The factory is kept so tests can build an independent app.
|
| 109 |
+
#
|
| 110 |
+
# This is the one module-level object this file is allowed to own. It is the app itself,
|
| 111 |
+
# not shared state: nothing mutates it per session.
|
| 112 |
+
demo = build_app()
|
| 113 |
+
|
| 114 |
if __name__ == "__main__":
|
| 115 |
+
demo.launch()
|