66import shutil
77import winsound
88import tkinter .scrolledtext as scrolledtext
9+ import importlib .util
910
1011def resource_path (relative_path ):
1112 """ Get absolute path to resource, works for dev and for PyInstaller """
@@ -172,6 +173,74 @@ def run_llama_quantize():
172173 # Play sound effect
173174 winsound .PlaySound ("SystemAsterisk" , winsound .SND_ALIAS )
174175
176+ def setup_environment ():
177+ process_text .insert (tk .END , "Checking environment...\n " )
178+ root .update ()
179+
180+ # Check for GitPython
181+ try :
182+ from git import Repo
183+ process_text .insert (tk .END , "GitPython is already installed.\n " )
184+ except ImportError :
185+ process_text .insert (tk .END , "Installing GitPython...\n " )
186+ root .update ()
187+ try :
188+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "GitPython" ])
189+ process_text .insert (tk .END , "Successfully installed GitPython.\n " )
190+ except subprocess .CalledProcessError as e :
191+ process_text .insert (tk .END , f"Error installing GitPython: { e } \n " )
192+ return False
193+
194+ # List of other required packages
195+ required_packages = ['torch' , 'tqdm' , 'safetensors' ]
196+
197+ for package in required_packages :
198+ try :
199+ __import__ (package )
200+ process_text .insert (tk .END , f"{ package } is already installed.\n " )
201+ except ImportError :
202+ process_text .insert (tk .END , f"Installing { package } ...\n " )
203+ root .update ()
204+ try :
205+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , package ])
206+ process_text .insert (tk .END , f"Successfully installed { package } .\n " )
207+ except subprocess .CalledProcessError as e :
208+ process_text .insert (tk .END , f"Error installing { package } : { e } \n " )
209+ return False
210+
211+ # Check if gguf-py is installed
212+ gguf_installed = False
213+ try :
214+ __import__ ('gguf' )
215+ process_text .insert (tk .END , "gguf-py is already installed.\n " )
216+ gguf_installed = True
217+ except ImportError :
218+ pass
219+
220+ if not gguf_installed :
221+ # Clone llama.cpp repository only if gguf-py is not installed
222+ if not os .path .exists ("llama.cpp" ):
223+ try :
224+ Repo .clone_from ("https://github.com/ggerganov/llama.cpp" , "llama.cpp" )
225+ process_text .insert (tk .END , "Successfully cloned llama.cpp repository.\n " )
226+ except Exception as e :
227+ process_text .insert (tk .END , f"Error cloning repository: { e } \n " )
228+ return False
229+
230+ # Install gguf-py
231+ process_text .insert (tk .END , "Installing gguf-py...\n " )
232+ root .update ()
233+ try :
234+ subprocess .check_call ([sys .executable , "-m" , "pip" , "install" , "llama.cpp/gguf-py" ])
235+ process_text .insert (tk .END , "Successfully installed gguf-py.\n " )
236+ except subprocess .CalledProcessError as e :
237+ process_text .insert (tk .END , f"Error installing gguf-py: { e } \n " )
238+ return False
239+
240+ process_text .insert (tk .END , "Environment check completed. All dependencies are in place.\n " )
241+ root .update ()
242+ return True
243+
175244root = tk .Tk ()
176245root .title ("Easy Quantization GUI" )
177246root .geometry ("800x600" ) # Enlarge the main window
@@ -227,6 +296,21 @@ def run_llama_quantize():
227296run_button = tk .Button (root , text = "Run Quantization" , command = run_llama_quantize )
228297run_button .pack (pady = 20 )
229298
299+ # Add process log to bottom of main window
300+ process_frame = tk .Frame (root )
301+ process_frame .pack (pady = 10 , padx = 10 , fill = tk .BOTH , expand = True )
302+
303+ process_label = tk .Label (process_frame , text = "Process Log:" )
304+ process_label .pack (side = tk .TOP , anchor = 'w' )
305+
306+ process_text = scrolledtext .ScrolledText (process_frame , wrap = tk .WORD , height = 15 )
307+ process_text .pack (expand = True , fill = tk .BOTH )
308+
309+ # Setup environment before creating other UI elements
310+ if not setup_environment ():
311+ messagebox .showerror ("Setup Error" , "Failed to set up the environment. Please check the process log for details." )
312+ root .quit ()
313+
230314# Bind events to update output filename
231315input_entry .bind ("<KeyRelease>" , update_output_filename )
232316quantize_level_var .trace_add ("write" , update_output_filename )
@@ -237,14 +321,4 @@ def on_window_resize(event):
237321
238322root .bind ("<Configure>" , on_window_resize )
239323
240- # Add process log to main window
241- process_frame = tk .Frame (root )
242- process_frame .pack (pady = 10 , padx = 10 , fill = tk .BOTH , expand = True )
243-
244- process_label = tk .Label (process_frame , text = "Process Log:" )
245- process_label .pack (side = tk .TOP , anchor = 'w' )
246-
247- process_text = scrolledtext .ScrolledText (process_frame , wrap = tk .WORD , height = 15 )
248- process_text .pack (expand = True , fill = tk .BOTH )
249-
250324root .mainloop ()
0 commit comments