Spaces:
Sleeping
Sleeping
Commit
·
7b50e2b
1
Parent(s):
6f979e9
Change the label
Browse files
app.py
CHANGED
@@ -17,9 +17,9 @@ def load_model(model_path):
|
|
17 |
detection_model = load_model(model_path)
|
18 |
|
19 |
# Function to perform prediction on an image
|
20 |
-
def predict_image(
|
21 |
try:
|
22 |
-
result = detection_model.predict(
|
23 |
img_bgr = result[0].plot()
|
24 |
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # Convert BGR to RGB for PIL image
|
25 |
return out_pilimg
|
@@ -27,9 +27,9 @@ def predict_image(input_img):
|
|
27 |
return f"Error processing image: {str(e)}"
|
28 |
|
29 |
# Function to perform prediction on a video
|
30 |
-
def predict_video(
|
31 |
try:
|
32 |
-
result_video = detection_model.predict(
|
33 |
|
34 |
# Find the processed video output path
|
35 |
processed_video_path = str(result_video[0].save_dir / result_video[0].path.name)
|
@@ -41,7 +41,7 @@ def predict_video(video_path):
|
|
41 |
image_interface = gr.Interface(
|
42 |
fn=predict_image,
|
43 |
inputs=gr.Image(type="pil"),
|
44 |
-
outputs=gr.Image(type="pil"),
|
45 |
title="Object Detection - Image",
|
46 |
description="Upload an image and the model will detect objects."
|
47 |
)
|
@@ -49,7 +49,7 @@ image_interface = gr.Interface(
|
|
49 |
video_interface = gr.Interface(
|
50 |
fn=predict_video,
|
51 |
inputs=gr.Video(),
|
52 |
-
outputs=gr.File(label="
|
53 |
title="Object Detection - Video",
|
54 |
description="Upload a video and the model will detect objects."
|
55 |
)
|
|
|
17 |
detection_model = load_model(model_path)
|
18 |
|
19 |
# Function to perform prediction on an image
|
20 |
+
def predict_image(Input_Image):
|
21 |
try:
|
22 |
+
result = detection_model.predict(Input_Image, conf=0.5, iou=0.6)
|
23 |
img_bgr = result[0].plot()
|
24 |
out_pilimg = Image.fromarray(img_bgr[..., ::-1]) # Convert BGR to RGB for PIL image
|
25 |
return out_pilimg
|
|
|
27 |
return f"Error processing image: {str(e)}"
|
28 |
|
29 |
# Function to perform prediction on a video
|
30 |
+
def predict_video(Input_Video):
|
31 |
try:
|
32 |
+
result_video = detection_model.predict(Input_Video, conf=0.5, iou=0.6, save=True)
|
33 |
|
34 |
# Find the processed video output path
|
35 |
processed_video_path = str(result_video[0].save_dir / result_video[0].path.name)
|
|
|
41 |
image_interface = gr.Interface(
|
42 |
fn=predict_image,
|
43 |
inputs=gr.Image(type="pil"),
|
44 |
+
outputs=gr.Image(type="pil", label="Processed_Image"),
|
45 |
title="Object Detection - Image",
|
46 |
description="Upload an image and the model will detect objects."
|
47 |
)
|
|
|
49 |
video_interface = gr.Interface(
|
50 |
fn=predict_video,
|
51 |
inputs=gr.Video(),
|
52 |
+
outputs=gr.File(label="Processed_Video"),
|
53 |
title="Object Detection - Video",
|
54 |
description="Upload a video and the model will detect objects."
|
55 |
)
|