11import 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 )
221
322class DocQA_GUI :
423 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
725
8- # Use a PanedWindow to manage the left buttons and the right text frames
926 main_pane = tk .PanedWindow (root , orient = tk .HORIZONTAL )
1027 main_pane .pack (fill = tk .BOTH , expand = 1 )
1128
12- # Left Section: Buttons
1329 left_frame = tk .Frame (main_pane )
1430
1531 self .download_embedding_model_button = tk .Button (left_frame , text = "Download Embedding Model" , width = 26 )
@@ -24,16 +40,16 @@ def __init__(self, root):
2440 self .create_chromadb_button = tk .Button (left_frame , text = "Create Vector Database" , width = 26 )
2541 self .create_chromadb_button .pack (pady = 5 )
2642
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 )
2947
3048 main_pane .add (left_frame )
3149
32- # Middle and Bottom Sections: Text Input and Output
3350 right_frame = tk .Frame (main_pane )
3451 main_pane .add (right_frame )
3552
36- # Middle Section: Text Input and Control
3753 middle_frame = tk .Frame (right_frame )
3854 middle_frame .pack (pady = 5 , fill = tk .BOTH , expand = 1 )
3955
@@ -45,11 +61,9 @@ def __init__(self, root):
4561 scroll1 .pack (side = tk .RIGHT , fill = tk .Y )
4662 self .text_input .config (yscrollcommand = scroll1 .set )
4763
48- # Button between Middle and Bottom
4964 self .submit_query_button = tk .Button (right_frame , text = "Submit Question" , width = 15 )
5065 self .submit_query_button .pack (pady = 5 , side = tk .TOP )
5166
52- # Bottom Section: Text Output and Actions
5367 bottom_frame = tk .Frame (right_frame )
5468 bottom_frame .pack (pady = 5 , fill = tk .BOTH , expand = 1 )
5569
@@ -61,64 +75,27 @@ def __init__(self, root):
6175 scroll2 .pack (side = tk .RIGHT , fill = tk .Y )
6276 self .read_only_text .config (yscrollcommand = scroll2 .set )
6377
64- # Center the window and display it
78+ self .cuda_logic = CudaVramLogic (self .cuda_info_label , self .root )
79+
6580 self .center_window (root )
6681
6782 def center_window (self , root ):
68- root .withdraw () # Hide the window
83+ root .withdraw ()
6984 root .update_idletasks ()
7085 width = root .winfo_width ()
7186 height = root .winfo_height ()
7287 x = (root .winfo_screenwidth () // 2 ) - (width // 2 )
7388 y = (root .winfo_screenheight () // 2 ) - (height // 2 )
7489 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 ()
11691
11792if __name__ == "__main__" :
93+ determine_compute_device ()
11894 root = tk .Tk ()
11995 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" )
12197 app = DocQA_GUI (root )
12298 from gui_logic import DocQA_Logic
12399 logic = DocQA_Logic (app )
100+ root .protocol ("WM_DELETE_WINDOW" , app .cuda_logic .stop_and_exit )
124101 root .mainloop ()
0 commit comments