Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,63 +1,30 @@
|
|
| 1 |
-
# ---------- MUST BE FIRST ----------
|
| 2 |
import os
|
| 3 |
os.environ.setdefault("GRADIO_USE_CDN", "true")
|
| 4 |
|
| 5 |
import spaces
|
| 6 |
import gradio as gr
|
| 7 |
from fastapi import FastAPI
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
from starlette.exceptions import ClientDisconnect # Starlette ≥0.27
|
| 11 |
-
except Exception:
|
| 12 |
-
from starlette.requests import ClientDisconnect # fallback
|
| 13 |
-
|
| 14 |
-
# Log versions to container logs for sanity
|
| 15 |
-
try:
|
| 16 |
-
print("== Sanity ==")
|
| 17 |
-
print("spaces.__version__:", getattr(spaces, "__version__", "unknown"))
|
| 18 |
-
import gradio
|
| 19 |
-
print("gradio.__version__:", getattr(gradio, "__version__", "unknown"))
|
| 20 |
-
import sys
|
| 21 |
-
print("python:", sys.version)
|
| 22 |
-
print("SPACE_RUNTIME:", os.getenv("SPACE_RUNTIME"))
|
| 23 |
-
print("HF_SPACE_ENTRYPOINT default: app.py")
|
| 24 |
-
except Exception as _e:
|
| 25 |
-
print("version log error:", _e)
|
| 26 |
-
|
| 27 |
-
# ---------- ZeroGPU probes (PUBLIC NAMES) ----------
|
| 28 |
@spaces.GPU(duration=10)
|
| 29 |
-
def gpu_probe(a: int = 1, b: int = 1)
|
| 30 |
-
# Not called; existence is enough for ZeroGPU startup check
|
| 31 |
-
return a + b
|
| 32 |
|
| 33 |
@spaces.GPU(duration=10)
|
| 34 |
-
def gpu_echo(x: str = "ok")
|
| 35 |
-
return x
|
| 36 |
|
| 37 |
-
#
|
| 38 |
-
with gr.Blocks(
|
| 39 |
-
gr.Markdown("### ✅ Minimal
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
t.submit(lambda s: f"echo: {s}", t, o)
|
| 44 |
|
| 45 |
-
demo = demo.queue(
|
| 46 |
|
| 47 |
-
#
|
| 48 |
app = FastAPI()
|
| 49 |
|
| 50 |
@app.get("/health")
|
| 51 |
-
def _health():
|
| 52 |
-
return {"ok": True}
|
| 53 |
-
|
| 54 |
-
@app.exception_handler(ClientDisconnect)
|
| 55 |
-
async def client_disconnect_handler(request, exc):
|
| 56 |
-
return PlainTextResponse("Client disconnected", status_code=499)
|
| 57 |
|
| 58 |
-
# Mount at root (Spaces health-check expects this)
|
| 59 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 60 |
-
|
| 61 |
-
if __name__ == "__main__":
|
| 62 |
-
import uvicorn
|
| 63 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
os.environ.setdefault("GRADIO_USE_CDN", "true")
|
| 3 |
|
| 4 |
import spaces
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI
|
| 7 |
+
|
| 8 |
+
# Public GPU probes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
@spaces.GPU(duration=10)
|
| 10 |
+
def gpu_probe(a: int = 1, b: int = 1): return a + b
|
|
|
|
|
|
|
| 11 |
|
| 12 |
@spaces.GPU(duration=10)
|
| 13 |
+
def gpu_echo(x: str = "ok"): return x
|
|
|
|
| 14 |
|
| 15 |
+
# Simple UI
|
| 16 |
+
with gr.Blocks() as demo:
|
| 17 |
+
gr.Markdown("### ✅ Minimal Space is running")
|
| 18 |
+
inp = gr.Textbox(label="Say something")
|
| 19 |
+
out = gr.Textbox(label="Echo")
|
| 20 |
+
inp.submit(lambda s: f"echo: {s}", inp, out)
|
|
|
|
| 21 |
|
| 22 |
+
demo = demo.queue()
|
| 23 |
|
| 24 |
+
# FastAPI wrapper with health
|
| 25 |
app = FastAPI()
|
| 26 |
|
| 27 |
@app.get("/health")
|
| 28 |
+
def _health(): return {"ok": True}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
|
|
|
| 30 |
app = gr.mount_gradio_app(app, demo, path="/")
|
|
|
|
|
|
|
|
|
|
|
|