Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,30 +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 = "
|
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)
|
|
|
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 = "lowboonsiong/ITC110"
|
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)
|