Skip to content

Commit

Permalink
added a GUI for selection of models if none was passed in through com…
Browse files Browse the repository at this point in the history
…mand line.
  • Loading branch information
LostRuins committed Mar 24, 2023
1 parent c6c6033 commit e791827
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
30 changes: 23 additions & 7 deletions llama_for_kobold.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
#from pathlib import Path


class load_model_inputs(ctypes.Structure):
_fields_ = [("threads", ctypes.c_int),
("max_context_length", ctypes.c_int),
Expand Down Expand Up @@ -249,10 +250,12 @@ def run(self):
except (KeyboardInterrupt,SystemExit):
#print("Thread %s - Server Closing" % (self.i))
self.httpd.server_close()
time.sleep(2)
sys.exit(0)
finally:
# Clean-up server (close socket, etc.)
self.httpd.server_close()
time.sleep(2)
sys.exit(0)
def stop(self):
self.httpd.server_close()
Expand All @@ -263,31 +266,44 @@ def stop(self):
threadArr.append(Thread(i))
while 1:
try:
time.sleep(2000)
time.sleep(2)
except KeyboardInterrupt:
for i in range(numThreads):
threadArr[i].stop()
time.sleep(2)
sys.exit(0)

if __name__ == '__main__':
# total arguments
argc = len(sys.argv)

ggml_selected_file = None
if argc<2:
print("Usage: " + sys.argv[0] + " model_file_q4_0.bin [port]")
sys.exit(0)
print("Command line usage: " + sys.argv[0] + " model_file_q4_0.bin [port]")
#give them a chance to pick a file
print("Alternative, please manually select ggml file:")
from tkinter.filedialog import askopenfilename
ggml_selected_file = askopenfilename (title="Select ggml model .bin files")
if not ggml_selected_file:
print("\nNo ggml model file was selected. Exiting.")
time.sleep(2)
sys.exit(0)
else:
ggml_selected_file = sys.argv[1]

if argc>=3:
port = int(sys.argv[2])

if not os.path.exists(sys.argv[1]):
print("Cannot find model file: " + sys.argv[1])
if not os.path.exists(ggml_selected_file):
print("Cannot find model file: " + ggml_selected_file)
time.sleep(2)
sys.exit(0)

mdl_nparts = 1
for n in range(1,9):
if os.path.exists(sys.argv[1]+"."+str(n)):
if os.path.exists(ggml_selected_file+"."+str(n)):
mdl_nparts += 1
modelname = os.path.abspath(sys.argv[1])
modelname = os.path.abspath(ggml_selected_file)
print("Loading model: " + modelname)
loadok = load_model(modelname,8,maxctx,mdl_nparts)
print("Load Model OK: " + str(loadok))
Expand Down
1 change: 1 addition & 0 deletions make_pyinstaller.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pyinstaller --noconfirm --onefile --console --icon "./niko.ico" --add-data "./klite.embd;." --add-data "./llamacpp.dll;." "./llama_for_kobold.py"
Binary file added niko.ico
Binary file not shown.

0 comments on commit e791827

Please sign in to comment.