import gradio as gr from gradio_webrtc import WebRTC import cv2 import os def generation(): url = 0 cap = cv2.VideoCapture(url) iterating = True while iterating: iterating, frame = cap.read() frame=cv2.flip(frame,1) yield frame with gr.Blocks() as demo: image = WebRTC(label="Stream", mode="receive", modality="video", height=480, width=640) conf_threshold = gr.Slider( label="Confidence Threshold", minimum=0.0, maximum=1.0, step=0.05, value=0.30, ) button = gr.Button("Start", variant="primary") image.stream( fn=generation, inputs=None, outputs=[image], trigger=button.click ) if __name__ == "__main__": demo.launch() # import gradio as gr # from gradio_webrtc import WebRTC # with gr.Blocks() as demo: # image = WebRTC(label="Stream", mode="send-receive", modality="video") # conf_threshold = gr.Slider( # label="Confidence Threshold", # minimum=0.0, # maximum=1.0, # step=0.05, # value=0.30, # ) # image.stream( # inputs=[image, conf_threshold], # outputs=[image], time_limit=10 # ) # if __name__ == "__main__": # demo.launch()