manojgup's picture
Upload 2 files
230e286 verified
Raw History Blame Contribute Delete
877 Bytes
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))