darkstorm2150 commited on
Commit
3e6dfa7
·
verified ·
1 Parent(s): 018e62b

Updating to working code

Browse files
Files changed (1) hide show
  1. app.py +144 -42
app.py CHANGED
@@ -1,60 +1,162 @@
1
  import os
2
  from subprocess import getoutput
3
 
4
- gpu_info = getoutput('nvidia-smi')
5
- if("A10G" in gpu_info):
6
- os.system("pip install -q xformers==0.0.24.post1+cu121torch2.1 -f https://nenejjj.github.io/whl/")
7
- elif("T4" in gpu_info):
8
- os.system(f"pip install -q https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+1515f77.d20221130-cp38-cp38-linux_x86_64.whl")
9
 
10
- os.system(f"git clone https://github.com/camenduru/stable-diffusion-webui /home/user/app/stable-diffusion-webui")
 
 
 
 
 
 
 
 
 
 
 
11
  os.chdir("/home/user/app/stable-diffusion-webui")
12
 
13
- os.system(f"wget -q https://github.com/camenduru/webui/raw/main/env_patch.py -O /home/user/app/env_patch.py")
14
- os.system(f'''sed -i "/import image_from_url_text/a import xformers\\nimport xformers.ops" /home/user/app/stable-diffusion-webui/modules/ui.py''')
15
- os.system(f'''sed -i -e '/import image_from_url_text/r /home/user/app/env_patch.py' /home/user/app/stable-diffusion-webui/modules/ui.py''')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
- os.system(f"sed -i -e '/(modelmerger_interface, \"Checkpoint Merger\", \"modelmerger\"),/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
18
- os.system(f"sed -i -e '/(train_interface, \"Train\", \"ti\"),/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
19
- os.system(f"sed -i -e '/extensions_interface, \"Extensions\", \"extensions\"/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
20
- os.system(f"sed -i -e '/settings_interface, \"Settings\", \"settings\"/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
21
- os.system(f'''sed -i -e "s/document.getElementsByTagName('gradio-app')\[0\].shadowRoot/!!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document/g" /home/user/app/stable-diffusion-webui/script.js''')
22
  os.system(f"sed -i -e 's/ show_progress=False,/ show_progress=True,/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
 
 
 
23
  os.system(f"sed -i -e 's/shared.demo.launch/shared.demo.queue().launch/g' /home/user/app/stable-diffusion-webui/webui.py")
24
- os.system(f"sed -i -e 's/inputs=\[component\],/&\\n queue=False,/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
25
- os.system(f"sed -i -e 's/outputs=\[token_counter\]/outputs=[token_counter], queue=False/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
26
 
27
- # ----------------------------Please duplicate this space and delete this block if you don't want to see the extra header----------------------------
28
- os.system(f"wget -q https://github.com/camenduru/webui/raw/main/header_patch.py -O /home/user/app/header_patch.py")
 
 
 
 
 
 
 
 
 
 
 
29
  os.system(f"sed -i -e '/demo:/r /home/user/app/header_patch.py' /home/user/app/stable-diffusion-webui/modules/ui.py")
30
- # ---------------------------------------------------------------------------------------------------------------------------------------------------
31
 
32
- # ------------------------------------ OpenGen Model ----------------------------------------------------------------------
33
 
34
 
35
- os.system(f"wget -q https://huggingface.co/darkstorm2150/OpenGen/resolve/main/OpenGen%20v1.0.safetensors -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/OpenGen_v1.0.safetensors")
 
 
 
 
 
 
 
 
 
36
 
37
- # ---------------------------------------------------------------------------------------------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
- # Please duplicate this space and delete # character in front of the custom script you want to use or add here more custom scripts with same structure os.system(f"wget -q https://CUSTOM_SCRIPT_URL -O /home/user/app/stable-diffusion-webui/scripts/CUSTOM_SCRIPT_NAME.py")
40
- os.system(f"wget -q https://gist.github.com/camenduru/9ec5f8141db9902e375967e93250860f/raw/d0bcf01786f20107c329c03f8968584ee67be12a/run_n_times.py -O /home/user/app/stable-diffusion-webui/scripts/run_n_times.py")
 
41
 
42
- # Please duplicate this space and delete # character in front of the extension you want to use or add here more extensions with same structure os.system(f"git clone https://EXTENSION_GIT_URL /home/user/app/stable-diffusion-webui/extensions/EXTENSION_NAME")
43
- #os.system(f"git clone https://github.com/camenduru/stable-diffusion-webui-artists-to-study /home/user/app/stable-diffusion-webui/extensions/stable-diffusion-webui-artists-to-study")
44
- os.system(f"git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser /home/user/app/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser")
45
- os.system(f"git clone https://github.com/deforum-art/deforum-for-automatic1111-webui /home/user/app/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui")
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- # Please duplicate this space and delete # character in front of the model you want to use or add here more ckpts with same structure os.system(f"wget -q https://CKPT_URL -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/CKPT_NAME.ckpt")
48
- #os.system(f"wget -q https://huggingface.co/nitrosocke/Arcane-Diffusion/resolve/main/arcane-diffusion-v3.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/arcane-diffusion-v3.ckpt")
49
- #os.system(f"wget -q https://huggingface.co/DGSpitzer/Cyberpunk-Anime-Diffusion/resolve/main/Cyberpunk-Anime-Diffusion.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/Cyberpunk-Anime-Diffusion.ckpt")
50
- #os.system(f"wget -q https://huggingface.co/prompthero/midjourney-v4-diffusion/resolve/main/mdjrny-v4.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/mdjrny-v4.ckpt")
51
- #os.system(f"wget -q https://huggingface.co/nitrosocke/mo-di-diffusion/resolve/main/moDi-v1-pruned.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/moDi-v1-pruned.ckpt")
52
- #os.system(f"wget -q https://huggingface.co/Fictiverse/Stable_Diffusion_PaperCut_Model/resolve/main/PaperCut_v1.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/PaperCut_v1.ckpt")
53
- #os.system(f"wget -q https://huggingface.co/lilpotat/sa/resolve/main/samdoesarts_style.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/samdoesarts_style.ckpt")
54
- #os.system(f"wget -q https://huggingface.co/hakurei/waifu-diffusion-v1-3/resolve/main/wd-v1-3-float32.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/wd-v1-3-float32.ckpt")
55
- #os.system(f"wget -q https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/sd-v1-4.ckpt")
56
- #os.system(f"wget -q https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt")
57
- #os.system(f"wget -q https://huggingface.co/runwayml/stable-diffusion-inpainting/resolve/main/sd-v1-5-inpainting.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/sd-v1-5-inpainting.ckpt")
58
- #os.system(f"wget -q https://huggingface.co/stabilityai/stable-diffusion-2/resolve/main/768-v-ema.ckpt -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/768-v-ema.ckpt")
59
- #os.system(f"wget -q https://raw.githubusercontent.com/Stability-AI/stablediffusion/main/configs/stable-diffusion/v2-inference-v.yaml -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/768-v-ema.yaml")
60
- os.system(f"python launch.py --force-enable-xformers --ui-config-file /home/user/app/ui-config.json --ui-settings-file /home/user/app/config.json --disable-console-progressbars --enable-console-prompts --cors-allow-origins huggingface.co,hf.space --no-progressbar-hiding --api --skip-torch-cuda-test")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  from subprocess import getoutput
3
 
4
+ # Welcome to the world of python madness!
 
 
 
 
5
 
6
+ # Debugging with Verbose mode on...
7
+ os.system(f'echo "Checking Python Version"')
8
+ os.system(f"python --version")
9
+
10
+ os.system(f'echo "Starting verbose diagnostic setup for stable-diffusion-webui..."')
11
+
12
+ # Clone repository
13
+ os.system(f'echo "Cloning Stable Diffusion WebUI repository from darkstorm2150..."')
14
+ os.system(f"git clone https://github.com/darkstorm2150/stable-diffusion-webui /home/user/app/stable-diffusion-webui")
15
+
16
+ # Set working directory
17
+ os.system(f'echo "Setting working directory to stable-diffusion-webui root folder..."')
18
  os.chdir("/home/user/app/stable-diffusion-webui")
19
 
20
+ # clean requirements.txt
21
+ #os.system(f'echo "Removing numpy and torch from requirements.txt to prevent version conflicts..."')
22
+ #os.system(f"sed -i '/numpy/d' /home/user/app/stable-diffusion-webui/requirements.txt")
23
+ #os.system(f"sed -i '/torch/d' /home/user/app/stable-diffusion-webui/requirements.txt")
24
+
25
+ # Patch environment
26
+ os.system(f'echo "Downloading environment patch script..."')
27
+ os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/env_patch.py -O /home/user/app/env_patch.py")
28
+ os.system(f"sed -i -e '/import image_from_url_text/r /home/user/app/env_patch.py' /home/user/app/stable-diffusion-webui/modules/ui.py")
29
+
30
+ # UI customization
31
+ #os.system(f'echo "Removing Checkpoint Merger tab from UI..."')
32
+ #os.system(f"sed -i -e '/(modelmerger_interface, \"Checkpoint Merger\", \"modelmerger\"),/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
33
+
34
+ #os.system(f'echo "Removing Training tab from UI..."')
35
+ #os.system(f"sed -i -e '/(train_interface, \"Train\", \"ti\"),/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
36
+
37
+ #os.system(f'echo "Removing Extensions tab from UI..."')
38
+ #os.system(f"sed -i -e '/extensions_interface, \"Extensions\", \"extensions\"/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
39
+
40
+ #os.system(f'echo "Removing Settings tab from UI..."')
41
+ #os.system(f"sed -i -e '/settings_interface, \"Settings\", \"settings\"/d' /home/user/app/stable-diffusion-webui/modules/ui.py")
42
+
43
+ # Gradio shadowRoot fix
44
+ os.system(f'echo "Fixing Gradio shadowRoot access in script.js for Hugging Face compatibility..."')
45
+ os.system(f'''sed -i -e "s/document.getElementsByTagName('gradio-app')\\[0\\].shadowRoot/!!document.getElementsByTagName('gradio-app')[0].shadowRoot ? document.getElementsByTagName('gradio-app')[0].shadowRoot : document/g" /home/user/app/stable-diffusion-webui/script.js''')
46
 
47
+ # Progress bar settings
48
+ os.system(f'echo "Enabling progress bars in UI for better user feedback..."')
 
 
 
49
  os.system(f"sed -i -e 's/ show_progress=False,/ show_progress=True,/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
50
+
51
+ # Queue settings
52
+ os.system(f'echo "Modifying webui.py to enable queuing for async processing..."')
53
  os.system(f"sed -i -e 's/shared.demo.launch/shared.demo.queue().launch/g' /home/user/app/stable-diffusion-webui/webui.py")
 
 
54
 
55
+ os.system(f'echo "Disabling queuing for input components to reduce latency..."')
56
+ os.system(f"sed -i -e 's/inputs=\\[component\\],/&\\n queue=False,/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
57
+
58
+ os.system(f'echo "Disabling queuing for token counter outputs..."')
59
+ os.system(f"sed -i -e 's/outputs=\\[token_counter\\]/outputs=[token_counter], queue=False/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
60
+
61
+
62
+
63
+ # ----------------------------Patch UI Header for Hugging Face Spaces----------------------------
64
+ os.system(f'echo "Downloading header_patch.py to customize UI header banners..."')
65
+ os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/header_patch.py -O /home/user/app/header_patch.py")
66
+
67
+ os.system(f'echo "Injecting header_patch.py content into modules/ui.py under the demo section..."')
68
  os.system(f"sed -i -e '/demo:/r /home/user/app/header_patch.py' /home/user/app/stable-diffusion-webui/modules/ui.py")
69
+ # ---------------------------------------------------------------------------------------------
70
 
 
71
 
72
 
73
+ # Handle shared vs. non-shared UI setup with verbose logging
74
+ if "IS_SHARED_UI" in os.environ:
75
+ os.system(f'echo "IS_SHARED_UI IS ENABLED: Loading shared configurations..."')
76
+
77
+ # Download shared UI configuration files
78
+ os.system(f"echo 'Downloading shared-config.json for UI settings...'")
79
+ os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/shared-config.json -O /home/user/app/shared-config.json")
80
+
81
+ os.system(f"echo 'Downloading shared-ui-config.json for layout preferences...'")
82
+ os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/shared-ui-config.json -O /home/user/app/shared-ui-config.json")
83
 
84
+ # Launch WebUI with shared settings
85
+ os.system(f'echo "Starting WebUI with shared configurations..."')
86
+ os.system(f"python launch.py --disable-console-progressbars --enable-console-prompts --ui-config-file /home/user/app/shared-ui-config.json --ui-settings-file /home/user/app/shared-config.json --cors-allow-origins huggingface.co,hf.space --no-progressbar-hiding")
87
+ else:
88
+ os.system(f'echo "IS_SHARED_UI IS DISABLED: Setting up custom environment..."')
89
+
90
+ # Download custom scripts
91
+ os.system(f'echo "Installing run_n_times.py script for batch processing..."')
92
+ os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/run_n_times.py -O /home/user/app/stable-diffusion-webui/scripts/run_n_times.py")
93
+
94
+ # Install extensions (commented lines can be activated by removing #)
95
+ os.system(f'echo "Installing image browser extension for managing outputs..."')
96
+ os.system(f"git clone https://github.com/yfszzx/stable-diffusion-webui-images-browser /home/user/app/stable-diffusion-webui/extensions/stable-diffusion-webui-images-browser")
97
+
98
+ os.system(f'echo "Installing Deforum animation extension..."')
99
+ os.system(f"git clone https://github.com/deforum-art/deforum-for-automatic1111-webui /home/user/app/stable-diffusion-webui/extensions/deforum-for-automatic1111-webui")
100
+
101
+ # Load Protogen model (example custom model)
102
+ os.system(f'echo "Downloading Protogen X3.4 Stable Diffusion model..."')
103
+ os.system(f"wget -q https://huggingface.co/darkstorm2150/OpenGen/resolve/main/OpenGen%20v1.0.safetensors -O /home/user/app/stable-diffusion-webui/models/Stable-diffusion/OpenGen_v1.0.safetensors")
104
+
105
+ # Critical dependency installation sequence
106
+ #os.system(f'echo "starting dependency cleanup..."')
107
+ #os.system(f'pip cache purge')
108
 
109
+ # Running multiple times to remove stubborn copies
110
+ #os.system(f'echo "Removing all existing numpy versions..."')
111
+ #os.system(f'pip uninstall -y numpy numpy numpy')
112
 
113
+ # Force NumPy 1.26.4 first
114
+ #os.system(f'echo "Installing NumPy 1.26.4..."')
115
+ #os.system(f"pip install --no-cache-dir numpy==1.26.4")
116
+
117
+ # Verify NumPy Version 1.26.4
118
+ #os.system(f"python -c 'import numpy; print(numpy.__version__)'")
119
+
120
+ # Install PyTorch + xformers with CUDA compatibility
121
+ #os.system(f'echo "Installing PyTorch..."')
122
+ #os.system(f"pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 --extra-index-url https://download.pytorch.org/whl/cu121 ")
123
+
124
+ #os.system(f'echo "Installing xformers..."')
125
+ #os.system(f"pip install --no-cache-dir xformers==0.0.25 --extra-index-url https://download.pytorch.org/whl/cu118")
126
+
127
+ os.system(f'echo "Installing build dependencies..."')
128
+ os.system(f'pip install ninja packaging wheel')
129
+ os.system(f'apt-get update && apt-get install -y build-essential cmake git')
130
 
131
+ # Building xformers from source
132
+ os.system(f'echo "Cloning xformers repo..."')
133
+ os.system(f'git clone https://github.com/facebookresearch/xformers.git /home/user/app/xformers')
134
+ os.system("cd /home/user/app/xformers && git submodule update --init --recursive")
135
+
136
+ # Change directory to xformers and install
137
+ os.chdir('/home/user/app/xformers')
138
+ os.system('pip install --no-cache-dir -e .')
139
+
140
+ # Final verification
141
+ os.system(f'echo "Verifying NumPy and PyTorch..."')
142
+
143
+ os.system("python -c 'import numpy; print(\"NumPy:\", numpy.__version__)'")
144
+ os.system("python -c 'import torch; print(\"PyTorch:\", torch.__version__)'")
145
+
146
+ # Explicitly verify xformers import
147
+ os.system("python -c 'import xformers; print(\"xformers version:\", xformers.__version__)'")
148
+
149
+ # Launch WebUI with custom settings
150
+ os.system(f'echo "Starting WebUI..."')
151
+
152
+ # reinstalling libraries
153
+ os.system(f'pip uninstall -y torch torchvision xformers')
154
+ os.system(f'pip install torch==2.7.1+cu126 torchvision==0.18.1+cu126 --extra-index-url https://download.pytorch.org/whl/cu126')
155
+ os.system(f'pip install xformers==0.0.32+0f0bb9d9.d20250720 --extra-index-url https://download.pytorch.org/whl/cu126')
156
+
157
+ os.system(f'pip install -U ninja cmake pybind11')
158
+
159
+ # starting xformers with WebUI...
160
+ os.chdir('/home/user/app/stable-diffusion-webui')
161
+ os.system("python launch.py --ui-config-file /home/user/app/shared-ui-config.json --ui-settings-file /home/user/app/shared-config.json --disable-console-progressbars --enable-console-prompts --cors-allow-origins huggingface.co,hf.space --no-progressbar-hiding --api --skip-torch-cuda-test")
162
+