arittrabag commited on
Commit
9ef0c02
·
verified ·
1 Parent(s): c290185

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ from fastapi.responses import JSONResponse
3
+ from ultralytics import YOLO
4
+ from PIL import Image
5
+ import io
6
+
7
+ app = FastAPI()
8
+ model = YOLO("best.pt") # make sure this file exists
9
+
10
+ @app.post("/detect")
11
+ async def detect_boxes(file: UploadFile = File(...)):
12
+ contents = await file.read()
13
+ img = Image.open(io.BytesIO(contents)).convert("RGB")
14
+
15
+ # Inference
16
+ results = model.predict(img, conf=0.3, iou=0.5, verbose=False)
17
+ box_count = len(results[0].boxes)
18
+
19
+ return JSONResponse(content={"box_count": box_count})