Spaces:
Running
Running
File size: 877 Bytes
230e286 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | import os
import runpy
from fastapi import FastAPI, HTTPException, Request
from huggingface_hub import snapshot_download
REPO_ID = "manojgup/waste-mobilenetv3-large-b9281378fe-291126"
model_dir = snapshot_download(repo_id=REPO_ID)
serving = runpy.run_path(os.path.join(model_dir, "waste_inference.py"))
predictor = serving["load_predictor"](model_dir, device="cpu")
app = FastAPI(title="ESP32-CAM Waste Classifier")
@app.get("/")
def health():
return {"status": "ready", "model": REPO_ID}
@app.post("/predict")
async def predict(request: Request):
jpeg_bytes = await request.body()
if not jpeg_bytes:
raise HTTPException(status_code=400, detail="Empty request body; send raw JPEG bytes.")
try:
return serving["predict_jpeg"](jpeg_bytes, predictor)
except Exception as exc:
raise HTTPException(status_code=400, detail=str(exc)) |