Update
Browse files
app.py
CHANGED
|
@@ -24,33 +24,53 @@ def process_frame(frame):
|
|
| 24 |
segments = results[0].plot()
|
| 25 |
return segments, f'FPS: {int(1 // (end - start))}'
|
| 26 |
|
| 27 |
-
def
|
| 28 |
global process, model
|
| 29 |
-
if
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
return process_frame(frame)
|
| 34 |
-
|
| 35 |
-
process = True
|
| 36 |
-
model = load_yolo_model()
|
| 37 |
-
return process_frame(uploaded_video)
|
| 38 |
-
elif action == "Stop" and process:
|
| 39 |
process = False
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
frame = gr.inputs.Video(label="Webcam Feed")
|
| 44 |
uploaded_video = gr.inputs.Video(label="Upload Video")
|
| 45 |
|
| 46 |
-
|
| 47 |
-
fn=
|
| 48 |
-
inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
outputs=[gr.components.Image(), gr.components.Textbox()],
|
| 50 |
live=True,
|
| 51 |
-
title="YOLO Image Segmentation",
|
| 52 |
-
description="This application uses the YOLO model to perform image segmentation on
|
| 53 |
theme="huggingface"
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
| 24 |
segments = results[0].plot()
|
| 25 |
return segments, f'FPS: {int(1 // (end - start))}'
|
| 26 |
|
| 27 |
+
def process_webcam(start_button, stop_button, frame):
|
| 28 |
global process, model
|
| 29 |
+
if start_button and not process and frame is not None:
|
| 30 |
+
process = True
|
| 31 |
+
model = load_yolo_model()
|
| 32 |
+
return process_frame(frame)
|
| 33 |
+
elif stop_button and process:
|
| 34 |
+
process = False
|
| 35 |
+
return None, ""
|
| 36 |
+
|
| 37 |
+
def process_video(start_button, stop_button, uploaded_video):
|
| 38 |
+
global process, model
|
| 39 |
+
if start_button and not process and uploaded_video is not None:
|
| 40 |
+
process = True
|
| 41 |
+
model = load_yolo_model()
|
| 42 |
+
cap = cv.VideoCapture(uploaded_video.name)
|
| 43 |
+
ret, frame = cap.read()
|
| 44 |
+
if ret:
|
| 45 |
return process_frame(frame)
|
| 46 |
+
elif stop_button and process:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
process = False
|
| 48 |
+
return None, ""
|
| 49 |
|
| 50 |
+
start_button = gr.inputs.Checkbox(label="Start")
|
| 51 |
+
stop_button = gr.inputs.Checkbox(label="Stop")
|
| 52 |
frame = gr.inputs.Video(label="Webcam Feed")
|
| 53 |
uploaded_video = gr.inputs.Video(label="Upload Video")
|
| 54 |
|
| 55 |
+
webcam_interface = gr.Interface(
|
| 56 |
+
fn=process_webcam,
|
| 57 |
+
inputs=[start_button, stop_button, frame],
|
| 58 |
+
outputs=[gr.components.Image(), gr.components.Textbox()],
|
| 59 |
+
live=True,
|
| 60 |
+
title="YOLO Image Segmentation (Webcam)",
|
| 61 |
+
description="This application uses the YOLO model to perform image segmentation on a webcam feed. Check 'Start' to begin. Check 'Stop' to end the process.",
|
| 62 |
+
theme="huggingface"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
video_interface = gr.Interface(
|
| 66 |
+
fn=process_video,
|
| 67 |
+
inputs=[start_button, stop_button, uploaded_video],
|
| 68 |
outputs=[gr.components.Image(), gr.components.Textbox()],
|
| 69 |
live=True,
|
| 70 |
+
title="YOLO Image Segmentation (Video)",
|
| 71 |
+
description="This application uses the YOLO model to perform image segmentation on an uploaded video. Upload a video and check 'Start' to begin. Check 'Stop' to end the process.",
|
| 72 |
theme="huggingface"
|
| 73 |
)
|
| 74 |
|
| 75 |
+
webcam_interface.launch()
|
| 76 |
+
video_interface.launch()
|