Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,11 +8,11 @@ model_path = MODEL_PATHS["YOLOv8n"]
|
|
| 8 |
model = YOLO(model_path)
|
| 9 |
|
| 10 |
# ---------- Detection Functions ----------
|
| 11 |
-
def detect_image_fn(
|
| 12 |
-
if
|
| 13 |
return None
|
| 14 |
-
|
| 15 |
-
return
|
| 16 |
|
| 17 |
def detect_video_fn(video_file, confidence):
|
| 18 |
if video_file is None:
|
|
@@ -27,7 +27,7 @@ def detect_video_fn(video_file, confidence):
|
|
| 27 |
image_interface = gr.Interface(
|
| 28 |
fn=detect_image_fn,
|
| 29 |
inputs=[
|
| 30 |
-
gr.Image(label="Upload Image"),
|
| 31 |
gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
|
| 32 |
],
|
| 33 |
outputs=gr.Image(label="Predicted Output"),
|
|
@@ -38,7 +38,7 @@ image_interface = gr.Interface(
|
|
| 38 |
video_interface = gr.Interface(
|
| 39 |
fn=detect_video_fn,
|
| 40 |
inputs=[
|
| 41 |
-
gr.Video(label="Upload Video"),
|
| 42 |
gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
|
| 43 |
],
|
| 44 |
outputs=gr.Video(label="Predicted Output"),
|
|
@@ -50,5 +50,5 @@ video_interface = gr.Interface(
|
|
| 50 |
gr.TabbedInterface(
|
| 51 |
[image_interface, video_interface],
|
| 52 |
tab_names=["Image Detection", "Video Detection"]
|
| 53 |
-
).launch(
|
| 54 |
|
|
|
|
| 8 |
model = YOLO(model_path)
|
| 9 |
|
| 10 |
# ---------- Detection Functions ----------
|
| 11 |
+
def detect_image_fn(image, confidence):
|
| 12 |
+
if image is None:
|
| 13 |
return None
|
| 14 |
+
output_paths = detect_from_images([image], model, confidence, return_path=True)
|
| 15 |
+
return output_paths[0] if output_paths else None
|
| 16 |
|
| 17 |
def detect_video_fn(video_file, confidence):
|
| 18 |
if video_file is None:
|
|
|
|
| 27 |
image_interface = gr.Interface(
|
| 28 |
fn=detect_image_fn,
|
| 29 |
inputs=[
|
| 30 |
+
gr.Image(type="filepath", label="Upload Image"),
|
| 31 |
gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
|
| 32 |
],
|
| 33 |
outputs=gr.Image(label="Predicted Output"),
|
|
|
|
| 38 |
video_interface = gr.Interface(
|
| 39 |
fn=detect_video_fn,
|
| 40 |
inputs=[
|
| 41 |
+
gr.Video(type="filepath", label="Upload Video"),
|
| 42 |
gr.Slider(0.1, 1.0, value=0.3, step=0.05, label="Confidence")
|
| 43 |
],
|
| 44 |
outputs=gr.Video(label="Predicted Output"),
|
|
|
|
| 50 |
gr.TabbedInterface(
|
| 51 |
[image_interface, video_interface],
|
| 52 |
tab_names=["Image Detection", "Video Detection"]
|
| 53 |
+
).launch()
|
| 54 |
|