Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,21 @@
|
|
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 |
-
download_dir = snapshot_download(repo_id)
|
9 |
-
print(download_dir)
|
10 |
-
path = os.path.join(download_dir, "best_int8_openvino_model")
|
11 |
-
print(path)
|
12 |
-
detection_model = YOLO(path, task='detect')
|
13 |
-
return detection_model
|
14 |
|
|
|
|
|
15 |
|
|
|
16 |
def predict(pilimg):
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
# print(x.shape)
|
21 |
-
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
22 |
-
img_bgr = result[0].plot()
|
23 |
-
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
24 |
-
|
25 |
return out_pilimg
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
gr.
|
32 |
-
|
33 |
-
|
34 |
-
).launch(share=True)
|
|
|
1 |
from ultralytics import YOLO
|
2 |
from PIL import Image
|
3 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
# Load model directly from file in the Space
|
6 |
+
detection_model = YOLO("best.pt")
|
7 |
|
8 |
+
# Prediction function
|
9 |
def predict(pilimg):
|
10 |
+
results = detection_model.predict(pilimg, conf=0.5, iou=0.6)
|
11 |
+
img_bgr = results[0].plot()
|
12 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # Convert BGR to RGB
|
|
|
|
|
|
|
|
|
|
|
13 |
return out_pilimg
|
14 |
|
15 |
+
# Gradio interface
|
16 |
+
gr.Interface(
|
17 |
+
fn=predict,
|
18 |
+
inputs=gr.Image(type="pil"),
|
19 |
+
outputs=gr.Image(type="pil"),
|
20 |
+
title="Mask Detection Demo"
|
21 |
+
).launch()
|
|