datbkpro commited on
Commit
5082129
·
verified ·
1 Parent(s): 8e78042

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +19 -28
ui/components.py CHANGED
@@ -106,36 +106,28 @@ def create_chat_components() -> tuple:
106
 
107
  return chatbot, state, user_input, send_button, clear_button, chat_tts_output
108
  def create_streaming_voice_components() -> tuple:
109
- """Tạo components cho streaming voice với VAD"""
110
  with gr.Group():
111
- gr.Markdown("## 🎤 Trò chuyện giọng nói thời gian thực với VAD")
112
- gr.Markdown("Hệ thống sẽ tự động phát hiện khi bạn nói dừng, tạo cuộc hội thoại tự nhiên")
113
 
114
  with gr.Row():
115
  with gr.Column(scale=1):
116
- # Voice activity visualization
117
- vad_visualizer = gr.HTML(
118
- value="<div class='vad-visualizer' style='width: 100%;'></div>",
119
- label="Voice Activity"
 
 
120
  )
121
 
122
- # Controls
123
- with gr.Row():
124
- start_listening_btn = gr.Button(
125
- "🎙️ Bắt đầu lắng nghe",
126
- variant="primary",
127
- size="sm"
128
- )
129
- stop_listening_btn = gr.Button(
130
- "🛑 Dừng lắng nghe",
131
- variant="secondary",
132
- size="sm"
133
- )
134
 
135
- # Status
136
  status_display = gr.Textbox(
137
  label="Trạng thái",
138
- value="Chưa lắng nghe",
139
  interactive=False
140
  )
141
 
@@ -148,7 +140,7 @@ def create_streaming_voice_components() -> tuple:
148
  with gr.Column(scale=2):
149
  # Real-time transcription
150
  realtime_transcription = gr.Textbox(
151
- label="🎯 Đang nói...",
152
  lines=2,
153
  interactive=False,
154
  placeholder="Văn bản được chuyển đổi sẽ xuất hiện ở đây..."
@@ -169,12 +161,11 @@ def create_streaming_voice_components() -> tuple:
169
  autoplay=True
170
  )
171
 
172
- # Hidden state components
173
- streaming_state = gr.State(value=False)
174
- conversation_history = gr.State(value=[])
175
 
176
  return (
177
- start_listening_btn, stop_listening_btn, status_display, state_display,
178
- realtime_transcription, ai_response, tts_output, streaming_state,
179
- conversation_history, vad_visualizer
180
  )
 
106
 
107
  return chatbot, state, user_input, send_button, clear_button, chat_tts_output
108
  def create_streaming_voice_components() -> tuple:
109
+ """Tạo components cho streaming voice sử dụng Gradio microphone"""
110
  with gr.Group():
111
+ gr.Markdown("## 🎤 Trò chuyện giọng nói thời gian thực")
112
+ gr.Markdown("Sử dụng microphone của thiết bị để trò chuyện với AI - hoạt động trên cả điện thoại máy tính")
113
 
114
  with gr.Row():
115
  with gr.Column(scale=1):
116
+ # Microphone component - THAY THẾ VAD bằng Gradio Microphone
117
+ microphone = gr.Microphone(
118
+ label="🎙️ Nhấn nói",
119
+ type="numpy",
120
+ streaming=True,
121
+ show_download_button=False
122
  )
123
 
124
+ # Clear conversation button
125
+ clear_btn = gr.Button("🗑️ Xóa hội thoại", variant="secondary", size="sm")
 
 
 
 
 
 
 
 
 
 
126
 
127
+ # Status display
128
  status_display = gr.Textbox(
129
  label="Trạng thái",
130
+ value="Sẵn sàng - nhấn nút microphone để nói",
131
  interactive=False
132
  )
133
 
 
140
  with gr.Column(scale=2):
141
  # Real-time transcription
142
  realtime_transcription = gr.Textbox(
143
+ label="📝 Bạn vừa nói",
144
  lines=2,
145
  interactive=False,
146
  placeholder="Văn bản được chuyển đổi sẽ xuất hiện ở đây..."
 
161
  autoplay=True
162
  )
163
 
164
+ # Hidden state
165
+ conversation_state = gr.State(value={})
 
166
 
167
  return (
168
+ microphone, clear_btn, status_display, state_display,
169
+ realtime_transcription, ai_response, tts_output, conversation_state
170
+ )
171
  )