DC / Xl.py
RenSilan's picture
Upload 5 files
4871519
import argparse
import binascii
# 自定义类型转换函数
def str_to_bool(value):
if value.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif value.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Invalid boolean value: {}'.format(value))
# 创建参数解析器
parser = argparse.ArgumentParser()
parser.add_argument('--Version', type=str)
parser.add_argument('--ControlNet', type=str_to_bool)
# 解析命令行参数
args = parser.parse_args()
Version = args.Version
ControlNet = args.ControlNet
################################################################################################################################################
import sys
import os
import base64
import importlib.util
from IPython import get_ipython
from IPython.display import clear_output
import tensorflow as tf
print("TensorFlow version:", tf.__version__)
if tf.test.gpu_device_name():
print("GPU is available")
else:
print("GPU is NOT available")
raise Exception("\n没有使用GPU,请在代码执行程序-更改运行时类型-设置为GPU!\n如果不能使用GPU,建议更换账号!")
w = base64.b64decode(("d2VidWk=").encode('ascii')).decode('ascii')
sdw = base64.b64decode(("c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==").encode('ascii')).decode('ascii')
# sdw = binascii.unhexlify("737461626c652d646966667573696f6e2d7765627569").decode('ascii')
# w = binascii.unhexlify("7765627569").decode('ascii')
wb = f'/root/main'
sd= binascii.a2b_uu("04W1A8FQE+61I9F9U<VEO;@``").decode('utf-8')
sai= binascii.a2b_uu("=<W1A8FQE+61I9F9U<VEO;BUS=&%B:6QI='DM86D`").decode('utf-8')
e = base64.b64decode(("ZXh0ZW5zaW9ucw==").encode('ascii')).decode('ascii')
get_ipython().run_line_magic('cd', '/content')
get_ipython().run_line_magic('env', 'TF_CPP_MIN_LOG_LEVEL=1')
# clong git
def gitDownload(url, localPath):
if os.path.exists(localPath):
return
get_ipython().system(f'git clone {url} {localPath}')
# 安装附加功能
def installAdditional():
# 安装扩展
urls = [
# f'https://github.com/zanllp/{w}-infinite-image-browsing', # 图像浏览器
f'https://github.com/camenduru/sd-{w}-tunnels', # Tunnel 网络支持
f'https://github.com/etherealxx/batchlinks-{w}', # 批量下载模型lora
f'https://github.com/camenduru/sd-civitai-browser', # Civitai 分类和搜索
f'https://github.com/AUTOMATIC1111/{sdw}-rembg', # 背景移除功能
f'https://github.com/thomasasfk/sd-{w}-aspect-ratio-helper', # 宽高比调整功能
f'https://github.com/hanamizuki-ai/{sdw}-localization-zh_Hans', # 中文
# f'https://github.com/nonnonstop/sd-{w}-3d-open-pose-editor', # 3D 人体姿态编辑功能
f'https://github.com/camenduru/{sdw}-catppuccin', # Catppuccin 主题
# f'https://github.com/IDEA-Research/DWPose', # cnt手部模型
f'https://github.com/Physton/sd-{w}-prompt-all-in-one', # 关键词插件
# f'https://github.com/numz/sd-wav2lip-uhq', # 语音转唇形
]
for url in urls:
filename = url.split('/')[-1]
if 'github' in url:
get_ipython().system(f'git clone {url} {wb}/{e}/{filename}')
# 优化embeddings
get_ipython().system(f'rm -rf {wb}/embeddings/negative')
gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
get_ipython().system(f'rm -rf {wb}/embeddings/negative/.git')
get_ipython().system(f'rm {wb}/embeddings/negative/.gitattributes')
#中文插件
gitDownload(f'https://github.com/DominikDoom/a1111-sd-{w}-tagcomplete',f'{wb}/{e}/a1111-sd-{w}-tagcomplete')
get_ipython().system(f'rm -f {wb}/{e}/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
get_ipython().system(f'wget https://beehomefile.oss-cn-beijing.aliyuncs.com/20210114/danbooru.csv -O {wb}/{e}/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')
# gitDownload(f'https://github.com/toriato/{sdw}-wd14-tagger',f'{wb}/{e}/{sdw}-wd14-tagge')
#附加插件=脸部修复/漫画助手
gitDownload(f'https://github.com/Bing-su/adetailer',f'{wb}/{e}/adetailer')
# ControlNet模型
Cnt_models = [
'control_v11e_sd15_ip2p.pth',
'control_v11e_sd15_shuffle.pth',
'control_v11f1e_sd15_tile.pth',
'control_v11f1p_sd15_depth.pth',
'control_v11p_sd15_canny.pth',
'control_v11p_sd15_inpaint.pth',
'control_v11p_sd15_lineart.pth',
'control_v11p_sd15_mlsd.pth',
'control_v11p_sd15_normalbae.pth',
'control_v11p_sd15_openpose.pth',
'control_v11p_sd15_scribble.pth',
'control_v11p_sd15_seg.pth',
'control_v11p_sd15_softedge.pth',
'control_v11p_sd15s2_lineart_anime.pth',
]
get_ipython().system(f'rm -rf {wb}/{e}/sd-{w}-controlnet')
# 模型下载到Colab
if ControlNet:
gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/{e}/sd-{w}-controlnet')
for v in Cnt_models:
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}/{e}/sd-{w}-controlnet/models -o {v}')
print("启用 ControlNet")
else:
print("不启用 ControlNet")
# get_ipython().system(f'git clone https://github.com/numz/sd-wav2lip-uhq {wb}/{e}/sd-wav2lip-uhq')
# get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip.pth -O {wb}/{e}/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip.pth')
# get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip_gan.pth -O {wb}/{e}/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip_gan.pth')
# get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/s3fd-619a316812.pth -O {wb}/{e}/sd-wav2lip-uhq/scripts/wav2lip/face_detection/detection/sfd/s3fd-619a316812.pth')
# get_ipython().system(f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/shape_predictor_68_face_landmarks.dat -O {wb}/{e}/sd-wav2lip-uhq/scripts/wav2lip/predicator/shape_predictor_68_face_landmarks.dat')
# get_ipython().system(f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/{e}/sd-wav2lip-uhq/scripts/faceswap/model/inswapper_128.onnx')
# 初始化本地环境
def initLocal():
#部署 env 环境变量
get_ipython().system(f'apt -y update -qq')
get_ipython().system(f'wget https://huggingface.co/gmk123/sd_config/resolve/main/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4')
get_ipython().run_line_magic('env', 'LD_PRELOAD=/content/libtcmalloc_minimal.so.4')
#设置 python 环境
get_ipython().system(f'apt -y install -qq aria2 libcairo2-dev pkg-config python3-dev')
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')
get_ipython().system(f'pip install -q xformers==0.0.20 triton==2.0.0 gradio_client==0.2.7 -U')
#主框架模块
if Version == "XL":
get_ipython().system(f'git clone -b master https://github.com/AUTOMATIC1111/{sdw} /root/main')
get_ipython().system(f'git -C {wb}/repositories/{sai} reset --hard')
# 安装附加功能
installAdditional()
# get_ipython().system(f'wget -O {wb}/config.json "https://huggingface.co/gmk123/main/raw/main/config.json"')
#下载主模型
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 {wb}/models/{sd} -o chilloutmix_NiPrunedFp32Fix.safetensors')
# #VAE
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')
#放大
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')
# 运行
def run(script):
clear_output()
get_ipython().run_line_magic('cd', f'{wb}')
get_ipython().system(f'python {script} --listen --xformers --enable-insecure-extension-access --no-download-sd-model --no-half-vae --theme dark --gradio-queue --disable-console-progressbars --multiple --api --cors-allow-origins=*')
# 运行脚本
if os.path.exists(f'{wb}'):
run('webui.py')
else:
# 初化本地环境
initLocal()
# 运行
run('launch.py')