devsdevline commited on
Commit
2c028d7
·
verified ·
1 Parent(s): f59cb68

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. app.py +31 -0
  3. requirements.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY . /app
6
+
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ EXPOSE 7860
10
+
11
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, File, UploadFile
2
+ from ultralytics import YOLO
3
+ from huggingface_hub import hf_hub_download
4
+ import io
5
+ from PIL import Image
6
+
7
+ app = FastAPI()
8
+
9
+ # Download your YOLO model from your model repo
10
+ model_path = hf_hub_download("devsdevline/soccer-homography-yolo", "best.pt")
11
+ model = YOLO(model_path)
12
+
13
+ @app.get("/")
14
+ def root():
15
+ return {"status": "API running", "model": "soccer-homography-yolo"}
16
+
17
+ @app.post("/predict")
18
+ async def predict(file: UploadFile = File(...)):
19
+ # Read uploaded image
20
+ image = Image.open(io.BytesIO(await file.read())).convert("RGB")
21
+ results = model(image)
22
+
23
+ detections = []
24
+ for box in results[0].boxes:
25
+ detections.append({
26
+ "class_id": int(box.cls[0]),
27
+ "confidence": float(box.conf[0]),
28
+ "bbox": box.xyxy[0].tolist()
29
+ })
30
+
31
+ return {"detections": detections}
requirements.txt ADDED
File without changes