1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
from typing import Any, Callable, Dict, List
from PySide6.QtCore import QTimer
from PySide6.QtWidgets import QGroupBox, QLabel, QTextEdit, QVBoxLayout, QWidget
from gui.gui_common import ensure_qt_app
AudioActivityProvider = Callable[[], Dict[str, Any]]
RuntimeLogLinesProvider = Callable[[], List[str]]
SubtitleLinesProvider = Callable[[], List[str]]
class _RuntimeDashboard(QWidget):
def __init__(
self,
get_audio_activity: AudioActivityProvider,
get_runtime_logs: RuntimeLogLinesProvider,
get_subtitle_lines: SubtitleLinesProvider,
on_close: Callable[[], None],
) -> None:
super().__init__()
self._get_audio_activity = get_audio_activity
self._get_runtime_logs = get_runtime_logs
self._get_subtitle_lines = get_subtitle_lines
self._on_close = on_close
self._closed = False
self._last_rendered_runtime_logs: str = ""
self._last_rendered_final_logs: str = ""
self.setWindowTitle("auto-live-tl")
self.setMinimumSize(1100, 700)
layout = QVBoxLayout(self)
title = QLabel("auto-live-tl", self)
title.setStyleSheet("font-size: 22px; font-weight: 700; color: #000000;")
layout.addWidget(title)
self.audio_indicator = QLabel("⚪ Idle", self)
self.audio_indicator.setStyleSheet("font-size: 16px; color: #b0b0b0; font-weight: 600;")
layout.addWidget(self.audio_indicator)
self.audio_details = QLabel("RMS 0.00000 | threshold 0.00300", self)
self.audio_details.setStyleSheet("font-size: 13px; color: #9aa0a6;")
layout.addWidget(self.audio_details)
raw_group = QGroupBox("Debug Log (It's recommended to fetch the final data via the SSE API, see the README)", self)
raw_group_layout = QVBoxLayout(raw_group)
raw_title = QLabel("System / Raw Output", raw_group)
raw_group_layout.addWidget(raw_title)
self.runtime_log_view = QTextEdit(raw_group)
self.runtime_log_view.setReadOnly(True)
self.runtime_log_view.setPlaceholderText("Waiting for raw Whisper output...")
self.runtime_log_view.setStyleSheet(
"""
QTextEdit {
background: #111417;
color: #d8dee9;
border: 1px solid #2f3742;
border-radius: 8px;
padding: 8px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 13px;
line-height: 1.4;
}
"""
)
raw_group_layout.addWidget(self.runtime_log_view, 3)
final_title = QLabel("Final (Sent via SSE)", raw_group)
raw_group_layout.addWidget(final_title)
self.final_log_view = QTextEdit(raw_group)
self.final_log_view.setReadOnly(True)
self.final_log_view.setPlaceholderText("Waiting for FINAL output...")
self.final_log_view.setStyleSheet(
"""
QTextEdit {
background: #0f1410;
color: #dcf9dd;
border: 1px solid #2f4a35;
border-radius: 8px;
padding: 8px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 14px;
font-weight: 700;
line-height: 1.6;
}
"""
)
raw_group_layout.addWidget(self.final_log_view, 2)
layout.addWidget(raw_group, 1)
self._timer = QTimer(self)
self._timer.setInterval(150)
self._timer.timeout.connect(self._refresh)
self._timer.start()
self._refresh()
def _shutdown(self) -> None:
if self._closed:
return
self._closed = True
self._timer.stop()
try:
self._on_close()
except Exception:
pass
def closeEvent(self, event: Any) -> None: # type: ignore[override]
self._shutdown()
super().closeEvent(event)
def _refresh(self) -> None:
try:
activity = self._get_audio_activity()
except Exception:
activity = {}
active = bool(activity.get("active", False))
try:
rms = float(activity.get("rms", 0.0))
except (TypeError, ValueError):
rms = 0.0
try:
threshold = float(activity.get("threshold", 0.0))
except (TypeError, ValueError):
threshold = 0.0
if active:
self.audio_indicator.setText("🟢 Audio detected")
self.audio_indicator.setStyleSheet("font-size: 16px; color: #8fd18f; font-weight: 600;")
else:
self.audio_indicator.setText("⚪ Idle")
self.audio_indicator.setStyleSheet("font-size: 16px; color: #b0b0b0; font-weight: 600;")
self.audio_details.setText(f"RMS {rms:.5f} | threshold {threshold:.5f}")
try:
logs = self._get_runtime_logs()
except Exception:
logs = []
runtime_lines = [line for line in logs if "[FINAL]" not in line]
final_lines = [line for line in logs if "[FINAL]" in line]
joined_runtime_logs = "\n".join(runtime_lines)
if joined_runtime_logs != self._last_rendered_runtime_logs:
self._last_rendered_runtime_logs = joined_runtime_logs
self.runtime_log_view.setPlainText(joined_runtime_logs)
log_scroll = self.runtime_log_view.verticalScrollBar()
log_scroll.setValue(log_scroll.maximum())
joined_final_logs = "\n\n".join(final_lines)
if joined_final_logs != self._last_rendered_final_logs:
self._last_rendered_final_logs = joined_final_logs
self.final_log_view.setPlainText(joined_final_logs)
final_scroll = self.final_log_view.verticalScrollBar()
final_scroll.setValue(final_scroll.maximum())
def run_runtime_dashboard(
get_audio_activity: AudioActivityProvider,
get_runtime_logs: RuntimeLogLinesProvider,
get_subtitle_lines: SubtitleLinesProvider,
on_close: Callable[[], None],
) -> None:
app = ensure_qt_app()
dashboard = _RuntimeDashboard(
get_audio_activity=get_audio_activity,
get_runtime_logs=get_runtime_logs,
get_subtitle_lines=get_subtitle_lines,
on_close=on_close,
)
dashboard.show()
app.exec()
|