gmk123 commited on
Commit
0b43475
·
1 Parent(s): 7f0f332

Upload Xl.py

Browse files
Files changed (1) hide show
  1. Xl.py +185 -0
Xl.py ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import binascii
3
+
4
+ # 自定义类型转换函数
5
+ def str_to_bool(value):
6
+ if value.lower() in ('yes', 'true', 't', 'y', '1'):
7
+ return True
8
+ elif value.lower() in ('no', 'false', 'f', 'n', '0'):
9
+ return False
10
+ else:
11
+ raise argparse.ArgumentTypeError('Invalid boolean value: {}'.format(value))
12
+
13
+ # 创建参数解析器
14
+ parser = argparse.ArgumentParser()
15
+
16
+ parser.add_argument('--Version', type=str)
17
+ parser.add_argument('--ControlNet', type=str_to_bool)
18
+
19
+ # 解析命令行参数
20
+ args = parser.parse_args()
21
+
22
+ Version = args.Version
23
+ ControlNet = args.ControlNet
24
+
25
+ ################################################################################################################################################
26
+
27
+ import sys
28
+ import os
29
+ import base64
30
+ import importlib.util
31
+ from IPython import get_ipython
32
+ from IPython.display import clear_output
33
+ import tensorflow as tf
34
+
35
+ print("TensorFlow version:", tf.__version__)
36
+ if tf.test.gpu_device_name():
37
+ print("GPU is available")
38
+ else:
39
+ print("GPU is NOT available")
40
+ raise Exception("\n没有使用GPU,请在代码执行程序-更改运行时类型-设置为GPU!\n如果不能使用GPU,建议更换账号!")
41
+
42
+ w = base64.b64decode(("d2VidWk=").encode('ascii')).decode('ascii')
43
+ sdw = base64.b64decode(("c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==").encode('ascii')).decode('ascii')
44
+ l = base64.b64decode(("bGF1bmNo").encode('ascii')).decode('ascii')
45
+ # sdw = binascii.a2b_uu("6<W1A8FQE+61I9F9U<VEO;BUW96)U:0``").decode('utf-8')
46
+ # w = binascii.a2b_uu("%=V5B=6D`").decode('utf-8')
47
+ wb = f'/root/main'
48
+ sai = binascii.a2b_uu("=<W1A8FQE+61I9F9U<VEO;BUS=&%B:6QI='DM86D`").decode('utf-8')
49
+ sd = binascii.a2b_uu("04W1A8FQE+61I9F9U<VEO;@``").decode('utf-8')
50
+
51
+
52
+ get_ipython().run_line_magic('cd', '/content')
53
+ get_ipython().run_line_magic('env', 'TF_CPP_MIN_LOG_LEVEL=1')
54
+
55
+ # clong git
56
+ def gitDownload(url, localPath):
57
+ if os.path.exists(localPath):
58
+ return
59
+
60
+ get_ipython().system(f'git clone {url} {localPath}')
61
+
62
+
63
+ # 安装附加功能
64
+ def installAdditional():
65
+ # 安装扩展
66
+ urls = [
67
+ # f'https://github.com/camenduru/{sdw}-images-browser', # 图像浏览器
68
+ f'https://github.com/camenduru/tunnels', # Tunnel 网络支持
69
+ f'https://github.com/etherealxx/batchlinks-{w}', # 批量下载模型lora
70
+ f'https://github.com/camenduru/sd-civitai-browser', # Civitai 分类和搜索
71
+ f'https://github.com/AUTOMATIC1111/{sdw}-rembg', # 背景移除功能
72
+ f'https://github.com/thomasasfk/sd-{w}-aspect-ratio-helper', # 宽高比调整功能
73
+ f'https://github.com/hanamizuki-ai/{sdw}-localization-zh_Hans', # 中文
74
+ # f'https://github.com/nonnonstop/sd-{w}-3d-open-pose-editor', # 3D 人体姿态编辑功能
75
+ f'https://github.com/camenduru/{sdw}-catppuccin', # Catppuccin 主题
76
+ # f'https://github.com/IDEA-Research/DWPose', # cnt手部模型
77
+ f'https://github.com/Physton/sd-{w}-prompt-all-in-one', # 关键词插件
78
+ # f'https://github.com/numz/sd-wav2lip-uhq', # 语音转唇形
79
+ ]
80
+ for url in urls:
81
+
82
+ filename = url.split('/')[-1]
83
+
84
+ if 'github' in url:
85
+ get_ipython().system(f'git clone {url} {wb}/extensions/{filename}')
86
+ # 优化embeddings
87
+ get_ipython().system(f'rm -rf {wb}/embeddings/negative')
88
+ gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
89
+ get_ipython().system(f'rm -rf {wb}/embeddings/negative/.git')
90
+ get_ipython().system(f'rm {wb}/embeddings/negative/.gitattributes')
91
+
92
+ #中文插件
93
+ gitDownload(f'https://github.com/DominikDoom/a1111-sd-{w}-tagcomplete',f'{wb}/extensions/a1111-sd-{w}-tagcomplete')
94
+ get_ipython().system(f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
95
+ get_ipython().system(f'wget https://github.com/zanllp/sd-{w}-infinite-image-browsing -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
96
+ # gitDownload(f'https://github.com/toriato/{sdw}-wd14-tagger',f'{wb}/extensions/{sdw}-wd14-tagge')
97
+ #附加插件=脸部修复/漫画助手
98
+ gitDownload(f'https://github.com/Bing-su/adetailer',f'{wb}/extensions/adetailer')
99
+
100
+ # ControlNet模型
101
+ Cnt_models = [
102
+ 'control_v11e_sd15_ip2p.pth',
103
+ 'control_v11e_sd15_shuffle.pth',
104
+ 'control_v11f1e_sd15_tile.pth',
105
+ 'control_v11f1p_sd15_depth.pth',
106
+ 'control_v11p_sd15_canny.pth',
107
+ 'control_v11p_sd15_inpaint.pth',
108
+ 'control_v11p_sd15_lineart.pth',
109
+ 'control_v11p_sd15_mlsd.pth',
110
+ 'control_v11p_sd15_normalbae.pth',
111
+ 'control_v11p_sd15_openpose.pth',
112
+ 'control_v11p_sd15_scribble.pth',
113
+ 'control_v11p_sd15_seg.pth',
114
+ 'control_v11p_sd15_softedge.pth',
115
+ 'control_v11p_sd15s2_lineart_anime.pth',
116
+ ]
117
+ get_ipython().system(f'rm -rf {wb}/extensions/sd-{w}-controlnet')
118
+ # 模型下载到Colab
119
+ if ControlNet:
120
+ gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')
121
+ for v in Cnt_models:
122
+ get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{v} -d {wb}/extensions/sd-{w}-controlnet/models -o {v}')
123
+ print("启用 ControlNet")
124
+ else:
125
+ print("不启用 ControlNet")
126
+
127
+ # get_ipython().system(f'git clone https://github.com/numz/sd-wav2lip-uhq {wb}/extensions/sd-wav2lip-uhq')
128
+ # get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip.pth -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip.pth')
129
+ # get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip_gan.pth -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip_gan.pth')
130
+ # get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/s3fd-619a316812.pth -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/face_detection/detection/sfd/s3fd-619a316812.pth')
131
+ # get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/shape_predictor_68_face_landmarks.dat -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/predicator/shape_predictor_68_face_landmarks.dat')
132
+ # get_ipython().system(f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/extensions/sd-wav2lip-uhq/scripts/faceswap/model/inswapper_128.onnx')
133
+
134
+ # 初始化本地环境
135
+ def initLocal():
136
+ #部署 env 环境变量
137
+ get_ipython().system(f'apt -y update -qq')
138
+ get_ipython().system(f'wget https://huggingface.co/gmk123/colab/resolve/main/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4')
139
+ get_ipython().run_line_magic('env', f'LD_PRELOAD=/content/libtcmalloc_minimal.so.4')
140
+
141
+ #设置 python 环境
142
+ get_ipython().system(f'apt -y install -qq aria2 libcairo2-dev pkg-config python3-dev')
143
+ 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')
144
+ get_ipython().system(f'pip install -q xformers==0.0.20 triton==2.0.0 -U')
145
+
146
+ #主框架模块
147
+ if Version == "XL":
148
+ get_ipython().system(f'git clone -b master https://github.com/AUTOMATIC1111/{sdw} /root/main')
149
+
150
+ get_ipython().system(f'git -C {wb}/repositories/{sai} reset --hard')
151
+
152
+ # 安装附加功能
153
+ installAdditional()
154
+
155
+ get_ipython().system(f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')
156
+ get_ipython().system(f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')
157
+
158
+ #下载主模型
159
+ model_dir = f"{wb}/models/{sd}"
160
+
161
+ get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/ckpt/chilloutmix/resolve/main/chilloutmix_NiPrunedFp32Fix.safetensors -d {model_dir} -o chilloutmix_NiPrunedFp32Fix.safetensors')
162
+
163
+ # #VAE
164
+ 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')
165
+
166
+ #放大
167
+ 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')
168
+
169
+
170
+
171
+
172
+ # 运行
173
+ def run(script):
174
+ clear_output()
175
+ get_ipython().run_line_magic('cd', f'{wb}')
176
+ get_ipython().system(f'python {script} --cloudflared --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers --disable-console-progressbars --theme dark --cors-allow-origins=*')
177
+
178
+ # 运行脚本
179
+ if os.path.exists(f'{wb}'):
180
+ run(f'{w}.py')
181
+ else:
182
+ # 初化本地环境
183
+ initLocal()
184
+ # 运行
185
+ run(f'{l}.py')