oilbread commited on
Commit
c8907bd
ยท
1 Parent(s): a59a5de
Files changed (1) hide show
  1. app.py +159 -1
app.py CHANGED
@@ -125,4 +125,162 @@ def process_stream_frame(frame):
125
  except Empty:
126
  return frame
127
 
128
- # ์ดํ•˜ Gradio UI ๊ตฌ์„ฑ ๋™์ผ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  except Empty:
126
  return frame
127
 
128
+ # ๋ฉ”์ธ ์•ฑ
129
+ with gr.Blocks(title="์ดˆ๊ณ ์† YOLO ์ŠคํŠธ๋ฆฌ๋ฐ") as app:
130
+ gr.Markdown("""
131
+ # โšก ์ดˆ๊ณ ์† YOLO ์ŠคํŠธ๋ฆฌ๋ฐ ํƒ์ง€
132
+
133
+ **์†๋„ ์ตœ์ ํ™” ๊ธฐ๋ฒ•๋“ค:**
134
+ - YOLOv5n ์‚ฌ์šฉ (๊ฐ€์žฅ ๋น ๋ฅธ ๋ชจ๋ธ)
135
+ - ์ž‘์€ ์ž…๋ ฅ ํฌ๊ธฐ (320x320, 160x160)
136
+ - FP16 ๋ฐ˜์ •๋ฐ€๋„ ์—ฐ์‚ฐ
137
+ - ํ ํฌ๊ธฐ ์ตœ์†Œํ™”
138
+ - ํ”„๋ ˆ์ž„ ๋“œ๋กญ ํ—ˆ์šฉ
139
+ """)
140
+
141
+ with gr.Tabs():
142
+ with gr.TabItem("๐Ÿš€ ๊ณ ์† ์ŠคํŠธ๋ฆฌ๋ฐ"):
143
+ with gr.Row():
144
+ with gr.Column():
145
+ webcam_input = gr.Image(
146
+ label="๐Ÿ“น ์›น์บ  ์ž…๋ ฅ",
147
+ sources=["webcam"],
148
+ streaming=True,
149
+ width=480,
150
+ height=360
151
+ )
152
+
153
+ with gr.Row():
154
+ start_btn = gr.Button("๐Ÿš€ ์‹œ์ž‘", variant="primary")
155
+ stop_btn = gr.Button("โน๏ธ ์ค‘์ง€", variant="secondary")
156
+
157
+ with gr.Accordion("โš™๏ธ ์„ค์ •", open=True):
158
+ model_select = gr.Dropdown(
159
+ choices=list(FAST_MODELS.keys()) + ["์—…๋กœ๋“œ๋œ ํŒŒ์ผ"],
160
+ value="yolov5n",
161
+ label="๋ชจ๋ธ ์„ ํƒ (์œ„์—์„œ๋ถ€ํ„ฐ ๋น ๋ฆ„)"
162
+ )
163
+
164
+ weight_upload = gr.File(
165
+ label="๊ฐ€์ค‘์น˜ ์—…๋กœ๋“œ",
166
+ file_types=[".pt"],
167
+ visible=False
168
+ )
169
+
170
+ conf_threshold = gr.Slider(
171
+ 0.1, 1.0, 0.3, 0.1,
172
+ label="์‹ ๋ขฐ๋„ ์ž„๊ณ„๊ฐ’"
173
+ )
174
+
175
+ iou_threshold = gr.Slider(
176
+ 0.1, 1.0, 0.5, 0.1,
177
+ label="IoU ์ž„๊ณ„๊ฐ’"
178
+ )
179
+
180
+ with gr.Column():
181
+ stream_output = gr.Image(
182
+ label="๐ŸŽฏ ํƒ์ง€ ๊ฒฐ๊ณผ",
183
+ width=480,
184
+ height=360
185
+ )
186
+
187
+ status_display = gr.Textbox(
188
+ label="๐Ÿ“Š ์ƒํƒœ",
189
+ value="์ค€๋น„ ์™„๋ฃŒ",
190
+ interactive=False
191
+ )
192
+
193
+ with gr.TabItem("โšก ๊ทนํ•œ ์ตœ์ ํ™”"):
194
+ gr.Markdown("""
195
+ ### ๊ทนํ•œ ์ตœ์ ํ™” ๋ชจ๋“œ
196
+ - 160x160 ์ดˆ์†Œํ˜• ์ฒ˜๋ฆฌ
197
+ - ์ตœ์†Œํ•œ์˜ ์‹œ๊ฐํ™”
198
+ - ํ”„๋ ˆ์ž„ ๋“œ๋กญ ํ—ˆ์šฉ
199
+ - ๋ชฉํ‘œ: 60+ FPS
200
+ """)
201
+
202
+ with gr.Row():
203
+ ultra_input = gr.Image(
204
+ label="๐Ÿ“น ๊ทนํ•œ ์ตœ์ ํ™” ์ž…๋ ฅ",
205
+ sources=["webcam"],
206
+ streaming=True,
207
+ width=320,
208
+ height=240
209
+ )
210
+
211
+ ultra_output = gr.Image(
212
+ label="โšก ๊ทนํ•œ ์ตœ์ ํ™” ์ถœ๋ ฅ",
213
+ width=320,
214
+ height=240
215
+ )
216
+
217
+ # ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ
218
+ def toggle_upload(choice):
219
+ return gr.update(visible=(choice == "์—…๋กœ๋“œ๋œ ํŒŒ์ผ"))
220
+
221
+ model_select.change(
222
+ fn=toggle_upload,
223
+ inputs=[model_select],
224
+ outputs=[weight_upload]
225
+ )
226
+
227
+ start_btn.click(
228
+ fn=start_streaming,
229
+ inputs=[model_select, weight_upload, conf_threshold, iou_threshold],
230
+ outputs=[status_display]
231
+ )
232
+
233
+ stop_btn.click(
234
+ fn=stop_streaming,
235
+ outputs=[status_display]
236
+ )
237
+
238
+ # ์ŠคํŠธ๋ฆผ ์ฒ˜๋ฆฌ
239
+ webcam_input.stream(
240
+ fn=process_stream_frame,
241
+ inputs=[webcam_input],
242
+ outputs=[stream_output],
243
+ stream_every=0.02 # 50 FPS ๋ชฉํ‘œ
244
+ )
245
+
246
+ # ๊ทนํ•œ ์ตœ์ ํ™” ์ŠคํŠธ๋ฆผ
247
+ ultra_input.stream(
248
+ fn=ultra_fast_detect,
249
+ inputs=[ultra_input],
250
+ outputs=[ultra_output],
251
+ stream_every=0.016 # 60 FPS ๋ชฉํ‘œ
252
+ )
253
+
254
+ gr.Markdown("""
255
+ ---
256
+ ## ๐Ÿƒโ€โ™‚๏ธ ์†๋„ ๊ฐœ์„  ํŒ
257
+
258
+ ### 1. ๋ชจ๋ธ ์„ ํƒ (๋น ๋ฅธ ์ˆœ์„œ)
259
+ - **YOLOv5n**: ๊ฐ€์žฅ ๋น ๋ฆ„, ์ •ํ™•๋„ ์ ๋‹น
260
+ - **YOLOv5s**: ๋น ๋ฆ„, ์ •ํ™•๋„ ์ข‹์Œ
261
+ - **YOLOv8n**: ๋ณดํ†ต ์†๋„, ๋†’์€ ์ •ํ™•๋„
262
+
263
+ ### 2. ํ•˜๋“œ์›จ์–ด ์ตœ์ ํ™”
264
+ - GPU ์‚ฌ์šฉ (CUDA)
265
+ - ์ถฉ๋ถ„ํ•œ RAM
266
+ - ์›น์บ  ํ•ด์ƒ๋„ ๋‚ฎ์ถ”๊ธฐ
267
+
268
+ ### 3. ์„ค์ • ์ตœ์ ํ™”
269
+ - ๋†’์€ confidence ์ž„๊ณ„๊ฐ’ (0.5+)
270
+ - ์ž‘์€ ์ž…๋ ฅ ํฌ๊ธฐ
271
+ - ๋ถˆํ•„์š”ํ•œ ํ›„์ฒ˜๋ฆฌ ์ œ๊ฑฐ
272
+
273
+ ### 4. ์‹œ์Šคํ…œ ์ตœ์ ํ™”
274
+ - ๋ธŒ๋ผ์šฐ์ € ๋‹ค๋ฅธ ํƒญ ๋‹ซ๊ธฐ
275
+ - ๋ฐฑ๊ทธ๋ผ์šด๋“œ ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ
276
+ - ์›น์บ  ๋“œ๋ผ๏ฟฝ๏ฟฝ๏ฟฝ๋ฒ„ ์—…๋ฐ์ดํŠธ
277
+ """)
278
+
279
+ if __name__ == "__main__":
280
+ app.launch(
281
+ share=True,
282
+ server_name="0.0.0.0",
283
+ server_port=7860,
284
+ show_error=True,
285
+ debug=True
286
+ )