datbkpro commited on
Commit
edfe5ba
·
verified ·
1 Parent(s): e33aef8

Update ui/tabs.py

Browse files
Files changed (1) hide show
  1. ui/tabs.py +17 -14
ui/tabs.py CHANGED
@@ -53,20 +53,24 @@ def create_all_tabs(audio_service: AudioService, chat_service: ChatService,
53
  with gr.Tab("Stream Object Detection"):
54
  create_streaming_object_detection()
55
  def create_sambanova_voice_tab(sambanova_service):
56
- """Tạo tab Sambanova Voice AI - Simplified version"""
57
 
58
  with gr.Blocks() as sambanova_tab:
59
  gr.Markdown("## 🤖 Sambanova Voice AI - Llama 3.2 3B")
60
  gr.Markdown("Trò chuyện voice-to-voice với model Llama 3.2 3B thông qua Sambanova API")
61
 
62
- # State variables
63
  chatbot = gr.Chatbot(
64
  type="messages",
65
  value=[],
66
  label="💬 Hội thoại Voice",
67
- height=400
 
 
 
 
 
68
  )
69
- conversation_state = gr.State(value=[])
70
 
71
  with gr.Row():
72
  with gr.Column(scale=1):
@@ -83,30 +87,29 @@ def create_sambanova_voice_tab(sambanova_service):
83
  ✅ Llama 3.2 3B model
84
  ✅ Stop-word activation
85
  ✅ Multi-language support
86
-
87
- **Lưu ý:** Chức năng voice output đang được phát triển
88
  """)
89
 
90
- # Tạo stream
91
- stream = sambanova_service.create_stream()
92
- webrtc = stream.ui()
93
 
94
  # Manual text input fallback
95
  with gr.Accordion("📝 Text Input (Fallback)", open=False):
96
  text_input = gr.Textbox(
97
  label="Nhập tin nhắn",
98
  placeholder="Nhập tin nhắn text nếu voice không hoạt động...",
99
- lines=2
 
100
  )
101
- text_send_btn = gr.Button("📤 Gửi tin nhắn")
102
 
103
  # Controls
104
  with gr.Row():
105
- clear_btn = gr.Button("🗑️ Xóa hội thoại", variant="secondary")
106
  status_display = gr.Textbox(
107
  label="Trạng thái",
108
  value="✅ Sẵn sàng kết nối...",
109
- interactive=False
 
110
  )
111
 
112
  with gr.Column(scale=2):
@@ -169,7 +172,7 @@ def create_sambanova_voice_tab(sambanova_service):
169
  error_msg = f"❌ Lỗi: {str(e)}"
170
  return current_chatbot, current_state, error_msg
171
 
172
- # Kết nối events
173
  webrtc.on_additional_outputs(
174
  handle_additional_outputs,
175
  outputs=[chatbot, conversation_state, status_display]
 
53
  with gr.Tab("Stream Object Detection"):
54
  create_streaming_object_detection()
55
  def create_sambanova_voice_tab(sambanova_service):
56
+ """Tạo tab Sambanova Voice AI - Fixed duplicate block error"""
57
 
58
  with gr.Blocks() as sambanova_tab:
59
  gr.Markdown("## 🤖 Sambanova Voice AI - Llama 3.2 3B")
60
  gr.Markdown("Trò chuyện voice-to-voice với model Llama 3.2 3B thông qua Sambanova API")
61
 
62
+ # State variables với ID duy nhất
63
  chatbot = gr.Chatbot(
64
  type="messages",
65
  value=[],
66
  label="💬 Hội thoại Voice",
67
+ height=400,
68
+ elem_id="sambanova_main_chatbot"
69
+ )
70
+ conversation_state = gr.State(
71
+ value=[],
72
+ elem_id="sambanova_main_state"
73
  )
 
74
 
75
  with gr.Row():
76
  with gr.Column(scale=1):
 
87
  ✅ Llama 3.2 3B model
88
  ✅ Stop-word activation
89
  ✅ Multi-language support
 
 
90
  """)
91
 
92
+ # WebRTC component - chỉ gọi một lần
93
+ webrtc = sambanova_service.get_ui_component()
 
94
 
95
  # Manual text input fallback
96
  with gr.Accordion("📝 Text Input (Fallback)", open=False):
97
  text_input = gr.Textbox(
98
  label="Nhập tin nhắn",
99
  placeholder="Nhập tin nhắn text nếu voice không hoạt động...",
100
+ lines=2,
101
+ elem_id="sambanova_text_input"
102
  )
103
+ text_send_btn = gr.Button("📤 Gửi tin nhắn", elem_id="sambanova_send_btn")
104
 
105
  # Controls
106
  with gr.Row():
107
+ clear_btn = gr.Button("🗑️ Xóa hội thoại", variant="secondary", elem_id="sambanova_clear_btn")
108
  status_display = gr.Textbox(
109
  label="Trạng thái",
110
  value="✅ Sẵn sàng kết nối...",
111
+ interactive=False,
112
+ elem_id="sambanova_status"
113
  )
114
 
115
  with gr.Column(scale=2):
 
172
  error_msg = f"❌ Lỗi: {str(e)}"
173
  return current_chatbot, current_state, error_msg
174
 
175
+ # Kết nối events - chỉ kết nối một lần
176
  webrtc.on_additional_outputs(
177
  handle_additional_outputs,
178
  outputs=[chatbot, conversation_state, status_display]