datbkpro commited on
Commit
67bfcbb
·
verified ·
1 Parent(s): 4c41d4a

Update ui/tabs.py

Browse files
Files changed (1) hide show
  1. ui/tabs.py +39 -0
ui/tabs.py CHANGED
@@ -228,6 +228,12 @@ def create_streaming_voice_tab(streaming_service: StreamingVoiceService):
228
  type="numpy",
229
  streaming=True
230
  )
 
 
 
 
 
 
231
 
232
  clear_btn = gr.Button("🗑️ Xóa hội thoại")
233
 
@@ -315,7 +321,27 @@ def create_streaming_voice_tab(streaming_service: StreamingVoiceService):
315
  state = f"VAD: Đã xử lý\nHistory: {len(streaming_service.conversation_history)} messages"
316
  return result['transcription'], result['response'], result['tts_audio'], state
317
  return gr.skip(), gr.skip(), gr.skip(), gr.skip()
 
 
 
 
318
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  # Event handlers đơn giản
320
  start_btn.click(start_vad, outputs=[vad_status, state_info])
321
  stop_btn.click(stop_vad, outputs=[vad_status, state_info])
@@ -330,6 +356,19 @@ def create_streaming_voice_tab(streaming_service: StreamingVoiceService):
330
  clear_chat,
331
  outputs=[transcription_box, response_box, audio_output, state_info]
332
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
  return streaming_tab
335
  def create_image_tab(image_service: ImageService):
 
228
  type="numpy",
229
  streaming=True
230
  )
231
+ with gr.Accordion("📊 Performance Metrics", open=False):
232
+ latency_display = gr.JSON(
233
+ label="Latency Statistics",
234
+ value={}
235
+ )
236
+ refresh_latency_btn = gr.Button("🔄 Refresh Metrics", size="sm")
237
 
238
  clear_btn = gr.Button("🗑️ Xóa hội thoại")
239
 
 
321
  state = f"VAD: Đã xử lý\nHistory: {len(streaming_service.conversation_history)} messages"
322
  return result['transcription'], result['response'], result['tts_audio'], state
323
  return gr.skip(), gr.skip(), gr.skip(), gr.skip()
324
+ def refresh_latency():
325
+ """Làm mới latency metrics"""
326
+ stats = streaming_service.get_latency_stats()
327
+ return stats
328
 
329
+ def update_state_info():
330
+ """Cập nhật thông tin trạng thái với latency"""
331
+ state = streaming_service.get_conversation_state()
332
+
333
+ # Format latency info
334
+ latency_info = state.get('latency_stats', {})
335
+ formatted_state = f"VAD: {'Đang chạy' if state['is_listening'] else 'Dừng'}\n"
336
+ formatted_state += f"Processing: {state['is_processing']}\n"
337
+ formatted_state += f"History: {state['history_length']} messages\n"
338
+ formatted_state += f"Queue: {state['queue_size']}\n"
339
+
340
+ if latency_info.get('total', {}).get('count', 0) > 0:
341
+ total_avg = latency_info['total']['recent_avg']
342
+ formatted_state += f"Avg Latency: {total_avg:.2f}s"
343
+
344
+ return formatted_state, latency_info
345
  # Event handlers đơn giản
346
  start_btn.click(start_vad, outputs=[vad_status, state_info])
347
  stop_btn.click(stop_vad, outputs=[vad_status, state_info])
 
356
  clear_chat,
357
  outputs=[transcription_box, response_box, audio_output, state_info]
358
  )
359
+
360
+ # Thêm event cho refresh latency
361
+ refresh_latency_btn.click(
362
+ refresh_latency,
363
+ outputs=[latency_display]
364
+ )
365
+
366
+ # Tự động cập nhật latency mỗi 5 giây
367
+ streaming_tab.load(
368
+ update_state_info,
369
+ outputs=[state_info, latency_display],
370
+ every=5000
371
+ )
372
 
373
  return streaming_tab
374
  def create_image_tab(image_service: ImageService):