oilbread commited on
Commit
f028118
·
1 Parent(s): b6adecd
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -5,7 +5,7 @@ import onnx
5
  import numpy as np
6
  import gradio as gr
7
  from huggingface_hub import hf_hub_download
8
-
9
  # --- YOLOv5n ONNX 추론 클래스 (간단히 구현) ---
10
  import onnxruntime
11
 
@@ -93,16 +93,18 @@ def detection(image, weight_file, conf_threshold=0.3):
93
 
94
  # --- Gradio UI ---
95
  with gr.Blocks() as demo:
96
- gr.Markdown("# YOLOv5n ONNX Detection with Weight Upload")
97
 
98
  weight_file = gr.File(label="Upload YOLOv5n weights (.pt or .onnx)", file_types=['.pt', '.onnx'])
99
  conf_threshold = gr.Slider(0.0, 1.0, value=0.3, step=0.05, label="Confidence Threshold")
100
- input_image = gr.Image(source="webcam", streaming=True)
101
- output_image = gr.Image()
102
 
103
- input_image.stream(
 
 
 
 
104
  fn=detection,
105
- inputs=[input_image, weight_file, conf_threshold],
106
  outputs=output_image,
107
  every=0.1,
108
  )
 
5
  import numpy as np
6
  import gradio as gr
7
  from huggingface_hub import hf_hub_download
8
+ from gradio_webrtc import WebRTCStreamer
9
  # --- YOLOv5n ONNX 추론 클래스 (간단히 구현) ---
10
  import onnxruntime
11
 
 
93
 
94
  # --- Gradio UI ---
95
  with gr.Blocks() as demo:
96
+ gr.Markdown("# YOLOv5n ONNX Detection with Weight Upload (WebRTC)")
97
 
98
  weight_file = gr.File(label="Upload YOLOv5n weights (.pt or .onnx)", file_types=['.pt', '.onnx'])
99
  conf_threshold = gr.Slider(0.0, 1.0, value=0.3, step=0.05, label="Confidence Threshold")
 
 
100
 
101
+ rtc_stream = WebRTCStreamer(label="WebRTC Webcam")
102
+
103
+ output_image = gr.Image(label="Detection Output")
104
+
105
+ rtc_stream.stream(
106
  fn=detection,
107
+ inputs=[rtc_stream, weight_file, conf_threshold],
108
  outputs=output_image,
109
  every=0.1,
110
  )