gmk123 commited on
Commit
3fc6d0b
·
verified ·
1 Parent(s): e23037e

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +66 -172
main.py CHANGED
@@ -1,172 +1,66 @@
1
- import sys
2
- import os
3
- from IPython import get_ipython
4
- from IPython.utils import capture
5
- from IPython.display import clear_output
6
-
7
- # 设置Stable-diffusion文件目录
8
- wb = f'/home/studio-lab-user/stable-diffusion-webui'
9
-
10
- # clong git
11
- def gitDownload(url, localPath):
12
- if os.path.exists(localPath):
13
- return
14
-
15
- get_ipython().system(f'git clone {url} {localPath}')
16
-
17
- # 安装附加功能
18
- def installAdditional():
19
- # 安装扩展
20
- urls = [
21
- f'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',# 图像浏览器
22
- f'https://github.com/etherealxx/batchlinks-webui', # 批量下载模型lora
23
- f'https://github.com/camenduru/sd-civitai-browser', # Civitai 分类和搜索
24
- f'https://github.com/thomasasfk/sd-webui-aspect-ratio-helper', # 宽高比调整功能
25
- f'https://github.com/kohya-ss/sd-webui-additional-networks', # 模型网络
26
- f'https://github.com/fkunn1326/openpose-editor', # 人体姿态编辑功能
27
- f'https://github.com/nonnonstop/sd-webui-3d-open-pose-editor', # 3D 人体姿态编辑功能
28
- f'https://github.com/Physton/sd-webui-prompt-all-in-one', # 关键词插件
29
- f'https://github.com/Bing-su/adetailer', # 脸部修复
30
- f'https://github.com/picobyte/stable-diffusion-webui-wd14-tagger', # tag反推
31
- f'https://github.com/Mikubill/sd-webui-controlnet', # cnt
32
- f'https://github.com/IDEA-Research/DWPose', # cnt手部模型
33
- f'https://github.com/hanamizuki-ai/stable-diffusion-webui-localization-zh_Hans', # 中文
34
- # f'https://github.com/camenduru/sd-webui-tunnels', # Tunnel 网络支持
35
- # f'https://github.com/AUTOMATIC1111/stable-diffusion-webui-rembg', # 背景移除功能
36
- # f'https://github.com/hnmr293/posex', # 人体姿态估计
37
- # f'https://github.com/s9roll7/ebsynth_utility', # 视频转绘
38
- # f'https://github.com/aigc-apps/sd-webui-EasyPhoto', # 视频图像生成
39
- # f'https://github.com/ashen-sensored/stable-diffusion-webui-two-shot', # 潜变量成对(双人特写)
40
- # f'https://github.com/camenduru/stable-diffusion-webui-huggingface', # 整合 Huggingface 的模型功能
41
- # f'https://github.com/camenduru/stable-diffusion-webui-catppuccin', # Catppuccin 主题
42
- # f'https://github.com/IDEA-Research/DWPose', # cnt手部模型
43
- # f'https://github.com/KohakuBlueleaf/a1111-sd-webui-lycoris', # 人物生成模型
44
- # f'https://github.com/Uminosachi/sd-webui-inpaint-anything', # 抠图
45
- # f'https://github.com/adieyal/sd-dynamic-prompts', # 动态提示词
46
- # f'https://github.com/antfu/sd-webui-qrcode-toolkit', # 二维码生成
47
- # f'https://github.com/Tencent/LightDiffusionFlow', # 复制工作流
48
- # f'https://github.com/yankooliveira/sd-webui-photopea-embed', # PS批图插件
49
- # f'https://github.com/jexom/sd-webui-depth-lib', # 深度图编辑器
50
- # f'https://github.com/Gerschel/sd_web_ui_preset_utils', # 预设
51
- # f'https://github.com/numz/sd-wav2lip-uhq', # 数字人说话
52
- # f'https://github.com/a2569875/stable-diffusion-webui-composable-lora', # 可自组 LoRA
53
- # f'https://github.com/deforum-art/sd-webui-deforum', # Deforum动态视频创作
54
- # f'https://github.com/Scholar01/sd-webui-mov2mov', # 视频转换
55
- # f'https://github.com/tjm35/asymmetric-tiling-sd-webui', # 非对称平铺功能
56
- # f'https://github.com/hako-mikan/sd-webui-lora-block-weight', # LORA 模型的权重调整
57
- # f'https://github.com/hako-mikan/sd-webui-supermerger', # 图像融合功能
58
- # f'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111', # 分块VAE
59
- ]
60
- for url in urls:
61
-
62
- filename = url.split('/')[-1]
63
-
64
- if 'github' in url:
65
- get_ipython().system(f'git clone --depth 1 {url} {wb}/extensions/{filename}')
66
-
67
- get_ipython().system(f'wget https://raw.githubuserhome/studio-lab-user.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')
68
- get_ipython().system(f'wget https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -O {wb}/models/ESRGAN/4x-UltraSharp.pth')
69
-
70
-
71
- # 优化embeddings
72
- gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
73
- get_ipython().system(f'rm -rf {wb}/embeddings/negative/.git')
74
- get_ipython().system(f'rm {wb}/embeddings/negative/.gitattributes')
75
-
76
- gitDownload(f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')
77
- get_ipython().system(f'rm -rf {wb}/models/Lora/positive/.git')
78
- get_ipython().system(f'rm {wb}/models/Lora/positive/.gitattributes')
79
-
80
- #Tag插件
81
- gitDownload(f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')
82
- get_ipython().system(f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')
83
- get_ipython().system(f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')
84
-
85
- #Roop换脸插件
86
- gitDownload(f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')
87
- get_ipython().system(f'pip install insightface==0.7.3') # 换脸插件
88
- get_ipython().system(f'mkdir -p {wb}/models/roop')
89
- get_ipython().system(f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')
90
- print('Roop换脸启用')
91
-
92
- # 部署conda环境
93
- # import subprocess
94
- # def run_command(command, message):
95
- # print(f"Please wait, {message} is loading...")
96
- # subprocess.run(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
97
- # print(f"{message} completed!")
98
-
99
-
100
- # 初始化本地环境
101
- def initLocal():
102
- #部署环境变量
103
- # run_command('conda install conda -y', 'Conda')
104
- # run_command('conda update -n base conda -y', 'Update')
105
- # run_command('conda install -n base python=3.10 -y', 'Python')
106
- # run_command('conda install -q -y glib=2.51.0', 'glib')
107
-
108
- # run_command('conda install -y conda glib psutil gperftools aria2 gdown', 'Installing Conda')
109
- # run_command('conda install -y -n base python=3.10.12', 'Installing Python')
110
- # run_command('conda clean -y --all', 'Cleaning Conda')
111
- # run_command('pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118', 'Installing Torch')
112
- # run_command('pip install xformers==0.0.20 triton==2.0.0', 'Installing xformers')
113
-
114
- #配置conda环境
115
- get_ipython().system('conda install -c conda-forge libglib -y && conda update -n base conda -y')
116
- get_ipython().system(f'pip install -q torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 torchtext==0.15.2 torchdata==0.6.1 --extra-index-url https://download.pytorch.org/whl/cu118 -U')
117
- get_ipython().system('conda install -q -y aria2')
118
- get_ipython().system('pip install tqdm')
119
-
120
- clear_output()
121
- get_ipython().run_line_magic('cd', '/home/studio-lab-user')
122
-
123
- #安装sd包
124
- get_ipython().system(f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')
125
-
126
- get_ipython().system(f'pip install -qq pycloudflared ngrok') # ngrok网络加速
127
- get_ipython().system(f'pip install --force-reinstall charset-normalizer==3.1.0') # 字符编码处理基础工具包
128
- get_ipython().system(f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')
129
-
130
- get_ipython().system(f'pip install fake_useragent') # civi、插件模块
131
-
132
- ########################################################
133
-
134
- # 安装附加功能
135
- installAdditional()
136
-
137
- clear_output()
138
- # 链接用户配置
139
- get_ipython().system(f'rm -rf {wb}/config.json')
140
- get_ipython().system(f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')
141
- get_ipython().system(f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')
142
-
143
- # 下载主模型
144
- get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/192916 -d {wb}/models/Stable-diffusion -o MoyouArtificial_v1060.safetensors')
145
- # 下载VAE
146
- get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -d {wb}/models/VAE -o vae-ft-mse-840000-ema-pruned.safetensors')
147
- # 放大脚本
148
- get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')
149
-
150
- wise = "--listen --api --enable-insecure-extension-access --xformers --theme dark --gradio-queue --disable-console-progressbars --upcast-sampling --cors-allow-origins=*"
151
-
152
- # Ngrok内网加速
153
- ngrok_token = os.environ.get('NGROK_TOKEN')
154
- wise += f" --ngrok {ngrok_token}"
155
-
156
- # 运行
157
- def run(script):
158
- clear_output()
159
- print(f'Ngrok内网令牌:{ngrok_token}')
160
- print(f'参数:{wise}')
161
- get_ipython().run_line_magic('cd', f'{wb}')
162
- get_ipython().system(f'python {script} {wise}')
163
-
164
- # 运行脚本
165
- if os.path.exists(f'{wb}'):
166
- run(f'webui.py')
167
- else:
168
- # 初化本地环境
169
- initLocal()
170
-
171
- # 运行
172
- run(f'launch.py')
 
1
+ import sys #line:1
2
+ import os #line:2
3
+ from IPython import get_ipython #line:3
4
+ from IPython .utils import capture #line:4
5
+ from IPython .display import clear_output #line:5
6
+ wb =f'/home/studio-lab-user/stable-diffusion-webui'#line:8
7
+ def gitDownload (OO000O00O000O000O ,O00O0O00OOOOO0000 ):#line:11
8
+ if os .path .exists (O00O0O00OOOOO0000 ):#line:12
9
+ return #line:13
10
+ get_ipython ().system (f'git clone {OO000O00O000O000O} {O00O0O00OOOOO0000}')#line:15
11
+ def installAdditional ():#line:18
12
+ O0000OOOOOO0O0000 =[f'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',f'https://github.com/etherealxx/batchlinks-webui',f'https://github.com/camenduru/sd-civitai-browser',f'https://github.com/thomasasfk/sd-webui-aspect-ratio-helper',f'https://github.com/kohya-ss/sd-webui-additional-networks',f'https://github.com/fkunn1326/openpose-editor',f'https://github.com/nonnonstop/sd-webui-3d-open-pose-editor',f'https://github.com/Physton/sd-webui-prompt-all-in-one',f'https://github.com/Bing-su/adetailer',f'https://github.com/picobyte/stable-diffusion-webui-wd14-tagger',f'https://github.com/Mikubill/sd-webui-controlnet',f'https://github.com/IDEA-Research/DWPose',f'https://github.com/hanamizuki-ai/stable-diffusion-webui-localization-zh_Hans',]#line:59
13
+ for OO0O000O0OOO00O0O in O0000OOOOOO0O0000 :#line:60
14
+ O0O00000OO000000O =OO0O000O0OOO00O0O .split ('/')[-1 ]#line:62
15
+ if 'github'in OO0O000O0OOO00O0O :#line:64
16
+ get_ipython ().system (f'git clone --depth 1 {OO0O000O0OOO00O0O} {wb}/extensions/{O0O00000OO000000O}')#line:65
17
+ get_ipython ().system (f'wget https://raw.githubuserhome/studio-lab-user.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')#line:67
18
+ get_ipython ().system (f'wget https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -O {wb}/models/ESRGAN/4x-UltraSharp.pth')#line:68
19
+ gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:72
20
+ get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:73
21
+ get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:74
22
+ gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:76
23
+ get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:77
24
+ get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:78
25
+ gitDownload (f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')#line:81
26
+ get_ipython ().system (f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:82
27
+ get_ipython ().system (f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:83
28
+ gitDownload (f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')#line:86
29
+ get_ipython ().system (f'pip install insightface==0.7.3')#line:87
30
+ get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:88
31
+ get_ipython ().system (f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')#line:89
32
+ print ('Roop换脸启用')#line:90
33
+ def initLocal ():#line:101
34
+ get_ipython ().system ('conda install -c conda-forge libglib -y && conda update -n base conda -y')#line:115
35
+ get_ipython ().system (f'pip install -q torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 torchtext==0.15.2 torchdata==0.6.1 --extra-index-url https://download.pytorch.org/whl/cu118 -U')#line:116
36
+ get_ipython ().system ('conda install -q -y aria2')#line:117
37
+ get_ipython ().system ('pip install tqdm')#line:118
38
+ clear_output ()#line:120
39
+ get_ipython ().run_line_magic ('cd','/home/studio-lab-user')#line:121
40
+ get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')#line:124
41
+ get_ipython ().system (f'pip install -qq pycloudflared ngrok')#line:126
42
+ get_ipython ().system (f'pip install --force-reinstall charset-normalizer==3.1.0')#line:127
43
+ get_ipython ().system (f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')#line:128
44
+ get_ipython ().system (f'pip install fake_useragent')#line:130
45
+ installAdditional ()#line:135
46
+ clear_output ()#line:137
47
+ get_ipython ().system (f'rm -rf {wb}/config.json')#line:139
48
+ get_ipython ().system (f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:140
49
+ get_ipython ().system (f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:141
50
+ get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/192916 -d {wb}/models/Stable-diffusion -o MoyouArtificial_v1060.safetensors')#line:144
51
+ get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors -d {wb}/models/VAE -o vae-ft-mse-840000-ema-pruned.safetensors')#line:146
52
+ get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -d {wb}/models/ESRGAN -o 4x-UltraSharp.pth')#line:148
53
+ wise ="--listen --api --enable-insecure-extension-access --xformers --theme dark --gradio-queue --disable-console-progressbars --upcast-sampling --cors-allow-origins=*"#line:150
54
+ ngrok_token =os .environ .get ('NGROK_TOKEN')#line:153
55
+ wise +=f" --ngrok {ngrok_token}"#line:154
56
+ def run (O0000OOO00O00O000 ):#line:157
57
+ clear_output ()#line:158
58
+ print (f'Ngrok内网令牌:{ngrok_token}')#line:159
59
+ print (f'参数:{wise}')#line:160
60
+ get_ipython ().run_line_magic ('cd',f'{wb}')#line:161
61
+ get_ipython ().system (f'python {O0000OOO00O00O000} {wise}')#line:162
62
+ if os .path .exists (f'{wb}'):#line:165
63
+ run (f'webui.py')#line:166
64
+ else :#line:167
65
+ initLocal ()#line:169
66
+ run (f'launch.py')#line:172