2828import html
2929import random
3030import hashlib
31- import urllib .parse as urlparse
31+ import urllib .parse
32+ import urllib .request
3233from concurrent .futures import ThreadPoolExecutor
3334from datetime import datetime , timezone
3435from typing import Tuple
36+ import shutil
37+ import subprocess
3538
3639# constants
3740sampler_order_max = 7
@@ -640,7 +643,6 @@ def is_incomplete_utf8_sequence(byte_seq): #note, this will only flag INCOMPLETE
640643 return False #invalid sequence, but not incomplete
641644
642645def unpack_to_dir (destpath = "" ):
643- import shutil
644646 srcpath = os .path .abspath (os .path .dirname (__file__ ))
645647 cliunpack = False if destpath == "" else True
646648 print ("Attempt to unpack KoboldCpp into directory..." )
@@ -1036,8 +1038,6 @@ def autoset_gpu_layers(ctxsize, sdquanted, bbs, qkv_level): #shitty algo to dete
10361038 return 0
10371039
10381040def fetch_gpu_properties (testCL ,testCU ,testVK ):
1039- import subprocess
1040-
10411041 gpumem_ignore_limit_min = 1024 * 1024 * 600 #600 mb min
10421042 gpumem_ignore_limit_max = 1024 * 1024 * 1024 * 300 #300 gb max
10431043
@@ -1812,11 +1812,8 @@ def websearch(query):
18121812 if query == websearch_lastquery :
18131813 print ("Returning cached websearch..." )
18141814 return websearch_lastresponse
1815- import urllib .parse
1816- import urllib .request
18171815 import difflib
18181816 from html .parser import HTMLParser
1819- from concurrent .futures import ThreadPoolExecutor
18201817 num_results = 3
18211818 searchresults = []
18221819 utfprint ("Performing new websearch..." ,1 )
@@ -1977,7 +1974,6 @@ def handle_data(self, data):
19771974
19781975def is_port_in_use (portNum ):
19791976 try :
1980- import socket
19811977 with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
19821978 return s .connect_ex (('localhost' , portNum )) == 0
19831979 except Exception :
@@ -2426,7 +2422,6 @@ def transform_genparams(genparams, api_format):
24262422def LaunchWebbrowser (target_url , failedmsg ):
24272423 try :
24282424 if os .name == "posix" and "DISPLAY" in os .environ : # UNIX-like systems
2429- import subprocess
24302425 clean_env = os .environ .copy ()
24312426 clean_env .pop ("LD_LIBRARY_PATH" , None )
24322427 clean_env ["PATH" ] = "/usr/bin:/bin"
@@ -2744,8 +2739,8 @@ def secure_endpoint(self): #returns false if auth fails. caller should exit
27442739
27452740 def noscript_webui (self ):
27462741 global modelbusy , sslvalid
2747- parsed_url = urlparse .urlparse (self .path )
2748- parsed_dict = urlparse .parse_qs (parsed_url .query )
2742+ parsed_url = urllib . parse .urlparse (self .path )
2743+ parsed_dict = urllib . parse .parse_qs (parsed_url .query )
27492744 reply = ""
27502745 status = str (parsed_dict ['status' ][0 ]) if 'status' in parsed_dict else "Ready To Generate"
27512746 prompt = str (parsed_dict ['prompt' ][0 ]) if 'prompt' in parsed_dict else ""
@@ -2816,7 +2811,7 @@ def noscript_webui(self):
28162811 parsed_dict ["status" ] = status
28172812 parsed_dict ["chatmode" ] = ("1" if chatmode else "0" )
28182813 parsed_dict ["imgmode" ] = ("1" if imgmode else "0" )
2819- updated_query_string = urlparse .urlencode (parsed_dict , doseq = True )
2814+ updated_query_string = urllib . parse .urlencode (parsed_dict , doseq = True )
28202815 updated_path = parsed_url ._replace (query = updated_query_string ).geturl ()
28212816 self .path = updated_path
28222817 time .sleep (0.5 ) #short delay
@@ -3902,8 +3897,6 @@ def stop(self):
39023897
39033898# Based on https://github.com/mathgeniuszach/xdialog/blob/main/xdialog/zenity_dialogs.py - MIT license | - Expanded version by Henk717
39043899def zenity (filetypes = None , initialdir = "" , initialfile = "" , ** kwargs ) -> Tuple [int , str ]:
3905- import shutil
3906- import subprocess
39073900 global zenity_recent_dir , zenity_permitted
39083901
39093902 if not zenity_permitted :
@@ -4445,8 +4438,8 @@ def fetch_search_models():
44454438 searchbase = model_search .get ()
44464439 if searchbase .strip ()== "" :
44474440 return
4448- urlcode = urlparse .urlencode ({"search" :( "GGUF " + searchbase ),"limit" :10 }, doseq = True )
4449- urlcode2 = urlparse .urlencode ({"search" :searchbase ,"limit" :6 }, doseq = True )
4441+ urlcode = urllib . parse .urlencode ({"search" :( "GGUF " + searchbase ),"limit" :10 }, doseq = True )
4442+ urlcode2 = urllib . parse .urlencode ({"search" :searchbase ,"limit" :6 }, doseq = True )
44504443 resp = make_url_request (f"https://huggingface.co/api/models?{ urlcode } " ,None ,'GET' ,{},10 )
44514444 for m in resp :
44524445 searchedmodels .append (m ["id" ])
@@ -5541,7 +5534,6 @@ def print_with_time(txt):
55415534 print (f"{ datetime .now ().strftime ('[%H:%M:%S]' )} " + txt , flush = True )
55425535
55435536def make_url_request (url , data , method = 'POST' , headers = {}, timeout = 300 ):
5544- import urllib .request
55455537 global nocertify
55465538 try :
55475539 request = None
@@ -5572,7 +5564,6 @@ def make_url_request(url, data, method='POST', headers={}, timeout=300):
55725564
55735565#A very simple and stripped down embedded horde worker with no dependencies
55745566def run_horde_worker (args , api_key , worker_name ):
5575- import random
55765567 global friendlymodelname , maxhordectx , maxhordelen , exitcounter , punishcounter , modelbusy , session_starttime , sslvalid
55775568 httpsaffix = ("https" if sslvalid else "http" )
55785569 epurl = f"{ httpsaffix } ://localhost:{ args .port } "
@@ -5769,8 +5760,6 @@ def setuptunnel(global_memory, has_sd):
57695760 # This script will help setup a cloudflared tunnel for accessing KoboldCpp over the internet
57705761 # It should work out of the box on both linux and windows
57715762 try :
5772- import subprocess
5773- import re
57745763 global sslvalid
57755764 httpsaffix = ("https" if sslvalid else "http" )
57765765 ssladd = (" --no-tls-verify" if sslvalid else "" )
@@ -5935,9 +5924,6 @@ def delete_old_pyinstaller():
59355924 if not base_path :
59365925 return
59375926
5938- import time
5939- import os
5940- import shutil
59415927 selfdirpath = os .path .abspath (base_path )
59425928 temp_parentdir_path = os .path .abspath (os .path .join (base_path , '..' ))
59435929 for dirname in os .listdir (temp_parentdir_path ):
@@ -5959,15 +5945,10 @@ def delete_old_pyinstaller():
59595945
59605946def sanitize_string (input_string ):
59615947 # alphanumeric characters, dots, dashes, and underscores
5962- import re
59635948 sanitized_string = re .sub ( r'[^\w\d\.\-_]' , '' , input_string )
59645949 return sanitized_string
59655950
59665951def downloader_internal (input_url , output_filename , capture_output , min_file_size = 64 ): # 64 bytes required by default
5967- import shutil
5968- import subprocess
5969- import os
5970-
59715952 if "https://huggingface.co/" in input_url and "/blob/main/" in input_url :
59725953 input_url = input_url .replace ("/blob/main/" , "/resolve/main/" )
59735954 if output_filename == "auto" :
@@ -6901,7 +6882,6 @@ def launch_browser_thread():
69016882 #if post-ready script specified, execute it
69026883 if args .onready :
69036884 def onready_subprocess ():
6904- import subprocess
69056885 print ("Starting Post-Load subprocess..." )
69066886 subprocess .run (args .onready [0 ], shell = True )
69076887 timer_thread = threading .Timer (1 , onready_subprocess ) #1 second delay
@@ -7026,7 +7006,6 @@ def onready_subprocess():
70267006 print ("Server was not started, main function complete. Idling." , flush = True )
70277007
70287008if __name__ == '__main__' :
7029- import multiprocessing
70307009 multiprocessing .freeze_support ()
70317010
70327011 def check_range (value_type , min_value , max_value ):
0 commit comments