daniel0708 commited on
Commit
d8a3216
ยท
verified ยท
1 Parent(s): d72673f

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +33 -0
  2. best.pt +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from ultralytics import YOLO
3
+ import cv2
4
+
5
+ # ๋ชจ๋ธ ๋กœ๋“œ
6
+ model = YOLO("best.pt")
7
+
8
+ def predict(image):
9
+ # YOLO ์ถ”๋ก 
10
+ results = model(image)
11
+
12
+ # ์ƒ์˜/ํ•˜์˜ ์ขŒํ‘œ ๋ฐ ๋ผ๋ฒจ ์ถ”์ถœ (๊ธฐ์กด ํ”„๋กœ์ ํŠธ JSON ํ˜•์‹์— ๋งž์ถฐ ๊ฐ€๊ณต)
13
+ detections = []
14
+ for r in results:
15
+ for box in r.boxes:
16
+ x1, y1, x2, y2 = box.xyxy[0].tolist()
17
+ label = model.names[int(box.cls[0])]
18
+ conf = float(box.conf[0])
19
+ detections.append({
20
+ "label": label,
21
+ "confidence": conf,
22
+ "box": [int(x1), int(y1), int(x2), int(y2)]
23
+ })
24
+ return detections
25
+
26
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • (API ์ „์šฉ์ด๋ฏ€๋กœ ๋‹จ์ˆœํ•˜๊ฒŒ ๊ตฌ์„ฑ)
27
+ demo = gr.Interface(
28
+ fn=predict,
29
+ inputs=gr.Image(type="numpy"),
30
+ outputs="json"
31
+ )
32
+
33
+ demo.launch()
best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef40b5c571b1e43220aa45e4a85a94bf2de27a5724e37467f0aaca725a7677a1
3
+ size 19164186
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ ultralytics==8.3.30
2
+ opencv-python-headless==4.9.0.80
3
+ gradio
4
+ numpy==1.26.4
5
+ Pillow==10.4.0