Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,22 @@
|
|
| 1 |
-
from fastapi import FastAPI, UploadFile, File, HTTPException
|
| 2 |
-
from
|
| 3 |
-
from
|
| 4 |
-
|
| 5 |
-
app = FastAPI(
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, File, HTTPException
|
| 2 |
+
from PIL import Image
|
| 3 |
+
from predict_helper import predict_damage
|
| 4 |
+
|
| 5 |
+
app = FastAPI(
|
| 6 |
+
title="Car Damage Detection API",
|
| 7 |
+
version="1.0"
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
@app.get("/")
|
| 11 |
+
def health():
|
| 12 |
+
return {"status": "API is running"}
|
| 13 |
+
|
| 14 |
+
@app.post("/predict_damage")
|
| 15 |
+
async def predict(image: UploadFile = File(...)):
|
| 16 |
+
try:
|
| 17 |
+
img = Image.open(image.file)
|
| 18 |
+
except Exception:
|
| 19 |
+
raise HTTPException(status_code=400, detail="Invalid image file")
|
| 20 |
+
|
| 21 |
+
result = predict_damage(img)
|
| 22 |
+
return result
|