Spaces:
Running on Zero
Running on Zero
Space: restore stable native-direct startup; keep explicit Qwen 09 controls
Browse files
app.py
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
-
"""Movimento Space:
|
| 2 |
from __future__ import annotations
|
| 3 |
|
| 4 |
-
import importlib.util
|
| 5 |
import os
|
| 6 |
import traceback
|
| 7 |
-
import
|
| 8 |
-
|
| 9 |
-
import gradio as gr
|
| 10 |
|
| 11 |
try:
|
| 12 |
import spaces # type: ignore
|
|
@@ -21,22 +18,15 @@ except Exception:
|
|
| 21 |
|
| 22 |
spaces = _SpacesFallback()
|
| 23 |
|
| 24 |
-
|
| 25 |
os.environ.setdefault("SERVER_NAME", "0.0.0.0")
|
| 26 |
-
os.environ["SERVER_PORT"] = str(
|
| 27 |
os.environ.setdefault("HF_MODE", "1")
|
| 28 |
# Avoid local LLM2Vec fallback on Spaces (requires gated Llama weights).
|
| 29 |
os.environ.setdefault("TEXT_ENCODER_MODE", "api")
|
| 30 |
# Prefer CPU on ZeroGPU to avoid low-level CUDA init crashes during model load.
|
| 31 |
os.environ.setdefault("KIMODO_DEVICE", "cpu")
|
| 32 |
|
| 33 |
-
_state: dict[str, object] = {
|
| 34 |
-
"ok": False,
|
| 35 |
-
"error": None,
|
| 36 |
-
"trace": None,
|
| 37 |
-
"demo": None,
|
| 38 |
-
}
|
| 39 |
-
|
| 40 |
|
| 41 |
@spaces.GPU(duration=60)
|
| 42 |
def _gpu_healthcheck() -> str:
|
|
@@ -44,72 +34,23 @@ def _gpu_healthcheck() -> str:
|
|
| 44 |
return "ok"
|
| 45 |
|
| 46 |
|
| 47 |
-
def
|
| 48 |
try:
|
| 49 |
-
if importlib.util.find_spec("viser") is None:
|
| 50 |
-
raise RuntimeError("Missing dependency: viser")
|
| 51 |
-
|
| 52 |
import kimodo
|
| 53 |
from kimodo.demo.app import Demo
|
| 54 |
|
| 55 |
print(f"[movimento][boot] kimodo_module={getattr(kimodo, '__file__', 'unknown')}")
|
| 56 |
-
print(f"[movimento][boot]
|
| 57 |
-
|
| 58 |
-
_state["ok"] = True
|
| 59 |
-
_state["error"] = None
|
| 60 |
-
_state["trace"] = None
|
| 61 |
-
except Exception as exc: # noqa: BLE001
|
| 62 |
-
_state["ok"] = False
|
| 63 |
-
_state["error"] = str(exc)
|
| 64 |
-
_state["trace"] = traceback.format_exc(limit=12)
|
| 65 |
-
print("[movimento][boot][fatal] native demo failed to start")
|
| 66 |
-
print(_state["trace"])
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
threading.Thread(target=_boot_native_demo, daemon=True).start()
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
def _redirect_html() -> str:
|
| 82 |
-
target = f"/proxy/{NATIVE_PORT}/"
|
| 83 |
-
return (
|
| 84 |
-
"<div style='padding:8px 0;color:#4d6372;font-size:13px;'>Preparing native UI...</div>"
|
| 85 |
-
f"<div><a href='{target}' target='_self' style='font-size:14px;'>Open native UI now</a></div>"
|
| 86 |
-
"<script>"
|
| 87 |
-
"(function(){"
|
| 88 |
-
f"const target='{target}';"
|
| 89 |
-
"async function step(){"
|
| 90 |
-
"try{"
|
| 91 |
-
"const r=await fetch(target,{method:'GET',cache:'no-store'});"
|
| 92 |
-
"if(r.ok){window.top.location.href=target;return;}"
|
| 93 |
-
"}catch(e){}"
|
| 94 |
-
"setTimeout(step,2500);"
|
| 95 |
-
"}"
|
| 96 |
-
"step();"
|
| 97 |
-
"})();"
|
| 98 |
-
"</script>"
|
| 99 |
-
)
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
def _refresh() -> tuple[str, str]:
|
| 103 |
-
return _status_markdown(), _redirect_html()
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
with gr.Blocks(title="Movimento") as demo:
|
| 107 |
-
gr.Markdown("# Movimento")
|
| 108 |
-
status_md = gr.Markdown(_status_markdown())
|
| 109 |
-
viewer = gr.HTML(_redirect_html())
|
| 110 |
-
refresh_btn = gr.Button("Refresh UI Status")
|
| 111 |
-
refresh_btn.click(fn=_refresh, inputs=[], outputs=[status_md, viewer])
|
| 112 |
|
| 113 |
|
| 114 |
if __name__ == "__main__":
|
| 115 |
-
|
|
|
|
| 1 |
+
"""Movimento Space entrypoint: run native Kimodo demo directly."""
|
| 2 |
from __future__ import annotations
|
| 3 |
|
|
|
|
| 4 |
import os
|
| 5 |
import traceback
|
| 6 |
+
import time
|
|
|
|
|
|
|
| 7 |
|
| 8 |
try:
|
| 9 |
import spaces # type: ignore
|
|
|
|
| 18 |
|
| 19 |
spaces = _SpacesFallback()
|
| 20 |
|
| 21 |
+
PORT = int(os.environ.get("PORT", "7860"))
|
| 22 |
os.environ.setdefault("SERVER_NAME", "0.0.0.0")
|
| 23 |
+
os.environ["SERVER_PORT"] = str(PORT)
|
| 24 |
os.environ.setdefault("HF_MODE", "1")
|
| 25 |
# Avoid local LLM2Vec fallback on Spaces (requires gated Llama weights).
|
| 26 |
os.environ.setdefault("TEXT_ENCODER_MODE", "api")
|
| 27 |
# Prefer CPU on ZeroGPU to avoid low-level CUDA init crashes during model load.
|
| 28 |
os.environ.setdefault("KIMODO_DEVICE", "cpu")
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
@spaces.GPU(duration=60)
|
| 32 |
def _gpu_healthcheck() -> str:
|
|
|
|
| 34 |
return "ok"
|
| 35 |
|
| 36 |
|
| 37 |
+
def main() -> None:
|
| 38 |
try:
|
|
|
|
|
|
|
|
|
|
| 39 |
import kimodo
|
| 40 |
from kimodo.demo.app import Demo
|
| 41 |
|
| 42 |
print(f"[movimento][boot] kimodo_module={getattr(kimodo, '__file__', 'unknown')}")
|
| 43 |
+
print(f"[movimento][boot] mode=native_direct port={PORT}")
|
| 44 |
+
Demo()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
# Keep the process alive while Viser serves on SERVER_PORT.
|
| 47 |
+
while True:
|
| 48 |
+
time.sleep(3600)
|
| 49 |
+
except Exception: # noqa: BLE001
|
| 50 |
+
print("[movimento][boot][fatal] native demo failed to start")
|
| 51 |
+
print(traceback.format_exc(limit=12))
|
| 52 |
+
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
if __name__ == "__main__":
|
| 56 |
+
main()
|