Spaces:
Configuration error
Configuration error
| from fastapi import FastAPI, File, UploadFile, HTTPException | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.inference import predict | |
| app = FastAPI( | |
| title="Visual Defect Inspector", | |
| description="PatchCore-based anomaly detection API for industrial surfaces", | |
| version="1.0.0" | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"] | |
| ) | |
| def health(): | |
| return {"status": "ok"} | |
| async def inspect(file: UploadFile = File(...)): | |
| if file.content_type not in ["image/jpeg", "image/png"]: | |
| raise HTTPException(status_code=400, detail="Only JPEG and PNG images are supported") | |
| image_bytes = await file.read() | |
| try: | |
| result = predict(image_bytes) | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |
| return result |