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