File size: 13,465 Bytes
eec351f
58a9f11
b2449ef
817c7fb
347cbd6
 
 
 
 
2417a52
347cbd6
 
 
 
 
 
 
 
817c7fb
 
 
 
 
 
b2449ef
18a56fa
347cbd6
 
 
 
2417a52
347cbd6
18a56fa
b2449ef
18a56fa
 
 
b2449ef
18a56fa
 
 
 
 
 
 
 
 
 
 
 
 
 
b2449ef
 
347cbd6
18a56fa
 
 
 
 
 
 
 
b2449ef
18a56fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eec351f
b2449ef
18a56fa
 
b2449ef
eec351f
b2449ef
34a90c1
 
eec351f
347cbd6
b2449ef
18a56fa
eec351f
18a56fa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import os

user_home = r"/home/user/app"

# 1. Create a constraint file to strictly pin NumPy < 2.0
# This prevents extensions (like ControlNet) from auto-upgrading NumPy and breaking the WebUI.
constraint_file_path = os.path.join(user_home, "constraints.txt")
with open(constraint_file_path, "w") as f:
    f.write("numpy<2.0.0\n")
    f.write("setuptools<82.0.0\n")

# 2. Set environment variables
# PIP_CONSTRAINT tells pip to use our file for ALL installations.
os.environ['PIP_CONSTRAINT'] = constraint_file_path
# STABLE_DIFFUSION_REPO fixes the 404 error by using a community mirror.
os.environ['STABLE_DIFFUSION_REPO'] = "https://github.com/w-e-w/stablediffusion.git"

# Standard temp dir setup
tmp_dir = os.path.join(user_home, "tmp")
os.makedirs(tmp_dir, exist_ok=True)
os.environ['TMPDIR'] = tmp_dir
os.environ['TEMP'] = tmp_dir
os.environ['TMP'] = tmp_dir

os.chdir(user_home)

# 3. Force install strict dependencies immediately
# We install numpy<2.0.0 now, and the PIP_CONSTRAINT env var ensures it stays that way.
print("Forcing installation of NumPy < 2.0.0...")
os.system("pip install 'numpy<2.0.0'")
os.system("pip install 'setuptools<82.0.0'")

# Clone stable-diffusion-webui repo
print("cloning stable-diffusion-webui repo")
os.system("git clone \"https://github.com/AUTOMATIC1111/stable-diffusion-webui.git\" " + user_home + r"/stable-diffusion-webui")

# Install extensions
print("installing extensions")
os.system(r"git clone https://huggingface.co/embed/negative " + user_home + "/stable-diffusion-webui/embeddings/negative")
os.system(r"git clone https://huggingface.co/embed/lora " + user_home + "/stable-diffusion-webui/models/Lora/positive")

os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d " + user_home + "/stable-diffusion-webui/models/ESRGAN -o 4x-UltraSharp.pth")
os.system(r"wget https://raw.githubusercontent.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O " + user_home + "/stable-diffusion-webui/scripts/run_n_times.py")
os.system(r"git clone https://github.com/AlUlkesh/stable-diffusion-webui-images-browser " + user_home + "/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser")
os.system(r"git clone https://github.com/camenduru/stable-diffusion-webui-huggingface " + user_home + "/stable-diffusion-webui/extensions/stable-diffusion-webui-huggingface")
os.system(r"git clone https://github.com/Mikubill/sd-webui-controlnet " + user_home + "/stable-diffusion-webui/extensions/sd-webui-controlnet")
os.system(r"git clone https://github.com/jexom/sd-webui-depth-lib " + user_home + "/stable-diffusion-webui/extensions/sd-webui-depth-lib")
os.system(r"git clone https://github.com/hnmr293/posex " + user_home + "/stable-diffusion-webui/extensions/posex")
os.system(r"git clone https://github.com/nonnonstop/sd-webui-3d-open-pose-editor " + user_home + "/stable-diffusion-webui/extensions/sd-webui-3d-open-pose-editor")
os.system(r"git clone https://github.com/imrayya/stable-diffusion-webui-Prompt_Generator " + user_home + "/stable-diffusion-webui/extensions/sd-webui-Prompt_Generator")

os.chdir(os.path.join(user_home, r"stable-diffusion-webui"))
os.system(r"git reset --hard")

# Pre-clone the stable-diffusion repository to ensure it exists before reset
repo_dir = os.path.join(user_home, "stable-diffusion-webui/repositories/stable-diffusion-stability-ai")
if not os.path.exists(repo_dir):
    print("Pre-cloning Stable Diffusion repo fix...")
    os.system(f"git clone https://github.com/w-e-w/stablediffusion.git {repo_dir}")

os.system(r"git -C " + repo_dir + " reset --hard")

# Download ControlNet models
print("downloading ControlNet models")
cn_models_dir = user_home + "/stable-diffusion-webui/extensions/sd-webui-controlnet/models"

os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors -d " + cn_models_dir + " -o control_v11e_sd15_ip2p_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors -d " + cn_models_dir + " -o control_v11e_sd15_shuffle_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_canny_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors -d " + cn_models_dir + " -o control_v11f1p_sd15_depth_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_inpaint_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_lineart_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_mlsd_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_normalbae_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_openpose_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_scribble_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_seg_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15_softedge_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors -d " + cn_models_dir + " -o control_v11p_sd15s2_lineart_anime_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors -d " + cn_models_dir + " -o control_v11f1e_sd15_tile_fp16.safetensors")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_ip2p_fp16.yaml -d " + cn_models_dir + " -o control_v11e_sd15_ip2p_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11e_sd15_shuffle_fp16.yaml -d " + cn_models_dir + " -o control_v11e_sd15_shuffle_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_canny_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_canny_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1p_sd15_depth_fp16.yaml -d " + cn_models_dir + " -o control_v11f1p_sd15_depth_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_inpaint_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_inpaint_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_lineart_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_lineart_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_mlsd_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_mlsd_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_normalbae_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_normalbae_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_openpose_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_openpose_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_scribble_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_scribble_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_seg_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_seg_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15_softedge_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15_softedge_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11p_sd15s2_lineart_anime_fp16.yaml -d " + cn_models_dir + " -o control_v11p_sd15s2_lineart_anime_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/raw/main/control_v11f1e_sd15_tile_fp16.yaml -d " + cn_models_dir + " -o control_v11f1e_sd15_tile_fp16.yaml")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_style_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_style_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_sketch_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_seg_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_seg_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_openpose_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_openpose_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_keypose_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_keypose_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_depth_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd14v1.pth -d " + cn_models_dir + " -o t2iadapter_canny_sd14v1.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_canny_sd15v2.pth -d " + cn_models_dir + " -o t2iadapter_canny_sd15v2.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_depth_sd15v2.pth -d " + cn_models_dir + " -o t2iadapter_depth_sd15v2.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_sketch_sd15v2.pth -d " + cn_models_dir + " -o t2iadapter_sketch_sd15v2.pth")
os.system(r"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/ControlNet-v1-1/resolve/main/t2iadapter_zoedepth_sd15v1.pth -d " + cn_models_dir + " -o t2iadapter_zoedepth_sd15v1.pth")

try:
   os.makedirs(os.path.join(user_home, "stable-diffusion-webui/models/Stable-diffusion"), exist_ok=True)
except FileExistsError:
   print("exist")

print("downloading model")
os.system(f"wget -q https://huggingface.co/FredZhang7/paint-journey-v2/resolve/main/paint_journey_v2_cpu_only.ckpt -O {user_home}/stable-diffusion-webui/models/Stable-diffusion/paint_journey_v2_cpu_only.ckpt")
os.system(f"wget -q  https://huggingface.co/FredZhang7/paint-journey-v2/resolve/main/paint_journey_v2.vae.pt -O {user_home}/stable-diffusion-webui/models/Stable-diffusion/paint_journey_v2_cpu_only.vae.pt")

# start webui
print("Done\nStarting Webui...")
os.system(r"python3 launch.py --precision full --ui-config-file /home/user/app/ui-config.json --ui-settings-file /home/user/app/config.json --no-half --no-half-vae --enable-insecure-extension-access --medvram --skip-torch-cuda-test")

del os, user_home