Skip to content

Commit 468895f

Browse files
authored
v2.7.1
1 parent c798067 commit 468895f

14 files changed

+347
-137
lines changed

src/config.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ Supported_CTranslate2_Quantizations:
2222
- int8_bfloat16
2323
- int8
2424
database:
25-
chunk_overlap: 300
25+
chunk_overlap: 200
2626
chunk_size: 600
27-
contexts: 25
27+
contexts: 8
2828
similarity: 0.9
2929
embedding-models:
3030
bge:
@@ -38,19 +38,27 @@ server:
3838
model_max_tokens: -1
3939
model_temperature: 0.1
4040
prefix: '[INST]'
41+
prefix_chat_ml: <|im_start|>
42+
prefix_llama2_and_mistral: '[INST]'
43+
prefix_neural_chat: '### User:'
44+
prefix_orca2: <|im_start|>user
4145
prompt_format_disabled: false
4246
suffix: '[/INST]'
47+
suffix_chat_ml: <|im_end|>
48+
suffix_llama2_and_mistral: '[/INST]'
49+
suffix_neural_chat: '### Assistant:'
50+
suffix_orca2: <|im_end|><|im_start|>assistant
4351
styles:
4452
button: 'background-color: #323842; color: light gray; font: 10pt "Segoe UI Historic";
4553
width: 29;'
4654
frame: 'background-color: #161b22;'
4755
input: 'background-color: #2e333b; color: light gray; font: 13pt "Segoe UI Historic";'
4856
text: 'background-color: #092327; color: light gray; font: 12pt "Segoe UI Historic";'
49-
test_embeddings: false
57+
test_embeddings: true
5058
transcribe_file:
5159
device: cpu
5260
file: null
53-
model: small.en
61+
model: large-v2
5462
quant: float32
5563
timestamps: true
5664
transcriber:

src/document_processor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
UnstructuredMarkdownLoader
2121
)
2222

23-
# Import DOCUMENT_LOADERS from constants.py
2423
from constants import DOCUMENT_LOADERS
2524

2625
ENABLE_PRINT = True
@@ -35,7 +34,6 @@ def my_cprint(*args, **kwargs):
3534
SOURCE_DIRECTORY = f"{ROOT_DIRECTORY}/Docs_for_DB"
3635
INGEST_THREADS = os.cpu_count() or 8
3736

38-
# Replace class names in DOCUMENT_LOADERS with actual classes
3937
for ext, loader_name in DOCUMENT_LOADERS.items():
4038
DOCUMENT_LOADERS[ext] = globals()[loader_name]
4139

src/gui.py

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from PySide6.QtWidgets import (
22
QApplication, QWidget, QPushButton, QVBoxLayout, QTabWidget,
3-
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar, QCheckBox
3+
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar, QCheckBox, QHBoxLayout
44
)
5-
from PySide6.QtCore import Qt, QThread, Signal, QUrl
6-
from PySide6.QtWebEngineWidgets import QWebEngineView
5+
from PySide6.QtCore import Qt
76
import os
7+
import torch
88
import yaml
99
import sys
1010
from initialize import main as initialize_system
@@ -15,7 +15,7 @@
1515
import create_database
1616
from gui_tabs import create_tabs
1717
from gui_threads import CreateDatabaseThread, SubmitButtonThread
18-
from button_module import create_button_row
18+
import voice_recorder_module
1919
from utilities import list_theme_files, make_theme_changer, load_stylesheet
2020

2121
class DocQA_GUI(QWidget):
@@ -29,6 +29,12 @@ def __init__(self):
2929
self.init_menu()
3030
self.load_config()
3131

32+
def is_nvidia_gpu(self):
33+
if torch.cuda.is_available():
34+
gpu_name = torch.cuda.get_device_name(0)
35+
return "nvidia" in gpu_name.lower()
36+
return False
37+
3238
def load_config(self):
3339
script_dir = os.path.dirname(os.path.realpath(__file__))
3440
config_path = os.path.join(script_dir, 'config.yaml')
@@ -52,7 +58,7 @@ def init_ui(self):
5258
# Buttons data
5359
button_data = [
5460
("Download Embedding Model", lambda: download_embedding_model(self)),
55-
("Set Embedding Model Directory", select_embedding_model_directory),
61+
("Choose Embedding Model Directory", select_embedding_model_directory),
5662
("Choose Documents for Database", choose_documents_directory),
5763
("Create Vector Database", self.on_create_button_clicked)
5864
]
@@ -88,16 +94,18 @@ def init_ui(self):
8894
right_vbox.addWidget(self.test_embeddings_checkbox)
8995

9096
# Create and add button row
91-
button_row_widget = create_button_row(self.on_submit_button_clicked, self)
97+
button_row_widget = self.create_button_row(self.on_submit_button_clicked)
9298
right_vbox.addWidget(button_row_widget)
9399

94100
right_frame.setLayout(right_vbox)
95101
main_splitter.addWidget(right_frame)
96102

97103
main_layout = QVBoxLayout(self)
98104
main_layout.addWidget(main_splitter)
105+
99106
# Metrics bar
100107
main_layout.addWidget(self.metrics_bar)
108+
self.metrics_bar.setMaximumHeight(75 if self.is_nvidia_gpu() else 30)
101109

102110
def init_menu(self):
103111
self.menu_bar = QMenuBar(self)
@@ -143,9 +151,36 @@ def update_transcription(self, text):
143151
self.text_input.setPlainText(text)
144152

145153
def closeEvent(self, event):
146-
self.metrics_bar.stop_monitors()
154+
self.metrics_bar.stop_metrics_collector()
147155
event.accept()
148156

157+
def create_button_row(self, submit_handler):
158+
voice_recorder = voice_recorder_module.VoiceRecorder(self)
159+
160+
def start_recording():
161+
voice_recorder.start_recording()
162+
163+
def stop_recording():
164+
voice_recorder.stop_recording()
165+
166+
start_button = QPushButton("Start Recording")
167+
start_button.clicked.connect(start_recording)
168+
169+
stop_button = QPushButton("Stop Recording")
170+
stop_button.clicked.connect(stop_recording)
171+
172+
hbox = QHBoxLayout()
173+
hbox.addWidget(start_button)
174+
hbox.addWidget(stop_button)
175+
176+
hbox.setStretchFactor(start_button, 3)
177+
hbox.setStretchFactor(stop_button, 3)
178+
179+
row_widget = QWidget()
180+
row_widget.setLayout(hbox)
181+
182+
return row_widget
183+
149184
if __name__ == '__main__':
150185
app = QApplication(sys.argv)
151186
app.setStyle(QStyleFactory.create('fusion'))

src/gui_tabs_settings.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from PySide6.QtWidgets import QVBoxLayout, QGroupBox, QPushButton, QHBoxLayout, QWidget, QMessageBox
1+
from PySide6.QtWidgets import QVBoxLayout, QGroupBox, QPushButton, QHBoxLayout, QWidget, QMessageBox, QLabel
22
from gui_tabs_settings_server import ServerSettingsTab
33
# from gui_tabs_settings_models import ModelsSettingsTab
44
# Commented out unless/until modifying BGE and Instructor settings become useful
55
from gui_tabs_settings_whisper import TranscriberSettingsTab
66
from gui_tabs_settings_database import DatabaseSettingsTab
7-
# from gui_tabs_settings_chunks import ChunkSettingsTab
87

98
def update_all_configs(configs):
109
updated = any(config.update_config() for config in configs.values())
@@ -28,8 +27,7 @@ def __init__(self):
2827
classes = {
2928
"Server/LLM Settings": (ServerSettingsTab, 3),
3029
"Voice Recorder Settings": (TranscriberSettingsTab, 1),
31-
"Database Settings": (DatabaseSettingsTab, 4),
32-
# "Chunking Settings": (ChunkSettingsTab, 4),
30+
"Database Settings": (DatabaseSettingsTab, 3),
3331
}
3432

3533
self.groups = {}
@@ -61,6 +59,13 @@ def __init__(self):
6159
center_button_layout.addWidget(self.update_all_button)
6260
center_button_layout.addStretch(1)
6361

62+
tip_label_1 = QLabel("<b><u>Must</u> 'Update Settings' before any settings take effect.</b>")
63+
tip_label_2 = QLabel("<b><u>Must recreate</u> database if changing Chunk Size/Overlap settings</b>")
64+
self.layout.addWidget(tip_label_1)
65+
self.layout.addWidget(tip_label_2)
66+
67+
self.setLayout(self.layout)
68+
6469
self.layout.addLayout(center_button_layout)
6570
self.setLayout(self.layout)
66-
adjust_stretch(self.groups, self.layout)
71+
adjust_stretch(self.groups, self.layout)

src/gui_tabs_settings_database.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,6 @@ def __init__(self):
5252
v_layout.addLayout(h_layout1)
5353
v_layout.addLayout(h_layout2)
5454
self.setLayout(v_layout)
55-
56-
tip_label_1 = QLabel("<b><u>Must</u> 'Update Settings' before any settings take effect.</b>")
57-
tip_label_2 = QLabel("<b><u>RECREATE</u> database if changing Chunk Size/Overlap settings</b>")
58-
v_layout.addWidget(tip_label_1)
59-
v_layout.addWidget(tip_label_2)
60-
61-
self.setLayout(v_layout)
6255

6356
def update_config(self):
6457
with open('config.yaml', 'r') as f:

src/gui_tabs_settings_server.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from PySide6.QtWidgets import QWidget, QLabel, QLineEdit, QGridLayout, QMessageBox, QSizePolicy, QCheckBox
1+
from PySide6.QtWidgets import QWidget, QLabel, QLineEdit, QGridLayout, QMessageBox, QSizePolicy, QCheckBox, QComboBox
22
from PySide6.QtGui import QIntValidator, QDoubleValidator
33
import yaml
44

@@ -7,14 +7,14 @@ def __init__(self):
77
super(ServerSettingsTab, self).__init__()
88

99
with open('config.yaml', 'r') as file:
10-
config_data = yaml.safe_load(file)
11-
self.connection_str = config_data.get('server', {}).get('connection_str', '')
10+
self.config_data = yaml.safe_load(file)
11+
self.connection_str = self.config_data.get('server', {}).get('connection_str', '')
1212
self.current_port = self.connection_str.split(":")[-1].split("/")[0]
13-
self.current_max_tokens = config_data.get('server', {}).get('model_max_tokens', '')
14-
self.current_temperature = config_data.get('server', {}).get('model_temperature', '')
15-
self.current_prefix = config_data.get('server', {}).get('prefix', '')
16-
self.current_suffix = config_data.get('server', {}).get('suffix', '')
17-
self.prompt_format_disabled = config_data.get('server', {}).get('prompt_format_disabled', False)
13+
self.current_max_tokens = self.config_data.get('server', {}).get('model_max_tokens', '')
14+
self.current_temperature = self.config_data.get('server', {}).get('model_temperature', '')
15+
self.current_prefix = self.config_data.get('server', {}).get('prefix', '')
16+
self.current_suffix = self.config_data.get('server', {}).get('suffix', '')
17+
self.prompt_format_disabled = self.config_data.get('server', {}).get('prompt_format_disabled', False)
1818

1919
settings_dict = {
2020
'port': {"placeholder": "Enter new port...", "validator": QIntValidator(), "current": self.current_port},
@@ -36,8 +36,13 @@ def __init__(self):
3636

3737
prompt_format_label = QLabel("Prompt Format:")
3838
layout.addWidget(prompt_format_label, 2, 0)
39+
40+
self.prompt_format_combobox = QComboBox()
41+
self.prompt_format_combobox.addItems(["", "ChatML", "Llama2/Mistral", "Neural Chat", "Orca2"])
42+
layout.addWidget(self.prompt_format_combobox, 2, 1)
43+
self.prompt_format_combobox.currentIndexChanged.connect(self.update_prefix_suffix)
3944

40-
disable_label = QLabel("Disable")
45+
disable_label = QLabel("Disable:")
4146
layout.addWidget(disable_label, 2, 2)
4247

4348
self.disable_checkbox = QCheckBox()
@@ -47,8 +52,8 @@ def __init__(self):
4752

4853
layout.addWidget(self.create_label('prefix', settings_dict), 3, 0)
4954
layout.addWidget(self.create_edit('prefix', settings_dict), 3, 1)
50-
layout.addWidget(self.create_label('suffix', settings_dict), 3, 2)
51-
layout.addWidget(self.create_edit('suffix', settings_dict), 3, 3)
55+
layout.addWidget(self.create_label('suffix', settings_dict), 4, 0)
56+
layout.addWidget(self.create_edit('suffix', settings_dict), 4, 1)
5257

5358
self.setLayout(layout)
5459

@@ -70,6 +75,21 @@ def create_edit(self, setting, settings_dict):
7075
self.widgets[setting]['edit'] = edit
7176
return edit
7277

78+
def update_prefix_suffix(self, index):
79+
option = self.prompt_format_combobox.currentText()
80+
81+
key_mapping = {
82+
"ChatML": ("prefix_chat_ml", "suffix_chat_ml"),
83+
"Llama2/Mistral": ("prefix_llama2_and_mistral", "suffix_llama2_and_mistral"),
84+
"Neural Chat": ("prefix_neural_chat", "suffix_neural_chat"),
85+
"Orca2": ("prefix_orca2", "suffix_orca2"),
86+
}
87+
88+
prefix_key, suffix_key = key_mapping.get(option, ("", ""))
89+
90+
self.widgets['prefix']['edit'].setText(self.config_data.get('server', {}).get(prefix_key, ''))
91+
self.widgets['suffix']['edit'].setText(self.config_data.get('server', {}).get(suffix_key, ''))
92+
7393
def update_config(self):
7494
with open('config.yaml', 'r') as file:
7595
config_data = yaml.safe_load(file)

src/initialize.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,8 @@ def get_supported_quantizations(device_type):
2828
types = ctranslate2.get_supported_compute_types(device_type)
2929
filtered_types = [q for q in types if q != 'int16']
3030

31-
# Define the desired order of quantizations
3231
desired_order = ['float32', 'float16', 'bfloat16', 'int8_float32', 'int8_float16', 'int8_bfloat16', 'int8']
33-
34-
# Sort the filtered_types based on the desired order
3532
sorted_types = [q for q in desired_order if q in filtered_types]
36-
3733
return sorted_types
3834

3935
def update_config_file(**system_info):
@@ -44,13 +40,11 @@ def update_config_file(**system_info):
4440
config_data['Compute_Device'].setdefault('database_creation', 'cpu')
4541
config_data['Compute_Device'].setdefault('database_query', 'cpu')
4642

47-
# Add supported quantizations for CPU and GPU
4843
config_data['Supported_CTranslate2_Quantizations'] = {
4944
'CPU': get_supported_quantizations('cpu'),
5045
'GPU': get_supported_quantizations('cuda') if torch.cuda.is_available() else []
5146
}
5247

53-
# Update other keys
5448
for key, value in system_info.items():
5549
if key != 'Compute_Device' and key != 'Supported_CTranslate2_Quantizations':
5650
config_data[key] = value

0 commit comments

Comments
 (0)