From 803b3e1070cff161073d104a5253c0ecd32cb995 Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Fri, 2 May 2025 11:40:37 +0800 Subject: [PATCH] added HF model search tool (+1 squashed commits) Squashed commits: [cbd925d59] added HF model search tool --- koboldcpp.py | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/koboldcpp.py b/koboldcpp.py index c015247e4..b6096eb3f 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -5079,12 +5079,90 @@ def show_gui(): def display_updates(): LaunchWebbrowser("https://github.com/LostRuins/koboldcpp/releases/latest","Cannot launch updates in browser.") + def model_searcher(): + searchbox1 = None + modelsearch1_var = ctk.StringVar(value="") + modelsearch2_var = ctk.StringVar(value="") + # Create popup window + popup = ctk.CTkToplevel(root) + popup.title("Model File Browser") + popup.geometry("400x400") + + def confirm_search_model_choice(): + nonlocal modelsearch1_var, modelsearch2_var, model_var + if modelsearch1_var.get()!="" and modelsearch2_var.get()!="": + model_var.set(f"https://huggingface.co/{modelsearch1_var.get()}/resolve/main/{modelsearch2_var.get()}") + popup.destroy() + def fetch_search_quants(a,b,c): + nonlocal modelsearch1_var, modelsearch2_var + try: + if modelsearch1_var.get()=="": + return + searchedmodels = [] + resp = make_url_request(f"https://huggingface.co/api/models/{modelsearch1_var.get()}",None,'GET',{},10) + for m in resp["siblings"]: + if ".gguf" in m["rfilename"]: + searchedmodels.append(m["rfilename"]) + searchbox2.configure(values=searchedmodels) + if len(searchedmodels)>0: + modelsearch2_var.set(searchedmodels[0]) + else: + modelsearch2_var.set("") + except Exception as e: + modelsearch1_var.set("") + modelsearch2_var.set("") + print(f"Error: {e}") + def fetch_search_models(): + from tkinter import messagebox + nonlocal searchbox1, modelsearch1_var, modelsearch2_var + try: + modelsearch1_var.set("") + modelsearch2_var.set("") + searchedmodels = [] + search = "GGUF " + model_search.get() + urlcode = urlparse.urlencode({"search":search,"limit":10}, doseq=True) + resp = make_url_request(f"https://huggingface.co/api/models?{urlcode}",None,'GET',{},10) + if len(resp)==0: + messagebox.showinfo("No Results Found", "Search found no results") + for m in resp: + searchedmodels.append(m["id"]) + searchbox1.configure(values=searchedmodels) + if len(searchedmodels)>0: + modelsearch1_var.set(searchedmodels[0]) + else: + modelsearch1_var.set("") + except Exception as e: + modelsearch1_var.set("") + modelsearch2_var.set("") + print(f"Error: {e}") + + ctk.CTkLabel(popup, text="Enter Search String:").pack(pady=(10, 0)) + model_search = ctk.CTkEntry(popup, width=300) + model_search.pack(pady=5) + model_search.insert(0, "") + + ctk.CTkButton(popup, text="Search Huggingface", command=fetch_search_models).pack(pady=5) + + ctk.CTkLabel(popup, text="Selected Model:").pack(pady=(10, 0)) + searchbox1 = ctk.CTkComboBox(popup, values=[], width=340, variable=modelsearch1_var, state="readonly") + searchbox1.pack(pady=5) + ctk.CTkLabel(popup, text="Selected Quant:").pack(pady=(10, 0)) + searchbox2 = ctk.CTkComboBox(popup, values=[], width=340, variable=modelsearch2_var, state="readonly") + searchbox2.pack(pady=5) + modelsearch1_var.trace("w", fetch_search_quants) + + ctk.CTkButton(popup, text="Confirm Selection", command=confirm_search_model_choice).pack(pady=5) + + popup.transient(root) + + ctk.CTkButton(tabs , text = "Launch", fg_color="#2f8d3c", hover_color="#2faa3c", command = guilaunch, width=80, height = 35 ).grid(row=1,column=1, stick="se", padx= 25, pady=5) ctk.CTkButton(tabs , text = "Update", fg_color="#9900cc", hover_color="#aa11dd", command = display_updates, width=90, height = 35 ).grid(row=1,column=0, stick="sw", padx= 5, pady=5) ctk.CTkButton(tabs , text = "Save", fg_color="#084a66", hover_color="#085a88", command = save_config_gui, width=60, height = 35 ).grid(row=1,column=1, stick="sw", padx= 5, pady=5) ctk.CTkButton(tabs , text = "Load", fg_color="#084a66", hover_color="#085a88", command = load_config_gui, width=60, height = 35 ).grid(row=1,column=1, stick="sw", padx= 70, pady=5) - ctk.CTkButton(tabs , text = "Help (Find Models)", fg_color="#992222", hover_color="#bb3333", command = display_help, width=100, height = 35 ).grid(row=1,column=1, stick="sw", padx= 135, pady=5) + ctk.CTkButton(tabs , text = "Help", fg_color="#992222", hover_color="#bb3333", command = display_help, width=50, height = 35 ).grid(row=1,column=1, stick="sw", padx= 135, pady=5) + ctk.CTkButton(tabs , text = "Model Search", fg_color="#2222aa", hover_color="#3333cc", command = model_searcher, width=90, height = 35 ).grid(row=1,column=1, stick="sw", padx= 190, pady=5) # start a thread that tries to get actual gpu names and layer counts gpuinfo_thread = threading.Thread(target=auto_set_backend_gui)