Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +25 -15
- requirements.txt +2 -1
app.py
CHANGED
@@ -3,7 +3,7 @@ from PIL import Image
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import snapshot_download
|
5 |
import os
|
6 |
-
|
7 |
|
8 |
def load_model(repo_id):
|
9 |
download_dir = snapshot_download(repo_id)
|
@@ -14,22 +14,32 @@ def load_model(repo_id):
|
|
14 |
return detection_model
|
15 |
|
16 |
|
17 |
-
def predict(
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
|
29 |
REPO_ID = "dexpyw/model"
|
30 |
detection_model = load_model(REPO_ID)
|
31 |
|
32 |
-
gr.Interface(
|
33 |
-
|
34 |
-
|
35 |
-
|
|
|
|
|
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import snapshot_download
|
5 |
import os
|
6 |
+
import cv2
|
7 |
|
8 |
def load_model(repo_id):
|
9 |
download_dir = snapshot_download(repo_id)
|
|
|
14 |
return detection_model
|
15 |
|
16 |
|
17 |
+
def predict(input_data):
|
18 |
+
if isinstance(input_data, Image.Image):
|
19 |
+
source = input_data
|
20 |
+
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
21 |
+
img_bgr = result[0].plot()
|
22 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1])
|
23 |
+
return out_pilimg
|
24 |
+
elif isinstance(input_data, str) and input_data.endswith('.mp4'):
|
25 |
+
cap = cv2.VideoCapture(input_data)
|
26 |
+
ret, frame = cap.read()
|
27 |
+
if ret:
|
28 |
+
result = detection_model.predict(frame, conf=0.5, iou=0.6)
|
29 |
+
img_bgr = result[0].plot()
|
30 |
+
out_pilimg = Image.fromarray(img_bgr[..., ::-1])
|
31 |
+
cap.release()
|
32 |
+
return out_pilimg
|
33 |
+
cap.release()
|
34 |
+
return None
|
35 |
|
36 |
|
37 |
REPO_ID = "dexpyw/model"
|
38 |
detection_model = load_model(REPO_ID)
|
39 |
|
40 |
+
gr.Interface(
|
41 |
+
fn=predict,
|
42 |
+
inputs=[gr.Image(type="pil", label="Upload Image"), gr.Video(type="file", label="Upload Video")],
|
43 |
+
outputs=gr.Image(type="pil", label="Predicted Output"),
|
44 |
+
live=True
|
45 |
+
).launch(share=True)
|
requirements.txt
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
ultralytics
|
2 |
-
huggingface_hub
|
|
|
|
1 |
ultralytics
|
2 |
+
huggingface_hub
|
3 |
+
opencv-python
|