Spaces:
Running
Running
Download app.py from manojgup/waste-classifier-api: direct link, hf CLI and curl.
- Browser
- Download file 877 Bytes
-
https://huggingface.co/spaces/manojgup/waste-classifier-api/resolve/main/app.py
- Command line
-
hf download hf://spaces/manojgup/waste-classifier-api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/manojgup/waste-classifier-api/resolve/main/app.py
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") | |
| def health(): | |
| return {"status": "ready", "model": REPO_ID} | |
| 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)) |