Skip to content

Commit b375ffd

Browse files
authored
v2.6.5
1 parent 22ce758 commit b375ffd

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

src/config.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ AVAILABLE_MODELS:
185185
max_sequence: 512
186186
size_mb: 670
187187
model: thenlper/gte-large
188-
COMPUTE_DEVICE: cpu
188+
COMPUTE_DEVICE: cuda
189189
Compute_Device:
190190
available:
191191
- cuda
@@ -194,9 +194,9 @@ Compute_Device:
194194
database_query: cpu
195195
EMBEDDING_MODEL_NAME:
196196
database:
197-
chunk_overlap: 250
198-
chunk_size: 700
199-
contexts: 10
197+
chunk_overlap: 150
198+
chunk_size: 512
199+
contexts: 25
200200
device: null
201201
similarity: 0.9
202202
embedding-models:
@@ -218,15 +218,16 @@ styles:
218218
frame: 'background-color: #161b22;'
219219
input: 'background-color: #2e333b; color: light gray; font: 13pt "Segoe UI Historic";'
220220
text: 'background-color: #092327; color: light gray; font: 12pt "Segoe UI Historic";'
221+
test_embeddings: false
221222
transcribe_file:
222-
device: cpu
223-
file:
223+
device: cuda
224+
file:
224225
language: Option 1
225-
model: small.en
226+
model: medium.en
226227
quant: float32
227-
timestamps: true
228+
timestamps: false
228229
translate: false
229230
transcriber:
230231
device: cpu
231-
model: base.en
232+
model: small.en
232233
quant: float32

src/gui.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from PySide6.QtWidgets import (
22
QApplication, QWidget, QPushButton, QVBoxLayout, QTabWidget,
3-
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar
3+
QTextEdit, QSplitter, QFrame, QStyleFactory, QLabel, QGridLayout, QMenuBar, QCheckBox
44
)
55
from PySide6.QtCore import Qt, QThread, Signal, QUrl
66
from PySide6.QtWebEngineWidgets import QWebEngineView
77
import os
8+
import yaml
89
from initialize import determine_compute_device, is_nvidia_gpu, get_os_name
910
from download_model import download_embedding_model
1011
from select_model import select_embedding_model_directory
@@ -33,15 +34,14 @@ def init_ui(self):
3334
self.setGeometry(300, 300, 975, 975)
3435
self.setMinimumSize(450, 510)
3536

36-
# Left panel setup with grid layout
37+
# Left frame setup
3738
self.left_frame = QFrame()
3839
grid_layout = QGridLayout()
3940

40-
# Tab widget spanning two columns
4141
tab_widget = create_tabs()
42-
grid_layout.addWidget(tab_widget, 0, 0, 1, 2) # Span two columns
42+
grid_layout.addWidget(tab_widget, 0, 0, 1, 2)
4343

44-
# Button definitions and positions in the grid
44+
# Button definitions and positions
4545
button_data = [
4646
("Download Embedding Model", lambda: download_embedding_model(self)),
4747
("Set Embedding Model Directory", select_embedding_model_directory),
@@ -59,7 +59,7 @@ def init_ui(self):
5959
self.left_frame.setLayout(grid_layout)
6060
main_splitter.addWidget(self.left_frame)
6161

62-
# Right panel setup
62+
# Right frame setup
6363
right_frame = QFrame()
6464
right_vbox = QVBoxLayout()
6565

@@ -73,13 +73,14 @@ def init_ui(self):
7373

7474
submit_questions_button = QPushButton("Submit Questions")
7575
submit_questions_button.clicked.connect(self.on_submit_button_clicked)
76-
7776
right_vbox.addWidget(submit_questions_button)
7877

79-
# Define widget containing buttons
80-
button_row_widget = create_button_row(self.on_submit_button_clicked)
78+
# Add Test Embeddings Checkbox
79+
self.test_embeddings_checkbox = QCheckBox("Test Embeddings")
80+
self.test_embeddings_checkbox.stateChanged.connect(self.on_test_embeddings_changed)
81+
right_vbox.addWidget(self.test_embeddings_checkbox)
8182

82-
# Add widgets from button_module.py
83+
button_row_widget = create_button_row(self.on_submit_button_clicked)
8384
right_vbox.addWidget(button_row_widget)
8485

8586
right_frame.setLayout(right_vbox)
@@ -90,7 +91,6 @@ def init_ui(self):
9091
main_layout.addWidget(main_splitter)
9192
main_layout.addWidget(self.metrics_bar)
9293

93-
# Create menu bar
9494
def init_menu(self):
9595
self.menu_bar = QMenuBar(self)
9696
self.theme_menu = self.menu_bar.addMenu('Themes')
@@ -116,6 +116,18 @@ def on_submit_button_clicked(self):
116116
self.submit_button_thread.responseSignal.connect(self.update_response)
117117
self.submit_button_thread.start()
118118

119+
def on_test_embeddings_changed(self):
120+
script_dir = os.path.dirname(os.path.realpath(__file__))
121+
config_path = os.path.join(script_dir, 'config.yaml')
122+
123+
with open(config_path, 'r') as file:
124+
config = yaml.safe_load(file)
125+
126+
config['test_embeddings'] = self.test_embeddings_checkbox.isChecked()
127+
128+
with open(config_path, 'w') as file:
129+
yaml.dump(config, file)
130+
119131
def update_response(self, response):
120132
self.read_only_text.setPlainText(response)
121133

src/server_connector.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
from termcolor import cprint
1010
from memory_profiler import profile
1111
import gc
12+
import tempfile
13+
import subprocess
1214

1315
ENABLE_PRINT = True
1416
ENABLE_CUDA_PRINT = False
1517

16-
# torch.cuda.reset_peak_memory_stats()
17-
1818
def my_cprint(*args, **kwargs):
1919
if ENABLE_PRINT:
2020
filename = "server_connector.py"
@@ -42,6 +42,19 @@ def print_cuda_memory():
4242
chroma_db_impl="duckdb+parquet", persist_directory=PERSIST_DIRECTORY, anonymized_telemetry=False
4343
)
4444

45+
# Function to write contexts to a temporary file and open it
46+
def write_contexts_to_temp_file_and_open(contexts):
47+
with tempfile.NamedTemporaryFile(delete=False, suffix=".txt", mode='w+') as temp_file:
48+
for context in contexts:
49+
temp_file.write(context + "\n\n")
50+
temp_file_path = temp_file.name
51+
52+
# Open the temp file with the default application
53+
if os.name == 'nt': # Windows
54+
os.startfile(temp_file_path)
55+
elif os.name == 'posix': # macOS, Linux
56+
subprocess.run(['open', temp_file_path])
57+
4558
# @profile
4659
def connect_to_local_chatgpt(prompt):
4760
with open('config.yaml', 'r') as config_file:
@@ -70,6 +83,12 @@ def connect_to_local_chatgpt(prompt):
7083
def ask_local_chatgpt(query, persist_directory=PERSIST_DIRECTORY, client_settings=CHROMA_SETTINGS):
7184
my_cprint("Attempting to connect to server.", "yellow")
7285
print_cuda_memory()
86+
87+
# Read the test_embeddings setting from config.yaml every time the function is called
88+
with open('config.yaml', 'r') as config_file:
89+
config = yaml.safe_load(config_file)
90+
test_embeddings = config.get('test_embeddings', False)
91+
7392
with open('config.yaml', 'r') as config_file:
7493
config = yaml.safe_load(config_file)
7594
EMBEDDING_MODEL_NAME = config['EMBEDDING_MODEL_NAME']
@@ -122,6 +141,12 @@ def ask_local_chatgpt(query, persist_directory=PERSIST_DIRECTORY, client_setting
122141

123142
relevant_contexts = retriever.get_relevant_documents(query)
124143
contexts = [document.page_content for document in relevant_contexts]
144+
145+
# Check if test_embeddings is True, then just write contexts to temp file and return
146+
if test_embeddings:
147+
write_contexts_to_temp_file_and_open(contexts)
148+
return {"answer": "Contexts written to temporary file and opened", "sources": relevant_contexts}
149+
125150
prepend_string = "Only base your answer to the following question on the provided context."
126151
augmented_query = "\n\n---\n\n".join(contexts) + "\n\n-----\n\n" + query
127152

@@ -139,7 +164,6 @@ def ask_local_chatgpt(query, persist_directory=PERSIST_DIRECTORY, client_setting
139164
my_cprint("Embedding model removed from memory.", "red")
140165

141166
return {"answer": response_json, "sources": relevant_contexts}
142-
print_cuda_memory()
143167

144168
# @profile
145169
def interact_with_chat(user_input):

0 commit comments

Comments
 (0)