1
1
import tkinter as tk
2
+ from gui_table import create_table
3
+ import threading
4
+ from nvml import CudaVramLogic
5
+ import torch
6
+ import yaml
7
+
8
+ def determine_compute_device ():
9
+ if torch .cuda .is_available ():
10
+ COMPUTE_DEVICE = "cuda"
11
+ elif torch .backends .mps .is_available ():
12
+ COMPUTE_DEVICE = "mps"
13
+ else :
14
+ COMPUTE_DEVICE = "cpu"
15
+
16
+ with open ("config.yaml" , 'r' ) as stream :
17
+ config_data = yaml .safe_load (stream )
18
+ config_data ['COMPUTE_DEVICE' ] = COMPUTE_DEVICE
19
+ with open ("config.yaml" , 'w' ) as stream :
20
+ yaml .safe_dump (config_data , stream )
2
21
3
22
class DocQA_GUI :
4
23
def __init__ (self , root ):
5
- self .root = root # Store the root window for later access
6
- self .file_path = tk .StringVar ()
24
+ self .root = root
7
25
8
- # Use a PanedWindow to manage the left buttons and the right text frames
9
26
main_pane = tk .PanedWindow (root , orient = tk .HORIZONTAL )
10
27
main_pane .pack (fill = tk .BOTH , expand = 1 )
11
28
12
- # Left Section: Buttons
13
29
left_frame = tk .Frame (main_pane )
14
30
15
31
self .download_embedding_model_button = tk .Button (left_frame , text = "Download Embedding Model" , width = 26 )
@@ -24,16 +40,16 @@ def __init__(self, root):
24
40
self .create_chromadb_button = tk .Button (left_frame , text = "Create Vector Database" , width = 26 )
25
41
self .create_chromadb_button .pack (pady = 5 )
26
42
27
- # Create table below the buttons
28
- self .create_table (left_frame )
43
+ create_table (left_frame )
44
+
45
+ self .cuda_info_label = tk .Label (left_frame , text = "CUDA & VRAM Info" , font = ("Segoe UI Historic" , 10 ))
46
+ self .cuda_info_label .pack (pady = 5 )
29
47
30
48
main_pane .add (left_frame )
31
49
32
- # Middle and Bottom Sections: Text Input and Output
33
50
right_frame = tk .Frame (main_pane )
34
51
main_pane .add (right_frame )
35
52
36
- # Middle Section: Text Input and Control
37
53
middle_frame = tk .Frame (right_frame )
38
54
middle_frame .pack (pady = 5 , fill = tk .BOTH , expand = 1 )
39
55
@@ -45,11 +61,9 @@ def __init__(self, root):
45
61
scroll1 .pack (side = tk .RIGHT , fill = tk .Y )
46
62
self .text_input .config (yscrollcommand = scroll1 .set )
47
63
48
- # Button between Middle and Bottom
49
64
self .submit_query_button = tk .Button (right_frame , text = "Submit Question" , width = 15 )
50
65
self .submit_query_button .pack (pady = 5 , side = tk .TOP )
51
66
52
- # Bottom Section: Text Output and Actions
53
67
bottom_frame = tk .Frame (right_frame )
54
68
bottom_frame .pack (pady = 5 , fill = tk .BOTH , expand = 1 )
55
69
@@ -61,64 +75,27 @@ def __init__(self, root):
61
75
scroll2 .pack (side = tk .RIGHT , fill = tk .Y )
62
76
self .read_only_text .config (yscrollcommand = scroll2 .set )
63
77
64
- # Center the window and display it
78
+ self .cuda_logic = CudaVramLogic (self .cuda_info_label , self .root )
79
+
65
80
self .center_window (root )
66
81
67
82
def center_window (self , root ):
68
- root .withdraw () # Hide the window
83
+ root .withdraw ()
69
84
root .update_idletasks ()
70
85
width = root .winfo_width ()
71
86
height = root .winfo_height ()
72
87
x = (root .winfo_screenwidth () // 2 ) - (width // 2 )
73
88
y = (root .winfo_screenheight () // 2 ) - (height // 2 )
74
89
root .geometry ('{}x{}+{}+{}' .format (width , height , x , y ))
75
- root .deiconify () # Show the window
76
-
77
- def create_table (self , parent_frame ):
78
- # Define the models and their corresponding VRAM values
79
- models = ["BAAI/bge-large-en" , "BAAI/bge-base-en" , "BAAI/bge-small-en" , "thenlper/gte-large" ,
80
- "thenlper/gte-base" , "thenlper/gte-small" , "intfloat/e5-large-v2" , "intfloat/e5-base-v2" ,
81
- "intfloat/e5-small-v2" , "hkunlp/instructor-xl" , "hkunlp/instructor-large" , "hkunlp/instructor-base" ,
82
- "sentence-transformers/all-mpnet-base-v2" , "sentence-transformers/all-MiniLM-L12-v2" , "sentence-transformers/all-MiniLM-L6-v2" ]
83
- vram_values = ["5.3GB" , "3.7GB" , "2.9GB" , "5.3GB" , "3.7GB" , "3GB" , "5.2GB" , "3.7GB" , "2.9GB" ,
84
- "18.1GB" , "6.8GB" , "4.6GB" , "2.7GB" , "1.6GB" , "1.6GB" ] # Placeholder values
85
-
86
- # Table frame
87
- table_frame = tk .Frame (parent_frame )
88
- table_frame .pack (pady = 5 , fill = tk .BOTH , expand = 1 )
89
-
90
- # Header
91
- tk .Label (table_frame , text = "Embedding Model" , borderwidth = 1 , relief = "solid" ).grid (row = 0 , column = 0 , sticky = "nsew" )
92
- tk .Label (table_frame , text = "Estimated VRAM" , borderwidth = 1 , relief = "solid" ).grid (row = 0 , column = 1 , sticky = "nsew" )
93
-
94
- # Content
95
- for i , (model , vram ) in enumerate (zip (models , vram_values ), start = 1 ):
96
- tk .Label (table_frame , text = model , borderwidth = 1 , relief = "solid" ).grid (row = i , column = 0 , sticky = "nsew" )
97
- tk .Label (table_frame , text = vram , borderwidth = 1 , relief = "solid" ).grid (row = i , column = 1 , sticky = "nsew" )
98
-
99
- # Adjusting column weights so they expand equally
100
- table_frame .grid_columnconfigure (0 , weight = 1 )
101
- table_frame .grid_columnconfigure (1 , weight = 1 )
102
-
103
- # Add Pro Tip and accompanying text
104
- pro_tip_label = tk .Label (parent_frame , text = "Pro tip:" , font = ("Segoe UI Historic" , 12 , "bold" ))
105
- pro_tip_label .pack (pady = (20 , 0 ), anchor = "w" , padx = 5 , side = tk .TOP )
106
-
107
- pro_tip_text = ("DO NOT have LM Studio running when creating the vector database. The VRAM numbers above refer to when creating the database. "
108
- "After it's created, run LM Studio and load your LLM (remember only Llama2-based models work currently when querying the database). "
109
- "To query the database, the embedding model will use about half the VRAM it used when creating it. Use the LARGEST embedding "
110
- "model you can possibly fit into VRAM while the LLM is loaded into LM Studio (remembering the half rule above). The quality of the "
111
- "embedding model is ACTUALLY MORE important that the size of the LLM. Experiment with low-quality LLMs and high-quality embedding models. "
112
- "EXAMPLE: q3_k_3 model + instructor-xl worked just fine together." )
113
-
114
- pro_tip_description = tk .Label (parent_frame , text = pro_tip_text , wraplength = 400 , justify = "left" )
115
- pro_tip_description .pack (anchor = "w" , padx = 5 , side = tk .TOP )
90
+ root .deiconify ()
116
91
117
92
if __name__ == "__main__" :
93
+ determine_compute_device ()
118
94
root = tk .Tk ()
119
95
root .title ("Welcome to the LM Studio ChromaDB Plugin!" )
120
- root .geometry ("800x700" ) # Adjust the size slightly for the paned layout
96
+ root .geometry ("800x800" )
121
97
app = DocQA_GUI (root )
122
98
from gui_logic import DocQA_Logic
123
99
logic = DocQA_Logic (app )
100
+ root .protocol ("WM_DELETE_WINDOW" , app .cuda_logic .stop_and_exit )
124
101
root .mainloop ()
0 commit comments