| import argparse |
| import binascii |
| def str_to_bool (OO0OO00OO0OO00000 ): |
| if OO0OO00OO0OO00000 .lower ()in ('yes','true','t','y','1'): |
| return True |
| elif OO0OO00OO0OO00000 .lower ()in ('no','false','f','n','0'): |
| return False |
| else : |
| raise argparse .ArgumentTypeError ('Invalid boolean value: {}'.format (OO0OO00OO0OO00000 )) |
| parser =argparse .ArgumentParser () |
| parser .add_argument ('--UI',type =str ) |
| parser .add_argument ('--Version',type =str ) |
| parser .add_argument ('--ControlNet',type =str ) |
| parser .add_argument ('--Roop',type =str_to_bool ) |
| parser .add_argument ('--Drive_Map',type =str_to_bool ) |
| parser .add_argument ('--Key_words',type =str_to_bool ) |
| parser .add_argument ('--SadTalker',type =str_to_bool ) |
| parser .add_argument ('--Segment_Anything',type =str_to_bool ) |
| args =parser .parse_args () |
| UI =args .UI |
| Roop =args .Roop |
| Version =args .Version |
| ControlNet =args .ControlNet |
| Drive_Map =args .Drive_Map |
| Key_words =args .Key_words |
| Segment_Anything =args .Segment_Anything |
| SadTalker =args .SadTalker |
| import sys |
| import os |
| import json |
| import base64 |
| import importlib .util |
| from IPython import get_ipython |
| from IPython .display import clear_output |
| from google .colab import drive |
| import tensorflow as tf |
| print ("TensorFlow version:",tf .__version__ ) |
| if tf .test .gpu_device_name (): |
| drive .mount ('/content/drive') |
| else : |
| raise Exception ("\n请在《代码执行程序》-《更改运行时类型》-设置为GPU~") |
| w =base64 .b64decode (("d2VidWk=").encode ('ascii')).decode ('ascii') |
| l =base64 .b64decode (("bGF1bmNo").encode ('ascii')).decode ('ascii') |
| sdw =base64 .b64decode (("c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==").encode ('ascii')).decode ('ascii') |
| wb =f'/root/main' |
| sai =base64 .b64decode (("c3RhYmxlLWRpZmZ1c2lvbi1zdGFiaWxpdHktYWk=").encode ('ascii')).decode ('ascii') |
| sd =base64 .b64decode (("U3RhYmxlLWRpZmZ1c2lvbg==").encode ('ascii')).decode ('ascii') |
| gwb =f'/content/drive/MyDrive/SD_DATA' |
| get_ipython ().run_line_magic ('cd','/content') |
| get_ipython ().run_line_magic ('env','TF_CPP_MIN_LOG_LEVEL=1') |
| def cloudDriveSync (O000O00OOOOO000O0 ,localPath ='',sync =False ): |
| if not os .path .exists (O000O00OOOOO000O0 ): |
| get_ipython ().system (f'mkdir {O000O00OOOOO000O0}') |
| if not sync : |
| return |
| get_ipython ().system (f'rm -rf {localPath}') |
| get_ipython ().system (f'ln -s {O000O00OOOOO000O0} {localPath}') |
| def initCloudDrive (): |
| cloudDriveSync (f'{gwb}') |
| cloudDriveSync (f'{gwb}/Config') |
| cloudDriveSync (f'{gwb}/Models',f'{wb}/models/{sd}',Drive_Map ) |
| cloudDriveSync (f'{gwb}/Lora',f'{wb}/models/Lora',Drive_Map ) |
| cloudDriveSync (f'{gwb}/LyCORIS',f'{wb}/models/LyCORIS',Drive_Map ) |
| cloudDriveSync (f'{gwb}/Vae',f'{wb}/models/VAE',Drive_Map ) |
| cloudDriveSync (f'{gwb}/Outputs',f'{wb}/outputs',Drive_Map ) |
| if not os .path .exists (f'{gwb}/Config/config.json'): |
| get_ipython ().system (f'wget -O {gwb}/Config/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"') |
| if not os .path .exists (f'{gwb}/styles.csv'): |
| get_ipython ().system (f'wget -O {gwb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"') |
| def gitDownload (O00OOO0OO0OO0OOOO ,OOO00O0O0OO0OOOOO ): |
| if os .path .exists (OOO00O0O0OO0OOOOO ): |
| return |
| get_ipython ().system (f'git clone {O00OOO0OO0OO0OOOO} {OOO00O0O0OO0OOOOO}') |
| def installAdditional (): |
| O0000O0O00000OOO0 =[f'https://github.com/camenduru/{sdw}-images-browser',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/kohya-ss/sd-{w}-additional-networks',f'https://github.com/fkunn1326/openpose-editor',f'https://github.com/hnmr293/posex',f'https://github.com/s9roll7/ebsynth_utility',f'https://github.com/ashen-sensored/{sdw}-two-shot',f'https://github.com/nonnonstop/sd-{w}-3d-open-pose-editor',f'https://github.com/camenduru/{sdw}-huggingface',f'https://github.com/camenduru/{sdw}-catppuccin',f'https://github.com/IDEA-Research/DWPose',f'https://github.com/KohakuBlueleaf/a1111-sd-{w}-lycoris',f'https://github.com/Physton/sd-{w}-prompt-all-in-one',] |
| for O0OO0000OO00O00OO in O0000O0O00000OOO0 : |
| OOO00OOO00OO0OO00 =O0OO0000OO00O00OO .split ('/')[-1 ] |
| if 'github'in O0OO0000OO00O00OO : |
| get_ipython ().system (f'git clone {O0OO0000OO00O00OO} {wb}/extensions/{OOO00OOO00OO0OO00}') |
| get_ipython ().system (f'wget https://raw.githubusercontent.com/camenduru/{sdw}-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py') |
| 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') |
| get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -d {wb}/models/ESRGAN -o RealESRGAN_x4plus_anime_6B.pth') |
| 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://huggingface.co/embed/lora',f'{wb}/models/Lora/positive') |
| get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git') |
| get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes') |
| gitDownload (f'https://github.com/DominikDoom/a1111-sd-{w}-tagcomplete',f'{wb}/extensions/a1111-sd-{w}-tagcomplete') |
| get_ipython ().system (f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv') |
| get_ipython ().system (f'wget https://beehomefile.oss-cn-beijing.aliyuncs.com/20210114/danbooru.csv -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv') |
| gitDownload (f'https://github.com/toriato/{sdw}-wd14-tagger',f'{wb}/extensions/{sdw}-wd14-tagge') |
| gitDownload (f'https://github.com/Bing-su/adetailer',f'{wb}/extensions/adetailer') |
| gitDownload (f'https://github.com/antfu/sd-{w}-qrcode-toolkit',f'{wb}/extensions/sd-{w}-qrcode-toolkit') |
| gitDownload (f'https://github.com/yankooliveira/sd-{w}-photopea-embed',f'{wb}/extensions/sd-{w}-photopea-embed') |
| gitDownload (f'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',f'{wb}/extensions/multidiffusion-upscaler-for-automatic1111') |
| if Roop : |
| gitDownload (f'https://github.com/Gourieff/sd-{w}-reactor',f'{wb}/extensions/sd-{w}-reactor') |
| print ('Roop换脸启用') |
| else : |
| print ('Roop换脸不启用') |
| O0000O00000OO00OO =['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}/extensions/sd-{w}-controlnet') |
| if ControlNet =="Colab": |
| gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet') |
| for O0O00000O0OO00O0O in O0000O00000OO00OO : |
| 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/{O0O00000O0OO00O0O} -d {wb}/extensions/sd-{w}-controlnet/models -o {O0O00000O0OO00O0O}') |
| elif ControlNet =="Google_Drive": |
| cloudDriveSync (f'{gwb}/CntModels') |
| gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet') |
| for O0O00000O0OO00O0O in O0000O00000OO00OO : |
| if not os .path .exists (f'{gwb}/CntModels/{O0O00000O0OO00O0O}'): |
| 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/{O0O00000O0OO00O0O} -d {gwb}/CntModels -o {O0O00000O0OO00O0O}') |
| print ("创建扩展",f'{O0O00000O0OO00O0O}') |
| else : |
| print ("扩展存在",f'{O0O00000O0OO00O0O}') |
| for O0O00000O0OO00O0O in os .listdir (f'{gwb}/CntModels'): |
| get_ipython ().system (f'ln -s {gwb}/CntModels/{O0O00000O0OO00O0O} {wb}/extensions/sd-{w}-controlnet/models') |
| elif ControlNet =="No": |
| print ("不使用 ControlNet") |
| if UI =="Kitchen_Ui": |
| gitDownload (f'https://github.com/canisminor1990/sd-{w}-kitchen-theme-legacy',f'{wb}/extensions/sd-{w}-kitchen-theme-legacy') |
| print ("Kitchen界面插件启用") |
| elif UI =="Lobe_Ui": |
| gitDownload (f'https://github.com/canisminor1990/sd-web-ui-kitchen-theme',f'{wb}/extensions/sd-web-ui-kitchen-theme') |
| print ("Lobe界面插件启用") |
| elif UI =="No": |
| print ("UI插件不启用") |
| if Key_words : |
| cloudDriveSync (f'{gwb}/Storage',f'{wb}/extensions/sd-{w}-prompt-all-in-one/storage',Drive_Map ) |
| print ("关键词插件启用") |
| else : |
| get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-prompt-all-in-one') |
| print ("关键词插件不启用") |
| if SadTalker : |
| if not os .path .exists (f'{wb}/extensions/SadTalker'): |
| get_ipython ().system (f'git clone https://github.com/OpenTalker/SadTalker {wb}/extensions/SadTalker') |
| get_ipython ().system (f'git -C {wb}/extensions/SadTalker clone https://huggingface.co/gmk123/checkpoints') |
| get_ipython ().system (f'git -C {wb}/models clone https://huggingface.co/gmk123/GFPGAN') |
| get_ipython ().system (f'git clone https://github.com/numz/sd-wav2lip-uhq {wb}/extensions/sd-wav2lip-uhq') |
| 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') |
| 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') |
| 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') |
| 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') |
| 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') |
| print ("SadTalker启用") |
| else : |
| get_ipython ().system (f'rm -rf {wb}/extensions/SadTalker') |
| print ("SadTalker不启用") |
| if Segment_Anything : |
| get_ipython ().system (f'git clone https://github.com/continue-revolution/sd-{w}-segment-anything {wb}/extensions/sd-{w}-segment-anything') |
| get_ipython ().system (f'wget https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth -O {wb}/extensions/sd-{w}-segment-anything/models/sam/sam_vit_l_0b3195.pth') |
| get_ipython ().system (f'wget https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth -O {wb}/extensions/sd-{w}-segment-anything/models/grounding-dino/groundingdino_swinb_cogcoor.pth') |
| print ("智能抠图插件启用") |
| else : |
| get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-segment-anything') |
| print ("智能抠图插件不启用") |
| def initLocal (): |
| get_ipython ().system (f'apt -y update -qq') |
| get_ipython ().system (f'wget https://huggingface.co/gmk123/colab/resolve/main/libtcmalloc_minimal.so.4 -O /content/libtcmalloc_minimal.so.4') |
| get_ipython ().run_line_magic ('env',f'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 -U') |
| if Version =="A1111": |
| get_ipython ().system (f'git clone -b v2.5 https://github.com/camenduru/{sdw} {wb}') |
| elif Version =="V2.5": |
| get_ipython ().system (f'git clone -b v2.5 https://github.com/camenduru/{sdw} {wb}') |
| elif Version =="V2.4": |
| get_ipython ().system (f'git clone -b v2.4 https://github.com/camenduru/{sdw} {wb}') |
| get_ipython ().system (f'git -C {wb}/repositories/{sai} reset --hard') |
| initCloudDrive () |
| installAdditional () |
| get_ipython ().system (f'rm -f {wb}/config.json') |
| get_ipython ().system (f'ln -s {gwb}/Config/config.json {wb}/config.json') |
| if os .path .exists (f"{gwb}/styles.csv"): |
| get_ipython ().system (f'ln -s {gwb}/styles.csv {wb}/styles.csv') |
| if os .path .exists (f"{wb}/extensions/sd-{w}-additional-networks"): |
| cloudDriveSync (f'{gwb}/Lora',f'{wb}/extensions/sd-{w}-additional-networks/models/lora',Drive_Map ) |
| if len (os .listdir (f"{gwb}/Models"))==0 : |
| 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') |
| if len (os .listdir (f"{gwb}/Vae"))==0 : |
| 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') |
| O00O0000O00OO00OO =os .path .join (wb ,"models",sd ) |
| if any (O0O0OOOOOO0OO0O00 .endswith (('.ckpt','.safetensors'))for O0O0OOOOOO0OO0O00 in os .listdir (O00O0000O00OO00OO )): |
| get_ipython ().system (f'sed -i \'s@weight_load_location =.*@weight_load_location = "cuda"@\' {wb}/modules/shared.py') |
| get_ipython ().system (f'sed -i "s@os.path.splitext(model_file)@os.path.splitext(model_file); map_location=\'cuda\'@" {wb}/modules/sd_models.py') |
| get_ipython ().system (f'sed -i "s@map_location=\'cpu\'@map_location=\'cuda\'@" {wb}/modules/extras.py') |
| get_ipython ().system (f"sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' {wb}/{w}.py") |
| def run (O0000OOO000OOOOOO ): |
| clear_output () |
| get_ipython ().run_line_magic ('cd',f'{wb}') |
| get_ipython ().system (f'python {O0000OOO000OOOOOO} --share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers --disable-console-progressbars --theme dark --cors-allow-origins=*') |
| if os .path .exists (f'{wb}'): |
| run (f'{w}.py') |
| else : |
| initLocal () |
| run (f'{l}.py') |