SiddhJagani commited on
Commit
82cd55e
·
verified ·
1 Parent(s): 825f751

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -92
app.py CHANGED
@@ -2,11 +2,9 @@ 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
@@ -17,29 +15,11 @@ os.system(f"git clone https://github.com/darkstorm2150/stable-diffusion-webui /
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''')
@@ -51,112 +31,53 @@ os.system(f"sed -i -e 's/ show_progress=False,/ sh
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 OpenGen v1.0 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
-
 
2
  from subprocess import getoutput
3
 
4
  # Welcome to the world of python madness!
 
5
  # Debugging with Verbose mode on...
6
  os.system(f'echo "Checking Python Version"')
7
  os.system(f"python --version")
 
8
  os.system(f'echo "Starting verbose diagnostic setup for stable-diffusion-webui..."')
9
 
10
  # Clone repository
 
15
  os.system(f'echo "Setting working directory to stable-diffusion-webui root folder..."')
16
  os.chdir("/home/user/app/stable-diffusion-webui")
17
 
 
 
 
 
 
18
  # Patch environment
19
  os.system(f'echo "Downloading environment patch script..."')
20
  os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/env_patch.py -O /home/user/app/env_patch.py")
21
  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")
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  # Gradio shadowRoot fix
24
  os.system(f'echo "Fixing Gradio shadowRoot access in script.js for Hugging Face compatibility..."')
25
  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''')
 
31
  # Queue settings
32
  os.system(f'echo "Modifying webui.py to enable queuing for async processing..."')
33
  os.system(f"sed -i -e 's/shared.demo.launch/shared.demo.queue().launch/g' /home/user/app/stable-diffusion-webui/webui.py")
 
34
  os.system(f'echo "Disabling queuing for input components to reduce latency..."')
35
  os.system(f"sed -i -e 's/inputs=\\[component\\],/&\\n queue=False,/g' /home/user/app/stable-diffusion-webui/modules/ui.py")
 
36
  os.system(f'echo "Disabling queuing for token counter outputs..."')
37
  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")
38
 
 
 
39
  # ----------------------------Patch UI Header for Hugging Face Spaces----------------------------
40
  os.system(f'echo "Downloading header_patch.py to customize UI header banners..."')
41
  os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/header_patch.py -O /home/user/app/header_patch.py")
 
42
  os.system(f'echo "Injecting header_patch.py content into modules/ui.py under the demo section..."')
43
  os.system(f"sed -i -e '/demo:/r /home/user/app/header_patch.py' /home/user/app/stable-diffusion-webui/modules/ui.py")
44
  # ---------------------------------------------------------------------------------------------
45
 
 
 
46
  # Handle shared vs. non-shared UI setup with verbose logging
47
  if "IS_SHARED_UI" in os.environ:
48
  os.system(f'echo "IS_SHARED_UI IS ENABLED: Loading shared configurations..."')
 
49
  # Download shared UI configuration files
50
  os.system(f"echo 'Downloading shared-config.json for UI settings...'")
51
  os.system(f"wget https://raw.githubusercontent.com/darkstorm2150/webui/refs/heads/main/shared-config.json -O /home/user/app/shared-config.json")
52
+ os.system(f"echo 'Downloading shared-ui-config.json for layout preferences...'")
 
53
  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")
 
54
  # Launch WebUI with shared settings
55
  os.system(f'echo "Starting WebUI with shared configurations..."')
56
+ 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 --use-cpu all --no-half")
57
  else:
58
  os.system(f'echo "IS_SHARED_UI IS DISABLED: Setting up custom environment..."')
 
59
  # Download custom scripts
60
  os.system(f'echo "Installing run_n_times.py script for batch processing..."')
61
  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")
62
+ # Install extensions
 
63
  os.system(f'echo "Installing image browser extension for managing outputs..."')
64
  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")
 
65
  os.system(f'echo "Installing Deforum animation extension..."')
66
  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")
67
+ # Load Protogen model
 
68
  os.system(f'echo "Downloading OpenGen v1.0 Stable Diffusion model..."')
69
  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")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
+ # Install CPU-specific dependencies
72
+ os.system(f'echo "Uninstalling any existing torch, torchvision, and xformers..."')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  os.system(f'pip uninstall -y torch torchvision xformers')
74
+
75
+ os.system(f'echo "Installing CPU version of PyTorch..."')
76
+ os.system(f'pip install torch torchvision --no-cache-dir')
77
 
78
+ os.system(f'echo "Verifying PyTorch installation..."')
79
+ os.system("python -c 'import torch; print(\"PyTorch:\", torch.__version__, \"(CPU version)\")'")
80
 
81
+ # Launch WebUI with CPU-specific settings
82
  os.chdir('/home/user/app/stable-diffusion-webui')
83
+ 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 --use-cpu all --no-half")