Skip to content

Commit aa77643

Browse files
authored
v2.6.4
1 parent e6b92d8 commit aa77643

File tree

6 files changed

+116
-102
lines changed

6 files changed

+116
-102
lines changed

src/button_module.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from PySide6.QtCore import Qt
33
import voice_recorder_module
44

5-
def create_button_row(submit_handler, style):
5+
def create_button_row(submit_handler):
66

77
voice_recorder = voice_recorder_module.VoiceRecorder()
88

@@ -12,37 +12,18 @@ def start_recording():
1212
def stop_recording():
1313
voice_recorder.stop_recording()
1414

15-
# submit_button = QPushButton("Submit Question")
16-
# submit_button.setStyleSheet(style)
17-
1815
start_button = QPushButton("Start Recording")
19-
start_button.setStyleSheet(style)
2016
start_button.clicked.connect(start_recording)
2117

2218
stop_button = QPushButton("Stop Recording")
23-
stop_button.setStyleSheet(style)
2419
stop_button.clicked.connect(stop_recording)
2520

26-
# disabled_label = QLabel("Disabled")
27-
# disabled_checkbox = QCheckBox()
28-
29-
# def toggle_checkbox():
30-
# disabled_checkbox.setChecked(not disabled_checkbox.isChecked())
31-
32-
# disabled_label.mousePressEvent = lambda event: toggle_checkbox()
33-
3421
hbox = QHBoxLayout()
35-
# hbox.addWidget(submit_button)
3622
hbox.addWidget(start_button)
3723
hbox.addWidget(stop_button)
38-
# hbox.addWidget(disabled_label)
39-
# hbox.addWidget(disabled_checkbox)
4024

41-
# hbox.setStretchFactor(submit_button, 7)
4225
hbox.setStretchFactor(start_button, 3)
4326
hbox.setStretchFactor(stop_button, 3)
44-
# hbox.setStretchFactor(disabled_label, 1)
45-
# hbox.setStretchFactor(disabled_checkbox, 1)
4627

4728
row_widget = QWidget()
4829
row_widget.setLayout(hbox)

src/gui.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
from PySide6.QtWidgets import (
22
QApplication, QWidget, QPushButton, QVBoxLayout, QTabWidget,
3-
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout
3+
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar
44
)
55
from PySide6.QtCore import Qt, QThread, Signal, QUrl
66
from PySide6.QtWebEngineWidgets import QWebEngineView
7-
import yaml
87
import os
98
from initialize import determine_compute_device, is_nvidia_gpu, get_os_name
109
from download_model import download_embedding_model
@@ -17,25 +16,22 @@
1716
from gui_threads import CreateDatabaseThread, SubmitButtonThread
1817
from metrics_bar import MetricsBar
1918
from button_module import create_button_row
20-
21-
with open('config.yaml', 'r') as config_file:
22-
config = yaml.safe_load(config_file)
23-
24-
tabs_config = config.get('tabs', [])
25-
styles = config.get('styles', {})
19+
import sys
20+
from utilities import list_theme_files, make_theme_changer, load_stylesheet
2621

2722
class DocQA_GUI(QWidget):
2823
def __init__(self):
2924
super().__init__()
3025
self.compute_device = determine_compute_device()
3126
os_name = get_os_name()
3227
self.init_ui()
28+
self.init_menu()
3329

3430
def init_ui(self):
3531
main_splitter = QSplitter(Qt.Horizontal)
3632
self.setWindowTitle('LM Studio ChromaDB Plugin - www.chintellalaw.com')
3733
self.setGeometry(300, 300, 975, 975)
38-
self.setMinimumSize(550, 610)
34+
self.setMinimumSize(450, 510)
3935

4036
# Left panel setup with grid layout
4137
self.left_frame = QFrame()
@@ -57,12 +53,10 @@ def init_ui(self):
5753
# Create and add buttons to the grid layout
5854
for position, (text, handler) in zip(button_positions, button_data):
5955
button = QPushButton(text)
60-
button.setStyleSheet(styles.get('button', ''))
6156
button.clicked.connect(handler)
6257
grid_layout.addWidget(button, *position)
6358

6459
self.left_frame.setLayout(grid_layout)
65-
self.left_frame.setStyleSheet(styles.get('frame', ''))
6660
main_splitter.addWidget(self.left_frame)
6761

6862
# Right panel setup
@@ -71,37 +65,45 @@ def init_ui(self):
7165

7266
self.read_only_text = QTextEdit()
7367
self.read_only_text.setReadOnly(True)
74-
self.read_only_text.setStyleSheet(styles.get('text', ''))
7568

7669
self.text_input = QTextEdit()
77-
self.text_input.setStyleSheet(styles.get('input', ''))
7870

7971
right_vbox.addWidget(self.read_only_text, 4)
8072
right_vbox.addWidget(self.text_input, 1)
8173

8274
submit_questions_button = QPushButton("Submit Questions")
83-
submit_questions_button.setStyleSheet(styles.get('button', ''))
8475
submit_questions_button.clicked.connect(self.on_submit_button_clicked)
8576

8677
right_vbox.addWidget(submit_questions_button)
8778

8879
# Define widget containing buttons
89-
button_row_widget = create_button_row(self.on_submit_button_clicked, styles.get('button', ''))
80+
button_row_widget = create_button_row(self.on_submit_button_clicked)
9081

9182
# Add widgets from button_module.py
9283
right_vbox.addWidget(button_row_widget)
9384

9485
right_frame.setLayout(right_vbox)
95-
right_frame.setStyleSheet(styles.get('frame', ''))
9686
main_splitter.addWidget(right_frame)
9787

9888
self.metrics_bar = MetricsBar()
9989
main_layout = QVBoxLayout(self)
10090
main_layout.addWidget(main_splitter)
10191
main_layout.addWidget(self.metrics_bar)
10292

93+
# Create menu bar
94+
def init_menu(self):
95+
self.menu_bar = QMenuBar(self)
96+
self.theme_menu = self.menu_bar.addMenu('Themes')
97+
98+
self.theme_files = list_theme_files()
99+
100+
for theme in self.theme_files:
101+
action = self.theme_menu.addAction(theme)
102+
action.triggered.connect(make_theme_changer(theme))
103+
103104
def resizeEvent(self, event):
104105
self.left_frame.setMaximumWidth(self.width() * 0.5)
106+
self.left_frame.setMinimumWidth(self.width() * 0.3)
105107
super().resizeEvent(event)
106108

107109
def on_create_button_clicked(self):
@@ -124,9 +126,10 @@ def closeEvent(self, event):
124126
event.accept()
125127

126128
if __name__ == '__main__':
127-
import sys
128129
app = QApplication(sys.argv)
129130
app.setStyle(QStyleFactory.create('fusion'))
131+
stylesheet = load_stylesheet('custom_stylesheet.css')
132+
app.setStyleSheet(stylesheet)
130133
ex = DocQA_GUI()
131134
ex.show()
132135
sys.exit(app.exec())

src/gui_tabs_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def __init__(self):
2525
# "Embedding Models Settings": (ModelsSettingsTab, 6),
2626
# "Chunk Settings": (ChunkSettingsTab, 2),
2727
"Transcriber Settings": (TranscriberSettingsTab, 1),
28-
"Database Settings": (DatabaseSettingsTab, 5),
28+
"Database Settings": (DatabaseSettingsTab, 4),
2929
}
3030

3131
self.groups = {}

src/gui_tabs_tools_transcribe.py

Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
11
from PySide6.QtWidgets import (
2-
QLabel, QComboBox, QWidget, QGridLayout, QPushButton, QFileDialog, QCheckBox, QApplication
2+
QLabel, QComboBox, QWidget, QHBoxLayout, QVBoxLayout, QPushButton, QFileDialog, QCheckBox, QApplication
33
)
4-
from PySide6.QtCore import QThread, Qt
4+
from PySide6.QtCore import Qt
55
import ctranslate2
66
import yaml
77
from transcribe_module import TranscribeFile
88

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-
249
class TranscriberToolSettingsTab(QWidget):
2510

2611
def __init__(self):
@@ -68,55 +53,64 @@ def update_quantization(self, device_combo, quantization_combo):
6853
quantization_combo.addItems(quantizations)
6954

7055
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"))
9470
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)
9676

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)
10278

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)
10684

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)
10988

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)
11293

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)
11595

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)
118112

119-
self.setLayout(layout)
113+
self.setLayout(main_layout)
120114

121115
def select_audio_file(self):
122116
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):
153147

154148
def start_transcription(self):
155149
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()
159152
else:
160153
print("Please select an audio file first.")
161154

162-
# Only used if ran standalone
163155
if __name__ == "__main__":
164156
app = QApplication([])
165157
window = TranscriberToolSettingsTab()

src/transcribe_module.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,30 @@
33
from faster_whisper import WhisperModel
44
import time
55
from termcolor import cprint
6+
from PySide6.QtCore import QThread
7+
8+
class TranscriptionThread(QThread):
9+
def __init__(self, transcriber):
10+
super().__init__()
11+
self.transcriber = transcriber
12+
13+
def run(self):
14+
try:
15+
self.transcriber.transcribe_to_file()
16+
print("Transcription completed and saved in 'Docs_for_DB' directory.")
17+
except FileNotFoundError as e:
18+
print(f"File not found error: {e}")
19+
except Exception as e:
20+
print(f"An error occurred during transcription: {e}")
621

722
class TranscribeFile:
8-
def __init__(self, config_path='config.yaml'):
23+
def __init__(self, audio_file, config_path='config.yaml'):
924
# Read the configuration from config.yaml
1025
with open(config_path, 'r') as file:
1126
config = yaml.safe_load(file)['transcribe_file']
1227

1328
model_name = f"ctranslate2-4you/whisper-{config['model']}-ct2-{config['quant']}"
14-
self.audio_file = config['file']
29+
self.audio_file = audio_file # Use the passed audio_file
1530
self.include_timestamps = config['timestamps']
1631
self.model = WhisperModel(model_name, device=config['device'], compute_type=config['quant'])
1732
self.enable_print = True
@@ -23,6 +38,10 @@ def my_cprint(self, *args, **kwargs):
2338
modified_message = f"{filename}: {args[0]}"
2439
cprint(modified_message, *args[1:], **kwargs)
2540

41+
def start_transcription_thread(self):
42+
self.transcription_thread = TranscriptionThread(self)
43+
self.transcription_thread.start()
44+
2645
@staticmethod
2746
def format_time(seconds):
2847
# Converts seconds to 'hours:minutes:seconds' format if more than 59m59s

0 commit comments

Comments
 (0)