|
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') |
|
|
|
|
|
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') |
|
|
|
|
|
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/camenduru/sd-{w}-tunnels', |
|
f'https://github.com/etherealxx/batchlinks-{w}', |
|
f'https://github.com/camenduru/sd-civitai-browser', |
|
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/camenduru/{sdw}-catppuccin', |
|
|
|
f'https://github.com/Physton/sd-{w}-prompt-all-in-one', |
|
|
|
] |
|
for url in urls: |
|
|
|
filename = url.split('/')[-1] |
|
|
|
if 'github' in url: |
|
get_ipython().system(f'git clone {url} {wb}/{e}/{filename}') |
|
|
|
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/Bing-su/adetailer',f'{wb}/{e}/adetailer') |
|
|
|
|
|
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') |
|
|
|
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") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def initLocal(): |
|
|
|
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') |
|
|
|
|
|
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'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') |
|
|
|
|
|
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') |