Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,11 @@
|
|
1 |
from ultralytics import YOLO
|
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import snapshot_download
|
4 |
-
import cv2
|
5 |
import os
|
6 |
|
|
|
|
|
7 |
def load_model(repo_id):
|
8 |
download_dir = snapshot_download(repo_id)
|
9 |
print(download_dir)
|
@@ -13,23 +15,22 @@ def load_model(repo_id):
|
|
13 |
return detection_model
|
14 |
|
15 |
|
16 |
-
def
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
23 |
|
24 |
-
def clear_image():
|
25 |
-
return None
|
26 |
|
27 |
REPO_ID = "CTYiHui/EggDefect"
|
28 |
detection_model = load_model(REPO_ID)
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
iface.launch()
|
|
|
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 = "best_int8_openvino_model"
|
8 |
+
|
9 |
def load_model(repo_id):
|
10 |
download_dir = snapshot_download(repo_id)
|
11 |
print(download_dir)
|
|
|
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 = "CTYiHui/EggDefect"
|
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)
|
|
|
|