Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ultralytics import YOLO
|
2 |
+
from PIL import Image
|
3 |
+
import gradio as gr
|
4 |
+
from huggingface_hub import snapshot_download
|
5 |
+
import os
|
6 |
+
|
7 |
+
def load_model(repo_id):
|
8 |
+
detection_model = YOLO('best.pt', task='detect')
|
9 |
+
return detection_model
|
10 |
+
|
11 |
+
|
12 |
+
def predict(pilimg):
|
13 |
+
|
14 |
+
source = pilimg
|
15 |
+
# x = np.asarray(pilimg)
|
16 |
+
# print(x.shape)
|
17 |
+
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
18 |
+
img_bgr = result[0].plot()
|
19 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
20 |
+
|
21 |
+
return out_pilimg
|
22 |
+
|
23 |
+
|
24 |
+
REPO_ID = "ITI107-2024S2/7821983W-lowboonsiong"
|
25 |
+
detection_model = load_model(REPO_ID)
|
26 |
+
|
27 |
+
gr.Interface(fn=predict,
|
28 |
+
inputs=gr.Image(type="pil"),
|
29 |
+
outputs=gr.Image(type="pil")
|
30 |
+
).launch(share=True)
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:50398b00a1c4b805df1ed1b372d6e728e6a55f2d2f075a3fd8e03c57c74b4a84
|
3 |
+
size 5470675
|