Saudi_Law_Vision / start.py
MustafaHussein's picture
fix deployment
beb251d
Raw History Blame Contribute Delete
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
@spaces.GPU(duration=1)
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)