From b6d8e6a57ff56a42a6b2fc1f78ed70ac3df6f7f6 Mon Sep 17 00:00:00 2001 From: Freddy Boulton Date: Mon, 27 Jan 2025 16:16:42 -0500 Subject: [PATCH] Fix (#52) Co-authored-by: Freddy Boulton --- demo/video_send_output.py | 14 +++++++------- frontend/shared/Webcam.svelte | 1 + pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/demo/video_send_output.py b/demo/video_send_output.py index 3ac5c9b..eace5e6 100644 --- a/demo/video_send_output.py +++ b/demo/video_send_output.py @@ -48,10 +48,10 @@ else: rtc_configuration = None -def detection(frame, conf_threshold=0.3): - print("frame.shape", frame.shape) - frame = cv2.flip(frame, 0) - return AdditionalOutputs(1) +def detection(image, conf_threshold=0.3): + image = cv2.resize(image, (model.input_width, model.input_height)) + new_image = model.detect_objects(image, conf_threshold) + return cv2.resize(new_image, (500, 500)) css = """.my-group {max-width: 600px !important; max-height: 600 !important;} @@ -76,7 +76,8 @@ with gr.Blocks(css=css) as demo: with gr.Group(elem_classes=["my-group"]): image = WebRTC( label="Stream", rtc_configuration=rtc_configuration, - mode="send", + mode="send-receive", + modality="video", track_constraints={"width": {"exact": 800}, "height": {"exact": 600}, "aspectRatio": {"exact": 1.33333} @@ -93,8 +94,7 @@ with gr.Blocks(css=css) as demo: number = gr.Number() image.stream( - fn=detection, inputs=[image, conf_threshold], outputs=[image], time_limit=10 + fn=detection, inputs=[image, conf_threshold], outputs=[image], time_limit=90 ) - image.on_additional_outputs(lambda n: n, outputs=number) demo.launch() diff --git a/frontend/shared/Webcam.svelte b/frontend/shared/Webcam.svelte index 5809826..7cd229d 100644 --- a/frontend/shared/Webcam.svelte +++ b/frontend/shared/Webcam.svelte @@ -135,6 +135,7 @@ case "connected": stream_state = "open"; _time_limit = time_limit; + dispatch("tick"); break; case "disconnected": stream_state = "closed"; diff --git a/pyproject.toml b/pyproject.toml index 207a178..8298ae7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ build-backend = "hatchling.build" [project] name = "gradio_webrtc" -version = "0.0.29" +version = "0.0.30" description = "Stream images in realtime with webrtc" readme = "README.md" license = "apache-2.0"