mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-10 17:14:36 +00:00
Download overhaul (#1369)
* Download overhaul * Restore deblobbifier * Cleanup * Fix incorrect return
This commit is contained in:
parent
6e6043fffe
commit
53486b6713
1 changed files with 41 additions and 42 deletions
73
koboldcpp.py
73
koboldcpp.py
|
@ -4703,32 +4703,16 @@ def setuptunnel(global_memory, has_sd):
|
||||||
tunnelproc.wait()
|
tunnelproc.wait()
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
if os.path.exists("cloudflared.exe") and os.path.getsize("cloudflared.exe") > 1000000:
|
downloader_internal("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe", "cloudflared.exe", True)
|
||||||
print("Cloudflared file exists, reusing it...")
|
|
||||||
else:
|
|
||||||
print("Downloading Cloudflare Tunnel for Windows...")
|
|
||||||
subprocess.run("curl -fL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe -o cloudflared.exe", shell=True, capture_output=True, text=True, check=True, encoding='utf-8')
|
|
||||||
elif sys.platform=="darwin":
|
elif sys.platform=="darwin":
|
||||||
if os.path.exists("cloudflared") and os.path.getsize("cloudflared") > 1000000:
|
downloader_internal("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz", "cloudflared-darwin-amd64.tgz", True)
|
||||||
print("Cloudflared file exists, reusing it...")
|
|
||||||
else:
|
|
||||||
print("Downloading Cloudflare Tunnel for MacOS...")
|
|
||||||
subprocess.run("curl -fL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-darwin-amd64.tgz -o cloudflared-darwin-amd64.tgz", shell=True, capture_output=True, text=True, check=True, encoding='utf-8')
|
|
||||||
subprocess.run("tar -xzf cloudflared-darwin-amd64.tgz", shell=True)
|
subprocess.run("tar -xzf cloudflared-darwin-amd64.tgz", shell=True)
|
||||||
subprocess.run("chmod +x 'cloudflared'", shell=True)
|
subprocess.run("chmod +x 'cloudflared'", shell=True)
|
||||||
elif sys.platform == "linux" and platform.machine().lower() == "aarch64":
|
elif sys.platform == "linux" and platform.machine().lower() == "aarch64":
|
||||||
if os.path.exists("cloudflared-linux-arm64") and os.path.getsize("cloudflared-linux-arm64") > 1000000:
|
downloader_internal("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64", "cloudflared-linux-arm64", True)
|
||||||
print("Cloudflared file exists, reusing it...")
|
|
||||||
else:
|
|
||||||
print("Downloading Cloudflare Tunnel for ARM64 Linux...")
|
|
||||||
subprocess.run("curl -fL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-arm64 -o cloudflared-linux-arm64", shell=True, capture_output=True, text=True, check=True, encoding='utf-8')
|
|
||||||
subprocess.run("chmod +x 'cloudflared-linux-arm64'", shell=True)
|
subprocess.run("chmod +x 'cloudflared-linux-arm64'", shell=True)
|
||||||
else:
|
else:
|
||||||
if os.path.exists("cloudflared-linux-amd64") and os.path.getsize("cloudflared-linux-amd64") > 1000000:
|
downloader_internal("https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64", "cloudflared-linux-amd64", True)
|
||||||
print("Cloudflared file exists, reusing it...")
|
|
||||||
else:
|
|
||||||
print("Downloading Cloudflare Tunnel for Linux...")
|
|
||||||
subprocess.run("curl -fL https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o cloudflared-linux-amd64", shell=True, capture_output=True, text=True, check=True, encoding='utf-8')
|
|
||||||
subprocess.run("chmod +x 'cloudflared-linux-amd64'", shell=True)
|
subprocess.run("chmod +x 'cloudflared-linux-amd64'", shell=True)
|
||||||
print("Attempting to start tunnel thread...", flush=True)
|
print("Attempting to start tunnel thread...", flush=True)
|
||||||
tunnel_thread = threading.Thread(target=run_tunnel)
|
tunnel_thread = threading.Thread(target=run_tunnel)
|
||||||
|
@ -4872,24 +4856,39 @@ def sanitize_string(input_string):
|
||||||
sanitized_string = re.sub( r'[^\w\d\.\-_]', '', input_string)
|
sanitized_string = re.sub( r'[^\w\d\.\-_]', '', input_string)
|
||||||
return sanitized_string
|
return sanitized_string
|
||||||
|
|
||||||
def download_model_from_url_internal(url): #returns path to downloaded model when done
|
def downloader_internal(input_url, output_filename, capture_output):
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
mdlfilename = os.path.basename(url)
|
import os
|
||||||
#check if file already exists
|
|
||||||
if mdlfilename:
|
input_url = input_url.split(',')
|
||||||
if os.path.exists(mdlfilename) and os.path.getsize(mdlfilename) > 10000000: #10MB trigger
|
for i in input_url:
|
||||||
print(f"File {mdlfilename} already exists, not redownloading.")
|
if "https://huggingface.co/" in i and "/blob/main/" in i:
|
||||||
return mdlfilename
|
i = i.replace("/blob/main/", "/resolve/main/")
|
||||||
|
if output_filename == "auto":
|
||||||
|
current_filename = os.path.basename(i).split('?')[0]
|
||||||
else:
|
else:
|
||||||
dl_url = url
|
current_filename = output_filename
|
||||||
if "https://huggingface.co/" in dl_url and "/blob/main/" in dl_url:
|
if os.path.exists(current_filename) and os.path.getsize(current_filename) > 1000: #1KB trigger
|
||||||
dl_url = dl_url.replace("/blob/main/", "/resolve/main/")
|
print(f"{current_filename} already exists, using existing file.")
|
||||||
print(f"Downloading file from external URL at {dl_url} now...")
|
continue
|
||||||
subprocess.run(f"curl -fL {dl_url} -o {mdlfilename}", shell=True, capture_output=True, text=True, check=True, encoding='utf-8')
|
print(f"Downloading {current_filename}", flush=True)
|
||||||
print(f"Download {mdlfilename} completed.", flush=True)
|
if shutil.which("aria2c") is None:
|
||||||
return mdlfilename
|
if shutil.which("curl") is None:
|
||||||
|
if shutil.which("wget") is None:
|
||||||
|
print("Could not find suitable download software, please install aria2 or curl.")
|
||||||
return None
|
return None
|
||||||
def download_model_from_url(url,permitted_types=[".gguf",".safetensors"]):
|
subprocess.run(f"wget -O {current_filename} {i}", shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8')
|
||||||
|
continue
|
||||||
|
subprocess.run(f"curl -fLo {current_filename} {i}", shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8')
|
||||||
|
continue
|
||||||
|
subprocess.run(f"aria2c -x 16 -s 16 --summary-interval=10 --download-result=default --allow-overwrite=true --file-allocation=none -o {current_filename} {i}", shell=True, capture_output=capture_output, text=True, check=True, encoding='utf-8')
|
||||||
|
continue
|
||||||
|
if output_filename == "auto":
|
||||||
|
output_filename = os.path.basename(input_url[0]).split('?')[0]
|
||||||
|
return output_filename
|
||||||
|
|
||||||
|
def download_model_from_url(url,permitted_types=[".gguf",".safetensors", ".ggml", ".bin"]):
|
||||||
if url and url!="":
|
if url and url!="":
|
||||||
if url.endswith("?download=true"):
|
if url.endswith("?download=true"):
|
||||||
url = url.replace("?download=true","")
|
url = url.replace("?download=true","")
|
||||||
|
@ -4899,7 +4898,7 @@ def download_model_from_url(url,permitted_types=[".gguf",".safetensors"]):
|
||||||
end_ext_ok = True
|
end_ext_ok = True
|
||||||
break
|
break
|
||||||
if ((url.startswith("http://") or url.startswith("https://")) and end_ext_ok):
|
if ((url.startswith("http://") or url.startswith("https://")) and end_ext_ok):
|
||||||
dlfile = download_model_from_url_internal(url)
|
dlfile = downloader_internal(url, "auto", False)
|
||||||
return dlfile
|
return dlfile
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -5154,7 +5153,7 @@ def kcpp_main_process(launch_args, g_memory=None, gui_launcher=False):
|
||||||
|
|
||||||
# handle model downloads if needed
|
# handle model downloads if needed
|
||||||
if args.model_param and args.model_param!="":
|
if args.model_param and args.model_param!="":
|
||||||
dlfile = download_model_from_url(args.model_param,[".gguf",".bin"])
|
dlfile = download_model_from_url(args.model_param,[".gguf",".bin", ".ggml"])
|
||||||
if dlfile:
|
if dlfile:
|
||||||
args.model_param = dlfile
|
args.model_param = dlfile
|
||||||
if args.sdmodel and args.sdmodel!="":
|
if args.sdmodel and args.sdmodel!="":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue