Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,18 +7,11 @@ Original file is located at
|
|
7 |
https://colab.research.google.com/drive/1GzjDFYPEtsFsBFnhi3x3B0vWyCE-Dtpb
|
8 |
"""
|
9 |
|
10 |
-
import
|
11 |
from PIL import Image
|
12 |
import gradio as gr
|
13 |
from huggingface_hub import snapshot_download
|
14 |
-
|
15 |
-
# Ensure necessary packages are installed
|
16 |
-
try:
|
17 |
-
from ultralytics import YOLO
|
18 |
-
except ImportError:
|
19 |
-
import subprocess
|
20 |
-
subprocess.check_call(["pip", "install", "ultralytics"])
|
21 |
-
from ultralytics import YOLO
|
22 |
|
23 |
model_path = "/Users/markk/Downloads/best_int8_openvino_model"
|
24 |
|
@@ -30,27 +23,24 @@ def load_model(repo_id):
|
|
30 |
detection_model = YOLO(path, task='detect')
|
31 |
return detection_model
|
32 |
|
|
|
33 |
def predict(pilimg):
|
34 |
source = pilimg
|
35 |
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
36 |
img_bgr = result[0].plot()
|
37 |
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
38 |
-
|
39 |
return out_pilimg
|
40 |
|
41 |
-
def predict_video(video_path):
|
42 |
-
result = detection_model.predict(video_path, conf=0.5, iou=0.6)
|
43 |
-
return result[0].save("output_video.mp4") # Save processed video
|
44 |
-
|
45 |
REPO_ID = "Lesterchia174/Monkey_Durian"
|
46 |
detection_model = load_model(REPO_ID)
|
47 |
|
|
|
|
|
48 |
gr.Interface(
|
49 |
fn=predict,
|
50 |
inputs=gr.Image(type="pil"),
|
51 |
-
outputs=gr.Image(type="pil")
|
|
|
|
|
52 |
).launch(share=True)
|
53 |
-
|
54 |
-
# Process the new video file
|
55 |
-
video_path = "Monkey_Durian.mp4"
|
56 |
-
predict_video(video_path)
|
|
|
7 |
https://colab.research.google.com/drive/1GzjDFYPEtsFsBFnhi3x3B0vWyCE-Dtpb
|
8 |
"""
|
9 |
|
10 |
+
from ultralytics import YOLO
|
11 |
from PIL import Image
|
12 |
import gradio as gr
|
13 |
from huggingface_hub import snapshot_download
|
14 |
+
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
model_path = "/Users/markk/Downloads/best_int8_openvino_model"
|
17 |
|
|
|
23 |
detection_model = YOLO(path, task='detect')
|
24 |
return detection_model
|
25 |
|
26 |
+
|
27 |
def predict(pilimg):
|
28 |
source = pilimg
|
29 |
result = detection_model.predict(source, conf=0.5, iou=0.6)
|
30 |
img_bgr = result[0].plot()
|
31 |
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # RGB-order PIL image
|
32 |
+
|
33 |
return out_pilimg
|
34 |
|
|
|
|
|
|
|
|
|
35 |
REPO_ID = "Lesterchia174/Monkey_Durian"
|
36 |
detection_model = load_model(REPO_ID)
|
37 |
|
38 |
+
video_url = "https://github.com/lesterchia1/Monkey_Durian/blob/main/Monkey_Durian.mp4"
|
39 |
+
|
40 |
gr.Interface(
|
41 |
fn=predict,
|
42 |
inputs=gr.Image(type="pil"),
|
43 |
+
outputs=gr.Image(type="pil"),
|
44 |
+
title="Monkey Durian Detector",
|
45 |
+
description=f"[Click here to watch the video]({video_url})"
|
46 |
).launch(share=True)
|
|
|
|
|
|
|
|