Update ui/tabs.py
Browse files- ui/tabs.py +2 -58
ui/tabs.py
CHANGED
|
@@ -10,7 +10,7 @@ from services.streaming_voice_service import StreamingVoiceService
|
|
| 10 |
from core.rag_system import EnhancedRAGSystem
|
| 11 |
from core.tts_service import EnhancedTTSService
|
| 12 |
from core.wikipedia_processor import WikipediaProcessor
|
| 13 |
-
from ui.components import create_audio_components, create_chat_components
|
| 14 |
|
| 15 |
def create_all_tabs(audio_service: AudioService, chat_service: ChatService,
|
| 16 |
image_service: ImageService, rag_system: EnhancedRAGSystem,
|
|
@@ -415,61 +415,5 @@ def create_tts_tab(tts_service: EnhancedTTSService):
|
|
| 415 |
inputs=[tts_text_input, tts_language, tts_provider],
|
| 416 |
outputs=[tts_output_audio]
|
| 417 |
)
|
| 418 |
-
|
| 419 |
-
"""Tạo tab streaming voice sử dụng Gradio microphone"""
|
| 420 |
-
|
| 421 |
-
# Create components - SỬA TÊN BIẾN CHO ĐÚNG
|
| 422 |
-
components = create_streaming_voice_components()
|
| 423 |
-
|
| 424 |
-
# Unpack components - CHỈ CÓ 7 GIÁ TRỊ
|
| 425 |
-
(microphone, clear_btn, status_display, state_display,
|
| 426 |
-
transcription, ai_response, tts_output) = components
|
| 427 |
-
|
| 428 |
-
def process_audio_stream(audio_data):
|
| 429 |
-
"""Xử lý audio stream từ microphone"""
|
| 430 |
-
if audio_data is None:
|
| 431 |
-
return "❌ Không có âm thanh", "Vui lòng nói lại", None, "Đang chờ...", {}
|
| 432 |
-
|
| 433 |
-
try:
|
| 434 |
-
print("🎯 Đang xử lý audio stream...")
|
| 435 |
-
|
| 436 |
-
# Xử lý audio
|
| 437 |
-
result = streaming_service.process_streaming_audio(audio_data)
|
| 438 |
-
|
| 439 |
-
# Cập nhật state
|
| 440 |
-
state = streaming_service.get_conversation_state()
|
| 441 |
-
status = f"✅ Đã xử lý - {len(result['transcription'])} ký tự"
|
| 442 |
-
|
| 443 |
-
return result['transcription'], result['response'], result['tts_audio'], status, state
|
| 444 |
-
|
| 445 |
-
except Exception as e:
|
| 446 |
-
error_msg = f"❌ Lỗi xử lý: {str(e)}"
|
| 447 |
-
print(f"Lỗi: {traceback.format_exc()}")
|
| 448 |
-
return error_msg, "Xin lỗi, có lỗi xảy ra", None, "❌ Lỗi", {}
|
| 449 |
-
|
| 450 |
-
def clear_conversation():
|
| 451 |
-
"""Xóa hội thoại"""
|
| 452 |
-
streaming_service.clear_conversation()
|
| 453 |
-
state = streaming_service.get_conversation_state()
|
| 454 |
-
return "", "", None, "🗑️ Đã xóa hội thoại", state
|
| 455 |
-
|
| 456 |
-
# Event handlers
|
| 457 |
-
microphone.stream(
|
| 458 |
-
process_audio_stream,
|
| 459 |
-
inputs=[microphone],
|
| 460 |
-
outputs=[transcription, ai_response, tts_output, status_display, state_display]
|
| 461 |
-
)
|
| 462 |
-
|
| 463 |
-
clear_btn.click(
|
| 464 |
-
clear_conversation,
|
| 465 |
-
outputs=[transcription, ai_response, tts_output, status_display, state_display]
|
| 466 |
-
)
|
| 467 |
-
|
| 468 |
-
# Khởi tạo giá trị ban đầu
|
| 469 |
-
def initialize_tab():
|
| 470 |
-
state = streaming_service.get_conversation_state()
|
| 471 |
-
return "Sẵn sàng - nhấn nút microphone để nói", state
|
| 472 |
-
|
| 473 |
-
# Gọi hàm khởi tạo
|
| 474 |
-
initialize_tab()
|
| 475 |
|
|
|
|
| 10 |
from core.rag_system import EnhancedRAGSystem
|
| 11 |
from core.tts_service import EnhancedTTSService
|
| 12 |
from core.wikipedia_processor import WikipediaProcessor
|
| 13 |
+
from ui.components import create_audio_components, create_chat_components
|
| 14 |
|
| 15 |
def create_all_tabs(audio_service: AudioService, chat_service: ChatService,
|
| 16 |
image_service: ImageService, rag_system: EnhancedRAGSystem,
|
|
|
|
| 415 |
inputs=[tts_text_input, tts_language, tts_provider],
|
| 416 |
outputs=[tts_output_audio]
|
| 417 |
)
|
| 418 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
|