|
1 | 1 | from PySide6.QtWidgets import (
|
2 |
| - QLabel, QComboBox, QWidget, QGridLayout, QPushButton, QFileDialog, QCheckBox, QApplication |
| 2 | + QLabel, QComboBox, QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QFileDialog, QCheckBox, QApplication |
3 | 3 | )
|
4 |
| -from PySide6.QtCore import QThread, Qt |
| 4 | +from PySide6.QtCore import Qt |
5 | 5 | import ctranslate2
|
6 | 6 | import yaml
|
7 | 7 | from transcribe_module import TranscribeFile
|
8 | 8 |
|
9 |
| -class TranscriptionThread(QThread): |
10 |
| - def __init__(self, transcriber): |
11 |
| - super().__init__() |
12 |
| - self.transcriber = transcriber |
13 |
| - |
14 |
| - def run(self): |
15 |
| - try: |
16 |
| - # Run the transcription process |
17 |
| - self.transcriber.transcribe_to_file() |
18 |
| - print("Transcription completed and saved in 'Docs_for_DB' directory.") |
19 |
| - except FileNotFoundError as e: |
20 |
| - print(f"File not found error: {e}") |
21 |
| - except Exception as e: |
22 |
| - print(f"An error occurred during transcription: {e}") |
23 |
| - |
24 | 9 | class TranscriberToolSettingsTab(QWidget):
|
25 | 10 |
|
26 | 11 | def __init__(self):
|
@@ -68,55 +53,64 @@ def update_quantization(self, device_combo, quantization_combo):
|
68 | 53 | quantization_combo.addItems(quantizations)
|
69 | 54 |
|
70 | 55 | def create_layout(self):
|
71 |
| - layout = QGridLayout() |
72 |
| - |
73 |
| - def add_widget(widget_class, text, row, column, colspan=1, signal_slot=None, items=None): |
74 |
| - widget = widget_class() |
75 |
| - if widget_class in [QLabel, QPushButton]: |
76 |
| - widget.setText(text) |
77 |
| - if signal_slot: |
78 |
| - widget.clicked.connect(signal_slot) |
79 |
| - if widget_class is QComboBox and items: |
80 |
| - widget.addItems(items) |
81 |
| - layout.addWidget(widget, row, column, 1, colspan) |
82 |
| - return widget |
83 |
| - |
84 |
| - # Model |
85 |
| - add_widget(QLabel, "Model", 0, 0) |
86 |
| - self.model_combo = add_widget(QComboBox, None, 0, 1, items=["tiny", "tiny.en", "base", "base.en", "small", "small.en", "medium", "medium.en", "large-v2"]) |
87 |
| - |
88 |
| - # Quantization |
89 |
| - add_widget(QLabel, "Quant", 0, 2) |
90 |
| - self.quantization_combo = add_widget(QComboBox, None, 0, 3) |
91 |
| - |
92 |
| - # Device |
93 |
| - add_widget(QLabel, "Device", 0, 4) |
| 56 | + main_layout = QVBoxLayout() |
| 57 | + |
| 58 | + # First horizontal layout |
| 59 | + hbox1 = QHBoxLayout() |
| 60 | + hbox1.addWidget(QLabel("Model")) |
| 61 | + self.model_combo = QComboBox() |
| 62 | + self.model_combo.addItems(["tiny", "tiny.en", "base", "base.en", "small", "small.en", "medium", "medium.en", "large-v2"]) |
| 63 | + hbox1.addWidget(self.model_combo) |
| 64 | + |
| 65 | + hbox1.addWidget(QLabel("Quant")) |
| 66 | + self.quantization_combo = QComboBox() |
| 67 | + hbox1.addWidget(self.quantization_combo) |
| 68 | + |
| 69 | + hbox1.addWidget(QLabel("Device")) |
94 | 70 | device_options = ["cpu"] + ["cuda"] if self.has_cuda_device() else []
|
95 |
| - self.device_combo = add_widget(QComboBox, None, 0, 5, items=device_options) |
| 71 | + self.device_combo = QComboBox() |
| 72 | + self.device_combo.addItems(device_options) |
| 73 | + self.device_combo.currentTextChanged.connect(lambda: self.update_quantization(self.device_combo, self.quantization_combo)) |
| 74 | + self.update_quantization(self.device_combo, self.quantization_combo) |
| 75 | + hbox1.addWidget(self.device_combo) |
96 | 76 |
|
97 |
| - # Timestamp and Translate Labels with Checkboxes |
98 |
| - add_widget(QLabel, "Timestamps", 1, 0) |
99 |
| - self.timestamp_checkbox = add_widget(QCheckBox, None, 1, 1) |
100 |
| - add_widget(QLabel, "Translate", 1, 2) |
101 |
| - self.translate_checkbox = add_widget(QCheckBox, None, 1, 3) |
| 77 | + main_layout.addLayout(hbox1) |
102 | 78 |
|
103 |
| - # Language Label and ComboBox |
104 |
| - add_widget(QLabel, "Language", 1, 4) |
105 |
| - self.language_combo = add_widget(QComboBox, None, 1, 5, items=["Option 1", "Option 2", "Option 3"]) |
| 79 | + # Second horizontal layout |
| 80 | + hbox2 = QHBoxLayout() |
| 81 | + hbox2.addWidget(QLabel("Timestamps")) |
| 82 | + self.timestamp_checkbox = QCheckBox() |
| 83 | + hbox2.addWidget(self.timestamp_checkbox) |
106 | 84 |
|
107 |
| - # Select Audio File Button |
108 |
| - self.select_file_button = add_widget(QPushButton, "Select Audio File", 2, 0, 3, signal_slot=self.select_audio_file) |
| 85 | + hbox2.addWidget(QLabel("Translate")) |
| 86 | + self.translate_checkbox = QCheckBox() |
| 87 | + hbox2.addWidget(self.translate_checkbox) |
109 | 88 |
|
110 |
| - # Transcribe/Translate Button |
111 |
| - self.transcribe_translate_button = add_widget(QPushButton, "Transcribe/Translate", 2, 3, 3, signal_slot=self.start_transcription) |
| 89 | + hbox2.addWidget(QLabel("Language")) |
| 90 | + self.language_combo = QComboBox() |
| 91 | + self.language_combo.addItems(["Option 1", "Option 2", "Option 3"]) |
| 92 | + hbox2.addWidget(self.language_combo) |
112 | 93 |
|
113 |
| - # Update Settings Button |
114 |
| - self.update_settings_button = add_widget(QPushButton, "Update Settings", 3, 0, 6, signal_slot=self.save_settings) |
| 94 | + main_layout.addLayout(hbox2) |
115 | 95 |
|
116 |
| - self.device_combo.currentTextChanged.connect(lambda: self.update_quantization(self.device_combo, self.quantization_combo)) |
117 |
| - self.update_quantization(self.device_combo, self.quantization_combo) |
| 96 | + # Third horizontal layout |
| 97 | + hbox3 = QHBoxLayout() |
| 98 | + self.select_file_button = QPushButton("Select Audio File") |
| 99 | + self.select_file_button.clicked.connect(self.select_audio_file) |
| 100 | + hbox3.addWidget(self.select_file_button) |
| 101 | + |
| 102 | + self.transcribe_translate_button = QPushButton("Transcribe/Translate") |
| 103 | + self.transcribe_translate_button.clicked.connect(self.start_transcription) |
| 104 | + hbox3.addWidget(self.transcribe_translate_button) |
| 105 | + |
| 106 | + main_layout.addLayout(hbox3) |
| 107 | + |
| 108 | + # Update settings button (without a horizontal layout) |
| 109 | + self.update_settings_button = QPushButton("Update Settings") |
| 110 | + self.update_settings_button.clicked.connect(self.save_settings) |
| 111 | + main_layout.addWidget(self.update_settings_button) |
118 | 112 |
|
119 |
| - self.setLayout(layout) |
| 113 | + self.setLayout(main_layout) |
120 | 114 |
|
121 | 115 | def select_audio_file(self):
|
122 | 116 | audio_file_filter = "Audio Files (*.mp3 *.wav *.flac *.mp4 *.wma *.mpeg *.mpga *.m4a *.webm *.ogg *.oga *.)"
|
@@ -153,13 +147,11 @@ def update_config(self, file_to_transcribe=None, **kwargs):
|
153 | 147 |
|
154 | 148 | def start_transcription(self):
|
155 | 149 | if self.selected_audio_file:
|
156 |
| - transcriber = TranscribeFile() |
157 |
| - self.transcription_thread = TranscriptionThread(transcriber) |
158 |
| - self.transcription_thread.start() |
| 150 | + transcriber = TranscribeFile(self.selected_audio_file) |
| 151 | + transcriber.start_transcription_thread() |
159 | 152 | else:
|
160 | 153 | print("Please select an audio file first.")
|
161 | 154 |
|
162 |
| -# Only used if ran standalone |
163 | 155 | if __name__ == "__main__":
|
164 | 156 | app = QApplication([])
|
165 | 157 | window = TranscriberToolSettingsTab()
|
|
0 commit comments