CodeHashira73's picture
initial commit: PatchCore anomaly detection API
84c5557
Raw
History Blame Contribute Delete
913 Bytes
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=["*"]
)
@app.get("/health")
def health():
return {"status": "ok"}
@app.post("/inspect")
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