Spaces:
Running on Zero
Running on Zero
Update utils.py
Browse files6 unmodified lines789101112138 unmodified lines22232425262782 unmodified lines110111112113114115116197 unmodified lines31431531631731831932089 unmodified lines4104114124134144156 unmodified linesHF_TOKEN,MODEL_TYPE_CLASS,DIRECTORY_LORAS,DIFFUSECRAFT_CHECKPOINT_NAME,)from huggingface_hub import HfApifrom huggingface_hub import snapshot_download8 unmodified linesimport requestsfrom requests.adapters import HTTPAdapterfrom urllib3.util import RetryUSER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'82 unmodified linesprint("\033[91mYou need an API key to download Civitai models.\033[0m")model_profile = retrieve_model_info(url)if model_profile.download_url and model_profile.filename_url:url = model_profile.download_urlfilename = unidecode(model_profile.filename_url) if romanize else model_profile.filename_urlelse:197 unmodified linesdef extract_exif_data(image):if image is None: return ""try:metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']89 unmodified linesreturn cached_folderdef progress_step_bar(step, total):# Calculate the percentage for the progress bar widthpercentage = min(100, ((step / total) * 100))6 unmodified lines789101112131415168 unmodified lines252627282930313282 unmodified lines115116117118119120121122123124125197 unmodified lines32332432532632732832933089 unmodified lines4204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554566 unmodified linesHF_TOKEN,MODEL_TYPE_CLASS,DIRECTORY_LORAS,DIRECTORY_MODELS,DIFFUSECRAFT_CHECKPOINT_NAME,CACHE_HF,STORAGE_ROOT,)from huggingface_hub import HfApifrom huggingface_hub import snapshot_download8 unmodified linesimport requestsfrom requests.adapters import HTTPAdapterfrom urllib3.util import Retryimport shutilimport subprocessUSER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:127.0) Gecko/20100101 Firefox/127.0'82 unmodified linesprint("\033[91mYou need an API key to download Civitai models.\033[0m")model_profile = retrieve_model_info(url)if (model_profile is not Noneand model_profile.download_urland model_profile.filename_url):url = model_profile.download_urlfilename = unidecode(model_profile.filename_url) if romanize else model_profile.filename_urlelse:197 unmodified linesdef extract_exif_data(image):if image is None:return ""try:metadata_keys = ['parameters', 'metadata', 'prompt', 'Comment']89 unmodified linesreturn cached_folderdef get_folder_size_gb(folder_path):result = subprocess.run(["du", "-s", folder_path], capture_output=True, text=True)total_size_kb = int(result.stdout.split()[0])total_size_gb = total_size_kb / (1024 ** 2)return total_size_gbdef get_used_storage_gb():try:used_gb = get_folder_size_gb(STORAGE_ROOT)print(f"Used Storage: {used_gb:.2f} GB")except Exception as e:used_gb = 999print(f"Error while retrieving the used storage: {e}.")return used_gbdef delete_model(removal_candidate):print(f"Removing: {removal_candidate}")if os.path.exists(removal_candidate):os.remove(removal_candidate)else:diffusers_model = f"{CACHE_HF}{DIRECTORY_MODELS}--{removal_candidate.replace('/', '--')}"if os.path.isdir(diffusers_model):shutil.rmtree(diffusers_model)def progress_step_bar(step, total):# Calculate the percentage for the progress bar widthpercentage = min(100, ((step / total) * 100))
utils.py+43-2