79 lines
No EOL
2.7 KiB
Python
79 lines
No EOL
2.7 KiB
Python
#app/ui/chat_tab.py
|
|
|
|
import asyncio
|
|
from PySide6.QtCore import Qt
|
|
from PySide6.QtWidgets import (
|
|
QFrame,
|
|
QHBoxLayout,
|
|
QLabel,
|
|
QLineEdit,
|
|
QPushButton,
|
|
QTextEdit,
|
|
QVBoxLayout,
|
|
QWidget,
|
|
)
|
|
|
|
|
|
class ChatTab(QWidget):
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent)
|
|
self._init_ui()
|
|
|
|
def _init_ui(self):
|
|
layout = QVBoxLayout(self)
|
|
|
|
# 1. Chat History Display
|
|
self.chat_display = QTextEdit(self)
|
|
self.chat_display.setReadOnly(True)
|
|
self.chat_display.setPlaceholderText(
|
|
"Su conversación aparecerá aquí... (Your conversation will appear here...)"
|
|
)
|
|
layout.addWidget(self.chat_display, stretch=4)
|
|
|
|
# 2. Feedback Panel (Pronunciation & WER Metrics)
|
|
self.feedback_panel = QFrame(self)
|
|
self.feedback_panel.setFrameShape(QFrame.Shape.StyledPanel)
|
|
feedback_layout = QVBoxLayout(self.feedback_panel)
|
|
|
|
self.feedback_label = QLabel("<b>Análisis de Pronunciación:</b>", self)
|
|
self.feedback_content = QLabel("Mantén presionado el botón o habla para evaluar.", self)
|
|
|
|
feedback_layout.addWidget(self.feedback_label)
|
|
feedback_layout.addWidget(self.feedback_content)
|
|
layout.addWidget(self.feedback_panel, stretch=1)
|
|
|
|
# 3. User Input Controls
|
|
input_layout = QHBoxLayout()
|
|
|
|
self.text_input = QLineEdit(self)
|
|
self.text_input.setPlaceholderText("Escribe un mensaje o habla...")
|
|
self.text_input.returnPressed.connect(self._on_send)
|
|
|
|
self.btn_send = QPushButton("Enviar", self)
|
|
self.btn_send.clicked.connect(self._on_send)
|
|
|
|
self.btn_record = QPushButton("🎤 Hablar (Hold Space)", self)
|
|
self.btn_record.clicked.connect(self._on_record_clicked)
|
|
|
|
input_layout.addWidget(self.text_input, stretch=3)
|
|
input_layout.addWidget(self.btn_send)
|
|
input_layout.addWidget(self.btn_record)
|
|
|
|
layout.addLayout(input_layout)
|
|
|
|
def _on_send(self):
|
|
text = self.text_input.text().strip()
|
|
if text:
|
|
self.chat_display.append(f"<b>Tú:</b> {text}")
|
|
self.text_input.clear()
|
|
# Schedule asynchronous processing via asyncio
|
|
asyncio.create_task(self._simulate_assistant_response(text))
|
|
|
|
def _on_record_clicked(self):
|
|
self.chat_display.append("<i>[Escuchando audio local vía mlx-whisper...]</i>")
|
|
|
|
async def _simulate_assistant_response(self, user_text: str):
|
|
# Async coroutine demonstrating QtAsyncio responsiveness
|
|
await asyncio.sleep(1.0)
|
|
response = f"¡Hola! Recibí tu mensaje: '{user_text}'. ¿Cómo te va?"
|
|
self.chat_display.append(f"<b>Asistente:</b> {response}") |