Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,46 +3,45 @@ from PIL import Image
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import snapshot_download
|
5 |
import os
|
6 |
-
import cv2
|
7 |
-
import tempfile
|
8 |
|
9 |
#load model
|
10 |
-
model_path = "best_int8_openvino_model"
|
11 |
-
|
12 |
def load_model(repo_id):
|
|
|
13 |
download_dir = snapshot_download(repo_id)
|
14 |
print(download_dir)
|
15 |
-
|
16 |
-
print(
|
17 |
-
detection_model = YOLO(
|
18 |
return detection_model
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
detection_model = load_model(REPO_ID)
|
22 |
|
23 |
-
#
|
24 |
-
def
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
title = "Object detection for glasses and mouth(human) image",
|
45 |
-
description = "You may adjust confidence and IoU Threshold"
|
46 |
-
)
|
47 |
-
|
48 |
-
iface.launch(share=True)
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import snapshot_download
|
5 |
import os
|
|
|
|
|
6 |
|
7 |
#load model
|
|
|
|
|
8 |
def load_model(repo_id):
|
9 |
+
|
10 |
download_dir = snapshot_download(repo_id)
|
11 |
print(download_dir)
|
12 |
+
model_path = os.path.join(download_dir,"best_int8_openvino_model")
|
13 |
+
print(model_path)
|
14 |
+
detection_model = YOLO(model_path, task='detect')
|
15 |
return detection_model
|
16 |
|
17 |
+
#object detection for image
|
18 |
+
def predict(pil_img, conf_thresh, iou_thresh):
|
19 |
+
source = pil_img
|
20 |
+
results = detection_model.predict(source, conf=conf_thresh, iou=iou_thresh)
|
21 |
+
annotated_img = results[0].plot()
|
22 |
+
return Image.fromarray(annotated_img[..., ::-1]) # Convert BGR to RGB
|
23 |
+
|
24 |
+
REPO_ID = "qiqiyuan/glasses_and_mouth"
|
25 |
detection_model = load_model(REPO_ID)
|
26 |
|
27 |
+
#gradio interface
|
28 |
+
def iface():
|
29 |
+
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn=predict, # Function to be called
|
32 |
+
inputs=[ # List of input components
|
33 |
+
gr.Image(type="pil", label="Input Image"),
|
34 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, value=0.5, label="Confidence Threshold"),
|
35 |
+
gr.Slider(minimum=0.0, maximum=1.0, step=0.05, value=0.5, label="IoU Threshold")
|
36 |
+
],
|
37 |
+
outputs=gr.Image(type="pil", label="InputImage"), # Output type
|
38 |
+
title="Object Detection for Glasses and Mouth (Human)",
|
39 |
+
description="Upload an image to detect glasses and mouth (Human) using a pre-trained YOLO model",
|
40 |
+
theme="huggingface",
|
41 |
+
)
|
42 |
+
|
43 |
+
return interface
|
44 |
+
|
45 |
+
#launch the gradio app
|
46 |
+
app_iface = iface()
|
47 |
+
app_iface.launch(share=True)
|
|
|
|
|
|
|
|
|
|