Spaces:
Running on Zero
Running on Zero
Justin Wood commited on
Commit Β·
c6a8bc8
1
Parent(s): 94d3997
Fix: Gradio 5.49.1 SDK (ZeroGPU requires Gradio), no Gradio in requirements
Browse files- Dockerfile +0 -18
- README.md +4 -2
- app.py +17 -12
Dockerfile
DELETED
|
@@ -1,18 +0,0 @@
|
|
| 1 |
-
FROM python:3.10-slim
|
| 2 |
-
|
| 3 |
-
WORKDIR /app
|
| 4 |
-
|
| 5 |
-
# System deps for OpenCV and trimesh
|
| 6 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 7 |
-
libgl1 libglib2.0-0 git \
|
| 8 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
-
|
| 10 |
-
# Install Python deps
|
| 11 |
-
COPY requirements.txt .
|
| 12 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 13 |
-
|
| 14 |
-
# Copy app
|
| 15 |
-
COPY . .
|
| 16 |
-
|
| 17 |
-
EXPOSE 7860
|
| 18 |
-
CMD ["uvicorn", "app:asgi_app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -3,12 +3,14 @@ title: Jiggle Physics Backend
|
|
| 3 |
emoji: π―
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
-
REST API for the Jiggle Physics Simulator.
|
| 12 |
|
| 13 |
| Endpoint | Method | What it does |
|
| 14 |
|---|---|---|
|
|
|
|
| 3 |
emoji: π―
|
| 4 |
colorFrom: purple
|
| 5 |
colorTo: indigo
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "5.49.1"
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
+
REST API for the Jiggle Physics Simulator. Routes mounted on Gradio 5's FastAPI instance for ZeroGPU compatibility.
|
| 14 |
|
| 15 |
| Endpoint | Method | What it does |
|
| 16 |
|---|---|---|
|
app.py
CHANGED
|
@@ -1,31 +1,32 @@
|
|
| 1 |
"""
|
| 2 |
-
Jiggle Physics Simulator β HuggingFace Space backend
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
import base64
|
| 6 |
import io
|
| 7 |
import json
|
| 8 |
from typing import Optional
|
| 9 |
|
|
|
|
| 10 |
import spaces
|
| 11 |
import numpy as np
|
| 12 |
-
from fastapi import
|
| 13 |
from fastapi.middleware.cors import CORSMiddleware
|
| 14 |
from fastapi.responses import Response
|
| 15 |
from PIL import Image
|
| 16 |
|
| 17 |
-
app
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
app
|
|
|
|
| 20 |
CORSMiddleware,
|
| 21 |
allow_origins=["*"],
|
| 22 |
allow_methods=["POST", "GET"],
|
| 23 |
allow_headers=["*"],
|
| 24 |
)
|
| 25 |
|
| 26 |
-
# Export for uvicorn CMD in Dockerfile
|
| 27 |
-
asgi_app = app
|
| 28 |
-
|
| 29 |
|
| 30 |
def _load_image(upload: UploadFile) -> Image.Image:
|
| 31 |
data = upload.file.read()
|
|
@@ -39,12 +40,12 @@ def _load_image(upload: UploadFile) -> Image.Image:
|
|
| 39 |
return img
|
| 40 |
|
| 41 |
|
| 42 |
-
@app.get("/health")
|
| 43 |
def health():
|
| 44 |
return {"status": "ok"}
|
| 45 |
|
| 46 |
|
| 47 |
-
@app.post("/segment")
|
| 48 |
@spaces.GPU
|
| 49 |
async def segment(
|
| 50 |
image: UploadFile = File(...),
|
|
@@ -88,7 +89,7 @@ async def segment(
|
|
| 88 |
return {"regions": encoded, "image_size": [img.width, img.height]}
|
| 89 |
|
| 90 |
|
| 91 |
-
@app.post("/depth")
|
| 92 |
@spaces.GPU
|
| 93 |
async def depth(image: UploadFile = File(...)):
|
| 94 |
"""Apple Depth Pro depth estimation. Returns base64 float32 depth map."""
|
|
@@ -113,7 +114,7 @@ async def depth(image: UploadFile = File(...)):
|
|
| 113 |
}
|
| 114 |
|
| 115 |
|
| 116 |
-
@app.post("/reconstruct")
|
| 117 |
@spaces.GPU
|
| 118 |
async def reconstruct(
|
| 119 |
image: UploadFile = File(...),
|
|
@@ -150,3 +151,7 @@ async def reconstruct(
|
|
| 150 |
raise HTTPException(status_code=500, detail=str(e))
|
| 151 |
|
| 152 |
return Response(content=glb_bytes, media_type="application/octet-stream")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
"""
|
| 2 |
+
Jiggle Physics Simulator β HuggingFace Space backend
|
| 3 |
+
Gradio 5 SDK + ZeroGPU. Routes added to demo.app (Gradio's FastAPI instance).
|
| 4 |
"""
|
| 5 |
import base64
|
| 6 |
import io
|
| 7 |
import json
|
| 8 |
from typing import Optional
|
| 9 |
|
| 10 |
+
import gradio as gr
|
| 11 |
import spaces
|
| 12 |
import numpy as np
|
| 13 |
+
from fastapi import File, Form, UploadFile, HTTPException
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
from fastapi.responses import Response
|
| 16 |
from PIL import Image
|
| 17 |
|
| 18 |
+
# ββ Minimal Gradio app required for ZeroGPU Spaces βββββββββββββββββββββββββββ
|
| 19 |
+
with gr.Blocks(title="Jiggle Physics API") as demo:
|
| 20 |
+
gr.Markdown("## Jiggle Physics ML API\nEndpoints: `/health` `/segment` `/depth` `/reconstruct`")
|
| 21 |
|
| 22 |
+
# Add CORS to Gradio's underlying FastAPI app
|
| 23 |
+
demo.app.add_middleware(
|
| 24 |
CORSMiddleware,
|
| 25 |
allow_origins=["*"],
|
| 26 |
allow_methods=["POST", "GET"],
|
| 27 |
allow_headers=["*"],
|
| 28 |
)
|
| 29 |
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
def _load_image(upload: UploadFile) -> Image.Image:
|
| 32 |
data = upload.file.read()
|
|
|
|
| 40 |
return img
|
| 41 |
|
| 42 |
|
| 43 |
+
@demo.app.get("/health")
|
| 44 |
def health():
|
| 45 |
return {"status": "ok"}
|
| 46 |
|
| 47 |
|
| 48 |
+
@demo.app.post("/segment")
|
| 49 |
@spaces.GPU
|
| 50 |
async def segment(
|
| 51 |
image: UploadFile = File(...),
|
|
|
|
| 89 |
return {"regions": encoded, "image_size": [img.width, img.height]}
|
| 90 |
|
| 91 |
|
| 92 |
+
@demo.app.post("/depth")
|
| 93 |
@spaces.GPU
|
| 94 |
async def depth(image: UploadFile = File(...)):
|
| 95 |
"""Apple Depth Pro depth estimation. Returns base64 float32 depth map."""
|
|
|
|
| 114 |
}
|
| 115 |
|
| 116 |
|
| 117 |
+
@demo.app.post("/reconstruct")
|
| 118 |
@spaces.GPU
|
| 119 |
async def reconstruct(
|
| 120 |
image: UploadFile = File(...),
|
|
|
|
| 151 |
raise HTTPException(status_code=500, detail=str(e))
|
| 152 |
|
| 153 |
return Response(content=glb_bytes, media_type="application/octet-stream")
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
if __name__ == "__main__":
|
| 157 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|