Download app.py from ChengyiX/nexora: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/ChengyiX/nexora/resolve/f26c60fe2d073154add319b62a5bf2e513d339b6/app.py
- Command line
-
hf download hf://spaces/ChengyiX/nexora@f26c60fe2d073154add319b62a5bf2e513d339b6/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ChengyiX/nexora/resolve/f26c60fe2d073154add319b62a5bf2e513d339b6/app.py
1.4 kB
| import os | |
| from pathlib import Path | |
| import sys | |
| import tarfile | |
| import time | |
| import gradio as gr | |
| import spaces | |
| ROOT = Path(__file__).resolve().parent | |
| ARCHIVE = ROOT / "nexora-bundle.tar.gz" | |
| if ARCHIVE.is_file() and not (ROOT / "static" / "index.html").is_file(): | |
| with tarfile.open(ARCHIVE, "r:gz") as bundle: | |
| bundle.extractall(ROOT) | |
| os.environ.setdefault("STATIC_DIR", str(ROOT / "static")) | |
| os.environ.setdefault("PANOR_CATALOG_PATH", str(ROOT / "deploy" / "panor-catalog.json")) | |
| sys.path.insert(0, str(ROOT)) | |
| from backend.app.main import app as api_app | |
| def zero_gpu_runtime_marker(): | |
| return None | |
| with gr.Blocks() as zero_gpu_app: | |
| trigger = gr.Button(visible=False) | |
| trigger.click(zero_gpu_runtime_marker, outputs=None) | |
| def attach_nexora_routes() -> None: | |
| fallback_routes = [ | |
| route for route in api_app.router.routes if getattr(route, "path", None) == "/{path:path}" | |
| ] | |
| api_routes = [route for route in api_app.router.routes if route not in fallback_routes] | |
| zero_gpu_app.app.router.routes = [ | |
| *api_routes, | |
| *zero_gpu_app.app.router.routes, | |
| *fallback_routes, | |
| ] | |
| if __name__ == "__main__": | |
| zero_gpu_app.launch( | |
| server_name="0.0.0.0", | |
| server_port=int(os.environ.get("PORT", "7860")), | |
| prevent_thread_lock=True, | |
| ) | |
| attach_nexora_routes() | |
| while True: | |
| time.sleep(3600) | |