Upload folder using huggingface_hub
Browse files- modules/directory_setup.py +12 -0
- modules/models_data.py +108 -0
- modules/setup_en.py +88 -0
- modules/setup_ru.py +88 -0
modules/directory_setup.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
|
3 |
+
webui_path = os.getenv('WEBUI_PATH')
|
4 |
+
|
5 |
+
output_dir = f"{webui_path}/outputs"
|
6 |
+
models_dir = f"{webui_path}/models/Stable-diffusion"
|
7 |
+
vaes_dir = f"{webui_path}/models/VAE"
|
8 |
+
embeddings_dir = f"{webui_path}/embeddings"
|
9 |
+
loras_dir = f"{webui_path}/models/Lora"
|
10 |
+
extensions_dir = f"{webui_path}/extensions"
|
11 |
+
control_dir = f"{webui_path}/models/ControlNet"
|
12 |
+
adetailer_dir = f"{webui_path}/models/adetailer"
|
modules/models_data.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
model_list = {
|
2 |
+
"1.Anime (by XpucT) + INP": [
|
3 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2.safetensors", "name": "Anime_V2.safetensors"},
|
4 |
+
{"url": "https://huggingface.co/XpucT/Anime/resolve/main/Anime_v2-inpainting.safetensors", "name": "Anime_V2-inpainting.safetensors"}
|
5 |
+
],
|
6 |
+
"2.BluMix [Anime] [V7] + INP": [
|
7 |
+
{"url": "https://civitai.com/api/download/models/361779", "name": "BluMix_V7.safetensors"},
|
8 |
+
{"url": "https://civitai.com/api/download/models/363850", "name": "BluMix_V7-inpainting.safetensors"}
|
9 |
+
],
|
10 |
+
"3.Cetus-Mix [Anime] [V4] + INP": [
|
11 |
+
{"url": "https://huggingface.co/fp16-guy/Cetus-Mix_v4_fp16_cleaned/resolve/main/cetusMix_v4_fp16.safetensors", "name": "CetusMix_V4.safetensors"},
|
12 |
+
{"url": "https://huggingface.co/fp16-guy/Cetus-Mix_v4_fp16_cleaned/resolve/main/cetusMix_v4_inp_fp16.safetensors", "name": "CetusMix_V4-inpainting.safetensors"}
|
13 |
+
],
|
14 |
+
"4.Counterfeit [Anime] [V3] + INP": [
|
15 |
+
{"url": "https://huggingface.co/fp16-guy/Counterfeit-V3.0_fp16_cleaned/resolve/main/CounterfeitV30_v30_fp16.safetensors", "name": "Counterfeit_V3.safetensors"},
|
16 |
+
{"url": "https://huggingface.co/fp16-guy/Counterfeit-V3.0_fp16_cleaned/resolve/main/CounterfeitV30_v30_inp_fp16.safetensors", "name": "Counterfeit_V3-inpainting.safetensors"}
|
17 |
+
],
|
18 |
+
"5.CuteColor [Anime] [V3]": [
|
19 |
+
{"url": "https://civitai.com/api/download/models/138754", "name": "CuteColor_V3.safetensors"}
|
20 |
+
],
|
21 |
+
"6.Dark-Sushi-Mix [Anime]": [
|
22 |
+
{"url": "https://civitai.com/api/download/models/101640", "name": "DarkSushiMix_2_5D.safetensors"},
|
23 |
+
{"url": "https://civitai.com/api/download/models/56071", "name": "DarkSushiMix_colorful.safetensors"}
|
24 |
+
],
|
25 |
+
"7.Deliberate [Realism] [V6] + INP": [
|
26 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6.safetensors", "name": "Deliberate_V6.safetensors"},
|
27 |
+
{"url": "https://huggingface.co/XpucT/Deliberate/resolve/main/Deliberate_v6-inpainting.safetensors", "name": "Deliberate_V6-inpainting.safetensors"}
|
28 |
+
],
|
29 |
+
"8.Meina-Mix [Anime] [V11] + INP": [
|
30 |
+
{"url": "https://civitai.com/api/download/models/119057", "name": "MeinaMix_V11.safetensors"},
|
31 |
+
{"url": "https://civitai.com/api/download/models/120702", "name": "MeinaMix_V11-inpainting.safetensors"}
|
32 |
+
],
|
33 |
+
"9.Mix-Pro [Anime] [V4] + INP": [
|
34 |
+
{"url": "https://huggingface.co/fp16-guy/MIX-Pro-V4_fp16_cleaned/resolve/main/mixProV4_v4_fp16.safetensors", "name": "MixPro_V4.safetensors"},
|
35 |
+
{"url": "https://huggingface.co/fp16-guy/MIX-Pro-V4_fp16_cleaned/resolve/main/mixProV4_v4_inp_fp16.safetensors", "name": "MixPro_V4-inpainting.safetensors"},
|
36 |
+
{"url": "https://huggingface.co/fp16-guy/MIX-Pro-V4.5_fp16_cleaned/resolve/main/mixProV45Colorbox_v45_fp16.safetensors", "name": "MixPro_V4_5.safetensors"},
|
37 |
+
{"url": "https://huggingface.co/fp16-guy/MIX-Pro-V4.5_fp16_cleaned/resolve/main/mixProV45Colorbox_v45_inp_fp16.safetensors", "name": "MixPro_V4_5-inpainting.safetensors"}
|
38 |
+
]
|
39 |
+
}
|
40 |
+
|
41 |
+
vae_list = {
|
42 |
+
"1.Anime.vae": [
|
43 |
+
{"url": "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/kl-f8-anime2_fp16.safetensors", "name": "Anime-kl-f8.vae.safetensors"},
|
44 |
+
{"url": "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/vae-ft-mse-840000-ema-pruned_fp16.safetensors", "name": "Anime-mse.vae.safetensors"}
|
45 |
+
],
|
46 |
+
"2.Anything.vae": [{"url": "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/anything_fp16.safetensors", "name": "Anything.vae.safetensors"}],
|
47 |
+
"3.Blessed2.vae": [{"url": "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/blessed2_fp16.safetensors", "name": "Blessed2.vae.safetensors"}],
|
48 |
+
"4.ClearVae.vae": [{"url": "https://huggingface.co/fp16-guy/anything_kl-f8-anime2_vae-ft-mse-840000-ema-pruned_blessed_clearvae_fp16_cleaned/resolve/main/ClearVAE_V2.3_fp16.safetensors", "name": "ClearVae_23.vae.safetensors"}],
|
49 |
+
"5.WD.vae": [{"url": "https://huggingface.co/NoCrypt/resources/resolve/main/VAE/wd.vae.safetensors", "name": "WD.vae.safetensors"}]
|
50 |
+
}
|
51 |
+
|
52 |
+
controlnet_list = {
|
53 |
+
"1.canny": [
|
54 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors", "name": "control_v11p_sd15_canny_fp16.safetensors"},
|
55 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml", "name": "control_v11p_sd15_canny_fp16.yaml"}
|
56 |
+
],
|
57 |
+
"2.openpose": [
|
58 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors", "name": "control_v11p_sd15_openpose_fp16.safetensors"},
|
59 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml", "name": "control_v11p_sd15_openpose_fp16.yaml"}
|
60 |
+
],
|
61 |
+
"3.depth": [
|
62 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors", "name": "control_v11f1p_sd15_depth_fp16.safetensors"},
|
63 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml", "name": "control_v11f1p_sd15_depth_fp16.yaml"},
|
64 |
+
{"url": "https://huggingface.co/NagisaNao/models/resolve/main/ControlNet_v11/control_v11p_sd15_depth_anything_fp16.safetensors", "name": "control_v11p_sd15_depth_anything_fp16.safetensors"}
|
65 |
+
],
|
66 |
+
"4.normal_map": [
|
67 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors", "name": "control_v11p_sd15_normalbae_fp16.safetensors"},
|
68 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml", "name": "control_v11p_sd15_normalbae_fp16.yaml"}
|
69 |
+
],
|
70 |
+
"5.mlsd": [
|
71 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors", "name": "control_v11p_sd15_mlsd_fp16.safetensors"},
|
72 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml", "name": "control_v11p_sd15_mlsd_fp16.yaml"}
|
73 |
+
],
|
74 |
+
"6.lineart": [
|
75 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors", "name": "control_v11p_sd15_lineart_fp16.safetensors"},
|
76 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors", "name": "control_v11p_sd15s2_lineart_anime_fp16.safetensors"},
|
77 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml", "name": "control_v11p_sd15_lineart_fp16.yaml"},
|
78 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml", "name": "control_v11p_sd15s2_lineart_anime_fp16.yaml"}
|
79 |
+
],
|
80 |
+
"7.soft_edge": [
|
81 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors", "name": "control_v11p_sd15_softedge_fp16.safetensors"},
|
82 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml", "name": "control_v11p_sd15_softedge_fp16.yaml"}
|
83 |
+
],
|
84 |
+
"8.scribble": [
|
85 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors", "name": "control_v11p_sd15_scribble_fp16.safetensors"},
|
86 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml", "name": "control_v11p_sd15_scribble_fp16.yaml"}
|
87 |
+
],
|
88 |
+
"9.segmentation": [
|
89 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors", "name": "control_v11p_sd15_seg_fp16.safetensors"},
|
90 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml", "name": "control_v11p_sd15_seg_fp16.yaml"}
|
91 |
+
],
|
92 |
+
"10.shuffle": [
|
93 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors", "name": "control_v11e_sd15_shuffle_fp16.safetensors"},
|
94 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml", "name": "control_v11e_sd15_shuffle_fp16.yaml"}
|
95 |
+
],
|
96 |
+
"11.tile": [
|
97 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors", "name": "control_v11f1e_sd15_tile_fp16.safetensors"},
|
98 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml", "name": "control_v11f1e_sd15_tile_fp16.yaml"}
|
99 |
+
],
|
100 |
+
"12.inpaint": [
|
101 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors", "name": "control_v11p_sd15_inpaint_fp16.safetensors"},
|
102 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml", "name": "control_v11p_sd15_inpaint_fp16.yaml"}
|
103 |
+
],
|
104 |
+
"13.instruct_p2p": [
|
105 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors", "name": "control_v11e_sd15_ip2p_fp16.safetensors"},
|
106 |
+
{"url": "https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml", "name": "control_v11e_sd15_ip2p_fp16.yaml"}
|
107 |
+
]
|
108 |
+
}
|
modules/setup_en.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import shutil
|
4 |
+
import argparse
|
5 |
+
import importlib
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser(description='Script configuration')
|
10 |
+
parser.add_argument('--lang', type=str, default='en', help='Код языка, по умолчанию "en"')
|
11 |
+
parser.add_argument('--repo', type=str, required=True, help='Repository Name')
|
12 |
+
return parser.parse_args()
|
13 |
+
|
14 |
+
def detect_environment():
|
15 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
16 |
+
environments = {
|
17 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
18 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
19 |
+
}
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
print("\033[31mError: an unsupported runtime environment was detected.\n\033[34mSupported environments:\033[0m Google Colab, Kaggle")
|
24 |
+
return None, None, None
|
25 |
+
|
26 |
+
def setup_module_folder(root_path):
|
27 |
+
modules_folder = os.path.join(root_path, "modules")
|
28 |
+
os.makedirs(modules_folder, exist_ok=True)
|
29 |
+
if modules_folder not in sys.path:
|
30 |
+
sys.path.append(modules_folder)
|
31 |
+
|
32 |
+
def clear_module_cache(modules_folder):
|
33 |
+
for module_name in list(sys.modules.keys()):
|
34 |
+
module = sys.modules[module_name]
|
35 |
+
if hasattr(module, '__file__') and module.__file__ and module.__file__.startswith(modules_folder):
|
36 |
+
del sys.modules[module_name]
|
37 |
+
|
38 |
+
importlib.invalidate_caches()
|
39 |
+
|
40 |
+
def download_files(root_path, lang, repo):
|
41 |
+
print("Please wait for the files to download... 👀", end='', flush=True)
|
42 |
+
files_dict = { # save folder name | url folder path | files list
|
43 |
+
'CSS': {'CSS': ['main_widgets.css', 'auto_cleaner.css', 'dl_display_result.css']},
|
44 |
+
'file_cell': {f'files_cells/python/{lang}': [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto_cleaner_{lang}.py']},
|
45 |
+
'file_cell/special': {f'special': ['dl_display_results.py']},
|
46 |
+
'modules': {f'modules': ['models_data.py', 'directory_setup.py']}
|
47 |
+
}
|
48 |
+
for folder, contents in files_dict.items():
|
49 |
+
folder_path = os.path.join(root_path, folder)
|
50 |
+
if os.path.exists(folder_path):
|
51 |
+
shutil.rmtree(folder_path)
|
52 |
+
os.makedirs(folder_path)
|
53 |
+
for path_url, files in contents.items():
|
54 |
+
for file in files:
|
55 |
+
file_url = f"https://huggingface.co/NagisaNao/{repo}/resolve/main/{path_url}/{file}"
|
56 |
+
file_path = os.path.join(folder_path, file)
|
57 |
+
os.system(f'wget -q {file_url} -O {file_path}')
|
58 |
+
print("\rDone! Now you can run the cells below. ☄️" + " "*30)
|
59 |
+
|
60 |
+
def main():
|
61 |
+
args = parse_args()
|
62 |
+
lang = args.lang
|
63 |
+
repo = args.repo
|
64 |
+
|
65 |
+
env, root_path, free_plan = detect_environment()
|
66 |
+
|
67 |
+
if env and root_path:
|
68 |
+
webui_path = f"{root_path}/sdw"
|
69 |
+
download_files(root_path, lang, repo)
|
70 |
+
clear_module_cache(os.path.join(root_path, "modules"))
|
71 |
+
setup_module_folder(root_path)
|
72 |
+
|
73 |
+
# Set global environment variable
|
74 |
+
os.environ['ENV_NAME'] = env
|
75 |
+
os.environ['ROOT_PATH'] = root_path
|
76 |
+
os.environ['WEBUI_PATH'] = webui_path
|
77 |
+
os.environ['FREE_PLAN'] = 'True' if free_plan else 'False'
|
78 |
+
|
79 |
+
print(f"Runtime environment: \033[33m{env}\033[0m")
|
80 |
+
if env == "Google Colab":
|
81 |
+
print(f"Colab Pro subscription: \033[34m{not free_plan}\033[0m")
|
82 |
+
print(f"File location: \033[32m{root_path}\033[0m")
|
83 |
+
|
84 |
+
if repo != 'fast_repo':
|
85 |
+
print('\n\033[31mWARNING: Test mode is used, there may be errors in use!\033[0m')
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
main()
|
modules/setup_ru.py
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
import shutil
|
4 |
+
import argparse
|
5 |
+
import importlib
|
6 |
+
import subprocess
|
7 |
+
|
8 |
+
def parse_args():
|
9 |
+
parser = argparse.ArgumentParser(description='Script configuration')
|
10 |
+
parser.add_argument('--lang', type=str, default='en', help='Код языка, по умолчанию "en"')
|
11 |
+
parser.add_argument('--repo', type=str, required=True, help='Название репозитория')
|
12 |
+
return parser.parse_args()
|
13 |
+
|
14 |
+
def detect_environment():
|
15 |
+
free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024 ** 3) <= 20)
|
16 |
+
environments = {
|
17 |
+
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
|
18 |
+
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content")
|
19 |
+
}
|
20 |
+
for env_var, (environment, path) in environments.items():
|
21 |
+
if env_var in os.environ:
|
22 |
+
return environment, path, free_plan
|
23 |
+
print("\033[31mОшибка: обнаружена неизвестная среда выполнения.\n\033[34mПоддерживаемые среды:\033[0m Google Colab, Kaggle.")
|
24 |
+
return None, None, None
|
25 |
+
|
26 |
+
def setup_module_folder(root_path):
|
27 |
+
modules_folder = os.path.join(root_path, "modules")
|
28 |
+
os.makedirs(modules_folder, exist_ok=True)
|
29 |
+
if modules_folder not in sys.path:
|
30 |
+
sys.path.append(modules_folder)
|
31 |
+
|
32 |
+
def clear_module_cache(modules_folder):
|
33 |
+
for module_name in list(sys.modules.keys()):
|
34 |
+
module = sys.modules[module_name]
|
35 |
+
if hasattr(module, '__file__') and module.__file__ and module.__file__.startswith(modules_folder):
|
36 |
+
del sys.modules[module_name]
|
37 |
+
|
38 |
+
importlib.invalidate_caches()
|
39 |
+
|
40 |
+
def download_files(root_path, lang, repo):
|
41 |
+
print("Пожалуйста, дождитесь загрузки файлов... 👀", end='', flush=True)
|
42 |
+
files_dict = { # save folder name | url folder path | files list
|
43 |
+
'CSS': {'CSS': ['main_widgets.css', 'auto_cleaner.css', 'dl_display_result.css']},
|
44 |
+
'file_cell': {f'files_cells/python/{lang}': [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto_cleaner_{lang}.py']},
|
45 |
+
'file_cell/special': {f'special': ['dl_display_results.py']},
|
46 |
+
'modules': {f'modules': ['models_data.py', 'directory_setup.py']}
|
47 |
+
}
|
48 |
+
for folder, contents in files_dict.items():
|
49 |
+
folder_path = os.path.join(root_path, folder)
|
50 |
+
if os.path.exists(folder_path):
|
51 |
+
shutil.rmtree(folder_path)
|
52 |
+
os.makedirs(folder_path)
|
53 |
+
for path_url, files in contents.items():
|
54 |
+
for file in files:
|
55 |
+
file_url = f"https://huggingface.co/NagisaNao/{repo}/resolve/main/{path_url}/{file}"
|
56 |
+
file_path = os.path.join(folder_path, file)
|
57 |
+
os.system(f'wget -q {file_url} -O {file_path}')
|
58 |
+
print(f"\rГотово! Теперь вы можете запустить ячейки ниже. ☄️" + " "*30)
|
59 |
+
|
60 |
+
def main():
|
61 |
+
args = parse_args()
|
62 |
+
lang = args.lang
|
63 |
+
repo = args.repo
|
64 |
+
|
65 |
+
env, root_path, free_plan = detect_environment()
|
66 |
+
|
67 |
+
if env and root_path:
|
68 |
+
webui_path = f"{root_path}/sdw"
|
69 |
+
download_files(root_path, lang, repo)
|
70 |
+
clear_module_cache(os.path.join(root_path, "modules"))
|
71 |
+
setup_module_folder(root_path)
|
72 |
+
|
73 |
+
# Set global environment variable
|
74 |
+
os.environ['ENV_NAME'] = env
|
75 |
+
os.environ['ROOT_PATH'] = root_path
|
76 |
+
os.environ['WEBUI_PATH'] = webui_path
|
77 |
+
os.environ['FREE_PLAN'] = 'True' if free_plan else 'False'
|
78 |
+
|
79 |
+
print(f"Среда выполнения: \033[33m{env}\033[0m")
|
80 |
+
if env == "Google Colab":
|
81 |
+
print(f"Подписка Colab Pro: \033[34m{not free_plan}\033[0m")
|
82 |
+
print(f"Расположение файлов: \033[32m{root_path}\033[0m")
|
83 |
+
|
84 |
+
if repo != 'fast_repo':
|
85 |
+
print('\n\033[31mВНИМАНИЕ: Используется тестовый режим, возможны ошибки при использовании!\033[0m')
|
86 |
+
|
87 |
+
if __name__ == "__main__":
|
88 |
+
main()
|