Spaces:
Sleeping
Sleeping
Download start.py from MustafaHussein/Saudi_Law_Vision: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/MustafaHussein/Saudi_Law_Vision/resolve/main/start.py
- Command line
-
hf download hf://spaces/MustafaHussein/Saudi_Law_Vision/start.py
-
curl -L -o start.py https://huggingface.co/spaces/MustafaHussein/Saudi_Law_Vision/resolve/main/start.py
1.25 kB
| """ | |
| Entry point for the Hugging Face Space (Gradio SDK, ZeroGPU hardware). | |
| ZeroGPU's startup check only runs when a Gradio app *launches*. So we: | |
| 1. declare a tiny @spaces.GPU function (never called -> no GPU quota used), | |
| 2. launch a hidden Gradio app on an internal port (127.0.0.1:7861), | |
| 3. serve the real FastAPI app on 7860 with uvicorn as before. | |
| """ | |
| # `spaces` must be imported BEFORE torch (app.main loads torch indirectly). | |
| try: | |
| import spaces | |
| except ImportError: # running locally | |
| spaces = None | |
| if spaces is not None: | |
| import gradio as gr | |
| def _gpu_probe() -> str: | |
| return "ok" | |
| with gr.Blocks() as _probe_demo: | |
| _btn = gr.Button("probe", visible=False) | |
| _out = gr.Textbox(visible=False) | |
| _btn.click(_gpu_probe, None, _out) | |
| # launch() is what triggers ZeroGPU's startup handshake. | |
| # Internal port only: your real app stays on 7860. | |
| _probe_demo.launch( | |
| server_name="127.0.0.1", | |
| server_port=7861, | |
| prevent_thread_lock=True, | |
| show_api=False, | |
| quiet=True, | |
| ) | |
| import uvicorn # noqa: E402 | |
| from app.main import app # noqa: E402 | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port=7860) |