Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
# YOLOv8 detection function
|
| 6 |
def detect_objects(image):
|
|
@@ -32,9 +33,9 @@ def detect_objects(image):
|
|
| 32 |
# Get the path to the output image
|
| 33 |
output_image_path = os.path.join(output_dir, "result", os.path.basename(input_image_path))
|
| 34 |
|
| 35 |
-
# Return the output image for display
|
| 36 |
if os.path.exists(output_image_path):
|
| 37 |
-
return output_image_path
|
| 38 |
else:
|
| 39 |
return "Error: Output image not found."
|
| 40 |
|
|
@@ -42,7 +43,7 @@ def detect_objects(image):
|
|
| 42 |
interface = gr.Interface(
|
| 43 |
fn=detect_objects, # The function to call when an image is uploaded
|
| 44 |
inputs=gr.Image(type="pil"), # Accept images as input
|
| 45 |
-
outputs=gr.Image(type="
|
| 46 |
title="YOLOv8 Object Detection",
|
| 47 |
description="Upload an image of floating waste in water, and this app will detect it using YOLOv8."
|
| 48 |
)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import subprocess
|
| 3 |
import os
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
# YOLOv8 detection function
|
| 7 |
def detect_objects(image):
|
|
|
|
| 33 |
# Get the path to the output image
|
| 34 |
output_image_path = os.path.join(output_dir, "result", os.path.basename(input_image_path))
|
| 35 |
|
| 36 |
+
# Return the output image for display as a PIL image
|
| 37 |
if os.path.exists(output_image_path):
|
| 38 |
+
return Image.open(output_image_path)
|
| 39 |
else:
|
| 40 |
return "Error: Output image not found."
|
| 41 |
|
|
|
|
| 43 |
interface = gr.Interface(
|
| 44 |
fn=detect_objects, # The function to call when an image is uploaded
|
| 45 |
inputs=gr.Image(type="pil"), # Accept images as input
|
| 46 |
+
outputs=gr.Image(type="pil"), # Return a PIL image for display
|
| 47 |
title="YOLOv8 Object Detection",
|
| 48 |
description="Upload an image of floating waste in water, and this app will detect it using YOLOv8."
|
| 49 |
)
|