Alvlt commited on
Commit
96285c2
·
1 Parent(s): 10c5bd3

First commit

Browse files
Files changed (4) hide show
  1. Dockerfile +15 -0
  2. app.py +35 -0
  3. best.pt +3 -0
  4. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ RUN apt-get update && apt-get install -y \
6
+ libgl1 \
7
+ libglib2.0-0 \
8
+ && rm -rf /var/lib/apt/lists/*
9
+
10
+ COPY requirements.txt .
11
+ RUN pip install --no-cache-dir -r requirements.txt
12
+
13
+ COPY . .
14
+
15
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from PIL import Image
3
+ from ultralytics import YOLO
4
+ import io
5
+
6
+ app = FastAPI()
7
+
8
+ # Loading model
9
+ model = YOLO("best.pt")
10
+ print("Model classes :", model.names)
11
+
12
+ # Health check
13
+ @app.get("/")
14
+ def home():
15
+ return {"status": "ok", "classes": model.names}
16
+
17
+ @app.post("/predict")
18
+ def predict(file: UploadFile = File(...)):
19
+ image = Image.open(io.BytesIO(file.file.read())).convert("RGB")
20
+
21
+ results = model.predict(image)[0]
22
+
23
+ detections = []
24
+ # For each bounding box, 3 pieces of information are extracted
25
+ for box in results.boxes:
26
+ detections.append({
27
+ # converte 0 and 1 into fire or smoke
28
+ "classe": model.names[int(box.cls)],
29
+ # confidence score
30
+ "confidence": float(box.conf),
31
+ # bbox coordinates
32
+ "bbox": box.xyxy[0].tolist(),
33
+ })
34
+
35
+ return {"detections": detections}
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:148ea5e757aabe4043582981eb24a1f6ed02d4ed3b8379c8a1bd876646e1476c
3
+ size 40480492
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ ultralytics # package which contains Yolo
4
+ python-multipart # allows Fast AFPI to receive uploaded files
5
+ pillow # For manipulate images