lowboonsiong
commited on
Upload 3 files
Browse files- app.py +37 -0
- best.pt +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
model_path = ""
|
8 |
+
|
9 |
+
def load_model(repo_id):
|
10 |
+
download_dir = snapshot_download(repo_id)
|
11 |
+
print(download_dir)
|
12 |
+
path = os.path.join(download_dir, "")
|
13 |
+
print(path)
|
14 |
+
detection_model = YOLO(path, task='detect')
|
15 |
+
return detection_model
|
16 |
+
|
17 |
+
|
18 |
+
def predict(pilimg):
|
19 |
+
|
20 |
+
source = pilimg
|
21 |
+
# x = np.asarray(pilimg)
|
22 |
+
# print(x.shape)
|
23 |
+
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
24 |
+
img_bgr = result[0].plot()
|
25 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
26 |
+
|
27 |
+
return out_pilimg
|
28 |
+
|
29 |
+
|
30 |
+
REPO_ID = "ITI107-2024S2/7821983W-lowboonsiong"
|
31 |
+
detection_model = load_model(REPO_ID)
|
32 |
+
|
33 |
+
gr.Interface(fn=predict,
|
34 |
+
inputs=gr.Image(type="pil"),
|
35 |
+
outputs=gr.Image(type="pil")
|
36 |
+
).launch(share=True)
|
37 |
+
|
best.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4d8e71d0f561b9fb7f569fddb711de769cc08a904d4e9282c6917b82165cd7c1
|
3 |
+
size 22512995
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
ultralytics
|
2 |
+
huggingface_hub
|