Update
Browse files23 unmodified lines242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757623 unmodified linessegments = results[0].plot()return segments, f'FPS: {int(1 // (end - start))}'def process_webcam(start_button, stop_button, frame):global process, modelif start_button and not process and frame is not None:process = Truemodel = load_yolo_model()return process_frame(frame)elif stop_button and process:process = Falsereturn None, ""def process_video(start_button, stop_button, uploaded_video):global process, modelif start_button and not process and uploaded_video is not None:process = Truemodel = load_yolo_model()cap = cv.VideoCapture(uploaded_video.name)ret, frame = cap.read()if ret:return process_frame(frame)elif stop_button and process:process = Falsereturn None, ""start_button = gr.components.Checkbox(label="Start")stop_button = gr.components.Checkbox(label="Stop")frame = gr.components.Video(label="Webcam Feed")uploaded_video = gr.components.Video(label="Upload Video")webcam_interface = gr.Interface(fn=process_webcam,inputs=[start_button, stop_button, frame],outputs=[gr.components.Image(), gr.components.Textbox()],live=True,title="YOLO Image Segmentation (Webcam)",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.",)video_interface = gr.Interface(fn=process_video,inputs=[start_button, stop_button, uploaded_video],outputs=[gr.components.Image(), gr.components.Textbox()],live=True,title="YOLO Image Segmentation (Video)",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.",)gr.TabbedInterface([webcam_interface, video_interface],tab_names=['Webcam inference', 'Video inference']).launch(share=True)23 unmodified lines242526272829303132333435363738394041424344454647484950515253545556575823 unmodified linessegments = results[0].plot()return segments, f'FPS: {int(1 // (end - start))}'def process_inputs(start_button, stop_button, mode_selection, frame, uploaded_video):global process, modelif start_button and not process:process = Truemodel = load_yolo_model()if mode_selection == "Webcam" and frame is not None:return process_frame(frame)elif mode_selection == "Video" and uploaded_video is not None:cap = cv.VideoCapture(uploaded_video.name)ret, frame = cap.read()if ret:return process_frame(frame)elif stop_button and process:process = Falsereturn None, ""start_button = gr.components.Checkbox(label="Start")stop_button = gr.components.Checkbox(label="Stop")mode_selection = gr.components.Radio(["Webcam", "Video"], label="Mode Selection")frame = gr.components.Video(label="Webcam Feed")uploaded_video = gr.components.Video(label="Upload Video")iface = gr.Interface(fn=process_inputs,inputs=[start_button, stop_button, mode_selection, frame, uploaded_video],outputs=[gr.components.Image(), gr.components.Textbox()],live=True,title="YOLO Image Segmentation",description="This application uses the YOLO model to perform image segmentation on a webcam feed or an uploaded video. Select 'Webcam' or 'Video', upload a video (if applicable), and check 'Start' to begin. Check 'Stop' to end the process.",)iface.launch(share=True)
app.py+15-33