Spaces:
Sleeping
Sleeping
Download src/mian.py from low-key-007/yoloapi: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/low-key-007/yoloapi/resolve/main/src/mian.py
- Command line
-
hf download hf://spaces/low-key-007/yoloapi/src/mian.py
-
curl -L -o mian.py https://huggingface.co/spaces/low-key-007/yoloapi/resolve/main/src/mian.py
1.12 kB
| from fastapi import FastAPI, File, UploadFile | |
| from fastapi.responses import JSONResponse | |
| from src.config import Config | |
| from src.inference import detector # Imports the loaded model instance | |
| app = FastAPI( | |
| title=Config.API_TITLE, | |
| description=Config.API_DESC, | |
| version=Config.API_VERSION | |
| ) | |
| def health_check(): | |
| return {"status": "operational", "model": Config.MODEL_PATH} | |
| async def predict(file: UploadFile = File(...)): | |
| try: | |
| # 1. Read Image | |
| image_bytes = await file.read() | |
| img = detector.process_image(image_bytes) | |
| # 2. Inference | |
| raw_results = detector.run_inference(img) | |
| # 3. Formatting | |
| detections, base64_img = detector.format_results(raw_results) | |
| return JSONResponse(content={ | |
| "meta": { | |
| "count": len(detections), | |
| "model": "YOLOv8-X" | |
| }, | |
| "detections": detections, | |
| "annotated_image_base64": base64_img | |
| }) | |
| except Exception as e: | |
| return JSONResponse(content={"error": str(e)}, status_code=500) |