mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
Fix (#52)
Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local>
This commit is contained in:
@@ -48,10 +48,10 @@ else:
|
|||||||
rtc_configuration = None
|
rtc_configuration = None
|
||||||
|
|
||||||
|
|
||||||
def detection(frame, conf_threshold=0.3):
|
def detection(image, conf_threshold=0.3):
|
||||||
print("frame.shape", frame.shape)
|
image = cv2.resize(image, (model.input_width, model.input_height))
|
||||||
frame = cv2.flip(frame, 0)
|
new_image = model.detect_objects(image, conf_threshold)
|
||||||
return AdditionalOutputs(1)
|
return cv2.resize(new_image, (500, 500))
|
||||||
|
|
||||||
|
|
||||||
css = """.my-group {max-width: 600px !important; max-height: 600 !important;}
|
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"]):
|
with gr.Group(elem_classes=["my-group"]):
|
||||||
image = WebRTC(
|
image = WebRTC(
|
||||||
label="Stream", rtc_configuration=rtc_configuration,
|
label="Stream", rtc_configuration=rtc_configuration,
|
||||||
mode="send",
|
mode="send-receive",
|
||||||
|
modality="video",
|
||||||
track_constraints={"width": {"exact": 800},
|
track_constraints={"width": {"exact": 800},
|
||||||
"height": {"exact": 600},
|
"height": {"exact": 600},
|
||||||
"aspectRatio": {"exact": 1.33333}
|
"aspectRatio": {"exact": 1.33333}
|
||||||
@@ -93,8 +94,7 @@ with gr.Blocks(css=css) as demo:
|
|||||||
number = gr.Number()
|
number = gr.Number()
|
||||||
|
|
||||||
image.stream(
|
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()
|
demo.launch()
|
||||||
|
|||||||
@@ -135,6 +135,7 @@
|
|||||||
case "connected":
|
case "connected":
|
||||||
stream_state = "open";
|
stream_state = "open";
|
||||||
_time_limit = time_limit;
|
_time_limit = time_limit;
|
||||||
|
dispatch("tick");
|
||||||
break;
|
break;
|
||||||
case "disconnected":
|
case "disconnected":
|
||||||
stream_state = "closed";
|
stream_state = "closed";
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ build-backend = "hatchling.build"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "gradio_webrtc"
|
name = "gradio_webrtc"
|
||||||
version = "0.0.29"
|
version = "0.0.30"
|
||||||
description = "Stream images in realtime with webrtc"
|
description = "Stream images in realtime with webrtc"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "apache-2.0"
|
license = "apache-2.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user