11import threading
2- from functools import partial
32from pathlib import Path
4-
53import yaml
64from PySide6 .QtCore import Qt
75from PySide6 .QtWidgets import (
86 QWidget , QHBoxLayout , QVBoxLayout , QPushButton , QFileDialog , QLabel , QComboBox , QSlider
97)
10-
118from module_transcribe import WhisperTranscriber
129from utilities import my_cprint
10+ from constants import WHISPER_MODELS
1311
1412class TranscriberToolSettingsTab (QWidget ):
1513 CONFIG_FILE = 'config.yaml'
1614
1715 def __init__ (self ):
1816 super ().__init__ ()
1917 self .selected_audio_file = None
20-
2118 self .create_layout ()
2219
2320 def read_config (self ):
@@ -26,40 +23,36 @@ def read_config(self):
2623
2724 def create_layout (self ):
2825 main_layout = QVBoxLayout ()
29-
3026 model_selection_hbox = QHBoxLayout ()
31- model_selection_hbox .addWidget (QLabel ("Whisper Model" ))
27+ model_selection_hbox .addWidget (QLabel ("Model" ))
3228 self .model_combo = QComboBox ()
33-
34- self .model_name_mapping = {f"{ size } - { precision } " : f"ctranslate2-4you/whisper-{ size } -ct2-{ precision } "
35- for size in ["large-v2" , "medium.en" , "small.en" ]
36- for precision in ["float32" , "float16" ]}
37-
38- self .model_combo .addItems (list (self .model_name_mapping .keys ()))
39-
29+
30+ # Use the WHISPER_MODELS dictionary to populate the combo box
31+ self .model_combo .addItems (WHISPER_MODELS .keys ())
32+
4033 model_selection_hbox .addWidget (self .model_combo )
41-
42- model_selection_hbox .addWidget (QLabel ("Speed:" ))
43-
34+ model_selection_hbox .addWidget (QLabel ("Batch:" ))
4435 self .slider_label = QLabel ("8" )
4536 self .number_slider = QSlider (Qt .Horizontal )
4637 self .number_slider .setMinimum (1 )
4738 self .number_slider .setMaximum (150 )
4839 self .number_slider .setValue (8 )
4940 self .number_slider .valueChanged .connect (self .update_slider_label )
50-
5141 model_selection_hbox .addWidget (self .number_slider )
5242 model_selection_hbox .addWidget (self .slider_label )
53-
43+
44+ model_selection_hbox .setStretchFactor (self .model_combo , 2 )
45+ model_selection_hbox .setStretchFactor (self .number_slider , 2 )
46+
5447 main_layout .addLayout (model_selection_hbox )
5548
5649 hbox = QHBoxLayout ()
5750 self .select_file_button = QPushButton ("Select Audio File" )
58- self .select_file_button .clicked .connect (lambda : self .select_audio_file () )
51+ self .select_file_button .clicked .connect (self .select_audio_file )
5952 hbox .addWidget (self .select_file_button )
6053
6154 self .transcribe_button = QPushButton ("Transcribe" )
62- self .transcribe_button .clicked .connect (lambda : self .start_transcription () )
55+ self .transcribe_button .clicked .connect (self .start_transcription )
6356 hbox .addWidget (self .transcribe_button )
6457
6558 main_layout .addLayout (hbox )
@@ -89,17 +82,16 @@ def start_transcription(self):
8982 if not self .selected_audio_file :
9083 print ("Please select an audio file." )
9184 return
92-
93- selected_model = self .model_combo .currentText ()
94- selected_model_identifier = self .model_name_mapping .get (selected_model , selected_model )
95-
96- selected_compute_type = selected_model .rsplit (' - ' , 1 )[- 1 ]
9785
86+ selected_model_key = self .model_combo .currentText ()
9887 selected_batch_size = int (self .slider_label .text ())
99-
88+
10089 def transcription_thread ():
101- transcriber = WhisperTranscriber (model_identifier = selected_model_identifier , batch_size = selected_batch_size , compute_type = selected_compute_type )
90+ transcriber = WhisperTranscriber (
91+ model_key = selected_model_key ,
92+ batch_size = selected_batch_size
93+ )
10294 transcriber .start_transcription_process (self .selected_audio_file )
10395 my_cprint ("Transcription created and ready to be input into vector database." , 'green' )
104-
96+
10597 threading .Thread (target = transcription_thread , daemon = True ).start ()
0 commit comments