Update ui/components.py
Browse files- 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
|
| 110 |
with gr.Group():
|
| 111 |
-
gr.Markdown("## 🎤 Trò chuyện giọng nói thời gian thực
|
| 112 |
-
gr.Markdown("
|
| 113 |
|
| 114 |
with gr.Row():
|
| 115 |
with gr.Column(scale=1):
|
| 116 |
-
#
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
| 120 |
)
|
| 121 |
|
| 122 |
-
#
|
| 123 |
-
|
| 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="
|
| 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="
|
| 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
|
| 173 |
-
|
| 174 |
-
conversation_history = gr.State(value=[])
|
| 175 |
|
| 176 |
return (
|
| 177 |
-
|
| 178 |
-
realtime_transcription, ai_response, tts_output,
|
| 179 |
-
|
| 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 và 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 và 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 |
)
|