Instructions to use gmk123/colab with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use gmk123/colab with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("gmk123/colab", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update run.py
Browse files123456789101112133 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224import argparse #line:1import binascii #line:2import ipywidgets as widgets #line:3def str_to_bool (O0000OOO0OO0OO0OO ):#line:7if O0000OOO0OO0OO0OO .lower ()in ('yes','true','t','y','1'):#line:8return True #line:9elif O0000OOO0OO0OO0OO .lower ()in ('no','false','f','n','0'):#line:10return False #line:11else :#line:12raise argparse .ArgumentTypeError ('Invalid boolean value: {}'.format (O0000OOO0OO0OO0OO ))#line:13parser =argparse .ArgumentParser ()#line:16parser .add_argument ('--Animatediff',type =str_to_bool )#line:18parser .add_argument ('--ControlNet',type =str )#line:193 unmodified linesparser .add_argument ('--SadTalker',type =str_to_bool )#line:23parser .add_argument ('--Segment_Anything',type =str_to_bool )#line:24args =parser .parse_args ()#line:27Animatediff =args .Animatediff #line:30Roop =args .Roop #line:31ControlNet =args .ControlNet #line:32Drive_Map =args .Drive_Map #line:33Key_words =args .Key_words #line:34Segment_Anything =args .Segment_Anything #line:35SadTalker =args .SadTalker #line:36import sys #line:40import os #line:41import json #line:42import base64 #line:43import importlib .util #line:44from IPython import get_ipython #line:45from IPython .utils import capture #line:46from IPython .display import clear_output #line:47from google .colab import drive #line:48import tensorflow as tf #line:49print ("TensorFlow version:",tf .__version__ )#line:52if tf .test .gpu_device_name ():#line:53drive .mount ('/content/drive')#line:54else :#line:55raise Exception ("\n请在《代码执行程序》-《更改运行时类型》-设置为GPU~")#line:56w =base64 .b64decode (("d2VidWk=").encode ('ascii')).decode ('ascii')#line:58l =base64 .b64decode (("bGF1bmNo").encode ('ascii')).decode ('ascii')#line:59sdw =base64 .b64decode (("c3RhYmxlLWRpZmZ1c2lvbi13ZWJ1aQ==").encode ('ascii')).decode ('ascii')#line:60wb =f'/root/main'#line:63sai =base64 .b64decode (("c3RhYmxlLWRpZmZ1c2lvbi1zdGFiaWxpdHktYWk=").encode ('ascii')).decode ('ascii')#line:64sd =base64 .b64decode (("U3RhYmxlLWRpZmZ1c2lvbg==").encode ('ascii')).decode ('ascii')#line:65gwb =f'/content/drive/MyDrive/SD_DATA'#line:66def cloudDriveSync (O00O000OO000OO000 ,O0000000O0O00OO0O ='',O0OOOO0OO000OOO00 =False ):#line:70if not os .path .exists (O00O000OO000OO000 ):#line:72get_ipython ().system (f'mkdir {O00O000OO000OO000}')#line:74if not O0OOOO0OO000OOO00 :#line:77return #line:78get_ipython ().system (f'rm -rf {O0000000O0O00OO0O}')#line:81get_ipython ().system (f'ln -s {O00O000OO000OO000} {O0000000O0O00OO0O}')#line:83def initCloudDrive ():#line:86cloudDriveSync (f'{gwb}')#line:87cloudDriveSync (f'{gwb}/Config')#line:88cloudDriveSync (f'{gwb}/Models',f'{wb}/models/{sd}',Drive_Map )#line:89cloudDriveSync (f'{gwb}/Lora',f'{wb}/models/Lora',Drive_Map )#line:90cloudDriveSync (f'{gwb}/Vae',f'{wb}/models/VAE',Drive_Map )#line:91cloudDriveSync (f'{gwb}/Outputs',f'{wb}/outputs',Drive_Map )#line:92cloudDriveSync (f'{gwb}/embeddings',f'{wb}/embeddings',Drive_Map )#line:93cloudDriveSync (f'{gwb}/hypernetworks',f'{wb}/models/hypernetworks',Drive_Map )#line:94if not os .path .exists (f'{gwb}/Config/config.json'):#line:98get_ipython ().system (f'wget -O {gwb}/Config/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:99if not os .path .exists (f'{gwb}/styles.csv'):#line:101get_ipython ().system (f'wget -O {gwb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:103def gitDownload (O00OOO00OO0O00O00 ,OOO00OO0O0OO0000O ):#line:106if os .path .exists (OOO00OO0O0OO0000O ):#line:107return #line:108get_ipython ().system (f'git clone {O00OOO00OO0O00O00} {OOO00OO0O0OO0000O}')#line:110def installAdditional ():#line:113O00OOO0OOOOO0OOOO =[f'https://github.com/AlUlkesh/{sdw}-images-browser',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/nonnonstop/sd-{w}-3d-open-pose-editor',f'https://github.com/IDEA-Research/DWPose',f'https://github.com/Physton/sd-{w}-prompt-all-in-one',f'https://github.com/adieyal/sd-dynamic-prompts',f'https://github.com/Bing-su/adetailer',f'https://github.com/Tencent/LightDiffusionFlow',f'https://github.com/picobyte/{sdw}-wd14-tagger',f'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',]#line:152for OO000O0OOOOO0O00O in O00OOO0OOOOO0OOOO :#line:153OOO0O0OO0OOOOOO00 =OO000O0OOOOO0O00O .split ('/')[-1 ]#line:155if 'github'in OO000O0OOOOO0O00O :#line:157get_ipython ().system (f'git clone {OO000O0OOOOO0O00O} {wb}/extensions/{OOO0O0OO0OOOOOO00}')#line:158cloudDriveSync (f'{gwb}/prompts',f'{wb}/extensions/sd-dynamic-prompts/wildcards',Drive_Map )#line:160get_ipython ().system (f'wget https://raw.githubusercontent.com/camenduru/{sdw}-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')#line:161get_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:162get_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')#line:163gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:167get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:168get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:169gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:171get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:172get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:173gitDownload (f'https://github.com/DominikDoom/a1111-sd-{w}-tagcomplete',f'{wb}/extensions/a1111-sd-{w}-tagcomplete')#line:176get_ipython ().system (f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')#line:177get_ipython ().system (f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')#line:178if Roop :#line:181gitDownload (f'https://github.com/s9roll7/ebsynth_utility',f'{wb}/extensions/ebsynth_utility')#line:183gitDownload (f'https://github.com/aigc-apps/sd-{w}-EasyPhoto',f'{wb}/extensions/sd-{w}-EasyPhoto')#line:184get_ipython ().system (f'pip install transparent-background color-matcher')#line:185get_ipython ().system (f'pip install fake_useragent')#line:186get_ipython ().system (f'pip install modelscope')#line:187gitDownload (f'https://github.com/s0md3v/sd-{w}-roop',f'{wb}/extensions/sd-{w}-roop')#line:189get_ipython ().system (f'pip install insightface==0.7.3')#line:190get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:191get_ipython ().system (f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')#line:192print ('Roop换脸启用')#line:193else :#line:194print ('Roop换脸不启用')#line:195O0000O0OO0O000000 =['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',]#line:213get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-controlnet')#line:214if ControlNet =="Colab":#line:216gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')#line:217for OOOO0OO0O0O000O0O in O0000O0OO0O000000 :#line:218get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{OOOO0OO0O0O000O0O} -d {wb}/extensions/sd-{w}-controlnet/models -o {v}')#line:219elif ControlNet =="Google_Drive":#line:222cloudDriveSync (f'{gwb}/CntModels')#line:223gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')#line:224for OOOO0OO0O0O000O0O in O0000O0OO0O000000 :#line:225if not os .path .exists (f'{gwb}/CntModels/{OOOO0OO0O0O000O0O}'):#line:226get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{OOOO0OO0O0O000O0O} -d {gwb}/CntModels -o {v}')#line:227print ("创建扩展",f'{OOOO0OO0O0O000O0O}')#line:228else :#line:229print ("扩展存在",f'{OOOO0OO0O0O000O0O}')#line:230for OOOO0OO0O0O000O0O in os .listdir (f'{gwb}/CntModels'):#line:232get_ipython ().system (f'ln -s {gwb}/CntModels/{OOOO0OO0O0O000O0O} {wb}/extensions/sd-{w}-controlnet/models')#line:234elif ControlNet =="No":#line:236print ("不使用 ControlNet")#line:237if Animatediff :#line:240gitDownload (f'https://github.com/continue-revolution/sd-{w}-animatediff',f'{wb}/extensions/sd-{w}-animatediff')#line:241get_ipython ().system (f'pip install pyav==11.4.1')#line:242gitDownload (f'https://github.com/deforum-art/sd-{w}-deforum',f'{wb}/extensions/sd-{w}-deforum')#line:244get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/lora/mm_sd15_v3_adapter.safetensors -d {wb}/models/Lora -o mm_sd15_v3_adapter.safetensors')#line:246get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v2.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sd15_v2.safetensors')#line:247get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v3.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sd15_v3.safetensors')#line:248get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sdxl_v10_beta.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sdxl_v10_beta.safetensors')#line:249print ("Animatediff动画制作插件启用")#line:250else :#line:251get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-animatediff')#line:252print ("Animatediff动画制作插件不启用")#line:253if Key_words :#line:256cloudDriveSync (f'{gwb}/Storage',f'{wb}/extensions/sd-{w}-prompt-all-in-one/storage',Drive_Map )#line:257print ("关键词插件启用")#line:258else :#line:259get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-prompt-all-in-one')#line:260print ("关键词插件不启用")#line:261if SadTalker :#line:264get_ipython ().system (f'git clone https://github.com/numz/sd-wav2lip-uhq {wb}/extensions/sd-wav2lip-uhq')#line:270get_ipython ().system (f'pip install bark')#line:271get_ipython ().system (f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip.pth -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip.pth')#line:272get_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')#line:273get_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')#line:274get_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')#line:275get_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')#line:276print ("数字人插件启用")#line:278else :#line:279get_ipython ().system (f'rm -rf {wb}/extensions/sd-wav2lip-uhq')#line:280print ("数字人插件不启用")#line:281if Segment_Anything :#line:284get_ipython ().system (f'git clone https://github.com/continue-revolution/sd-{w}-segment-anything {wb}/extensions/sd-{w}-segment-anything')#line:285get_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')#line:288get_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')#line:289print ("智能抠图插件启用")#line:291else :#line:292get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-segment-anything')#line:293print ("智能抠图插件不启用")#line:294def initLocal ():#line:297get_ipython ().system ('apt -y install -qq aria2 git')#line:299get_ipython ().system (f'pip install lmdb')#line:301get_ipython ().system (f'pip install torch==2.2.1+cu121 torchvision==0.17.0+cu121 torchaudio==2.2.1+cu121 torchtext==0.17.0+cpu torchdata==0.7.0 --index-url https://download.pytorch.org/whl/cu121')#line:303get_ipython ().system (f'pip install xformers==0.0.23.post1')#line:304get_ipython ().run_line_magic ('cd','/content')#line:305get_ipython ().system (f'pip install -q basicsr')#line:306with capture .capture_output ()as O0OO0OO0000O0OO00 :#line:308def OO000O0OO00OOO00O (O00O00000OO00O00O ,OOO00OO0OO00OO000 ,O0OOO00OOOOO0O0O0 ):OO000O000O000OOOO =widgets .Button (description =O00O00000OO00O00O ,disabled =True ,button_style =OOO00OO0OO00OO000 ,layout =widgets .Layout (min_width =O0OOO00OOOOO0O0O0 ));display (OO000O000O000OOOO )#line:309get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/{sdw} /root/main')#line:311with capture .capture_output ()as O0OO0OO0000O0OO00 :#line:312get_ipython ().run_line_magic ('cd',f'{wb}')#line:313get_ipython ().system ('pip install -q -r requirements.txt')#line:315with capture .capture_output ()as O0OO0OO0000O0OO00 :#line:316get_ipython ().run_line_magic ('cd','/content')#line:317get_ipython ().system (f'mkdir -p {wb}/repositories/{sai}')#line:319get_ipython ().system ('wget -q -i https://huggingface.co/gmk123/run/raw/main/A1111.txt')#line:320get_ipython ().system ('dpkg -i *.deb')#line:321get_ipython ().system ('tar -C /content/ --zstd -xf sd_mrep.tar.zst')#line:322get_ipython ().system ('tar -C / --zstd -xf gcolabdeps.tar.zst')#line:323get_ipython ().system ('rm *.deb | rm *.zst | rm *.txt')#line:324get_ipython ().system (f'mv -n /content/sd/stablediffusion/* {wb}/repositories/{sai} && rm -rf /content/sd')#line:325os .environ ['TF_CPP_MIN_LOG_LEVEL']='3'#line:326os .environ ['PYTHONWARNINGS']='ignore'#line:327get_ipython ().system ('sed -i \'s@text = _formatwarnmsg(msg)@text =\"\"@g\' /usr/lib/python3.10/warnings.py')#line:328get_ipython ().system ('apt --fix-broken install')#line:330get_ipython ().system (f'pip install --force-reinstall charset-normalizer==3.1.0')#line:331get_ipython ().system (f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')#line:332get_ipython ().system (f'pip install -U dynamicprompts[attentiongrabber,magicprompt]')#line:334get_ipython ().system (f'git -C {wb}/repositories/{sai} reset --hard')#line:336initCloudDrive ()#line:341installAdditional ()#line:344clear_output ()#line:346get_ipython ().system (f'rm -f {wb}/config.json')#line:348get_ipython ().system (f'ln -s {gwb}/Config/config.json {wb}/config.json')#line:349if os .path .exists (f"{gwb}/styles.csv"):#line:352get_ipython ().system (f'ln -s {gwb}/styles.csv {wb}/styles.csv')#line:353if os .path .exists (f"{wb}/extensions/sd-{w}-additional-networks"):#line:356cloudDriveSync (f'{gwb}/Lora',f'{wb}/extensions/sd-{w}-additional-networks/models/lora',Drive_Map )#line:357if len (os .listdir (f"{gwb}/Models"))==0 :#line:360get_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')#line:362if len (os .listdir (f"{gwb}/Vae"))==0 :#line:365get_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:367get_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:370get_ipython ().run_line_magic ('cd',f'{wb}/modules')#line:374get_ipython ().system ('wget -q -O extras.py https://huggingface.co/gmk123/run/raw/main/extras.py')#line:375get_ipython ().system ('wget -q -O sd_models.py https://huggingface.co/gmk123/run/raw/main/sd_models.py')#line:376get_ipython ().system ('wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://huggingface.co/gmk123/run/raw/main/blocks.py')#line:377get_ipython ().run_line_magic ('cd',f'{wb}')#line:379get_ipython ().system (f'sed -i \'s@print(\\"No module.*@@\' {wb}/repositories/{sai}/ldm/modules/diffusionmodules/model.py')#line:380get_ipython ().system (f'sed -i \'s@\\["sd_model_checkpoint"\\]@\\["sd_model_checkpoint", "sd_vae", "CLIP_stop_at_last_layers", "inpainting_mask_weight", "initial_noise_multiplier"\\]@g\' {wb}/modules/shared.py')#line:381get_ipython ().system (f'sed -i \'s@possible_sd_paths =.*@possible_sd_paths = [\"{wb}/repositories/{sai}\"]@\' {wb}/modules/paths.py')#line:383get_ipython ().system (f'sed -i \'s@\\.\\.\\/@src/@g\' {wb}/modules/paths.py')#line:384get_ipython ().system (f'sed -i \'s@src/generative-models@generative-models@g\' {wb}/modules/paths.py')#line:385def run (OO0O0OOO000OOO000 ):#line:389clear_output ()#line:390get_ipython ().run_line_magic ('cd',f'{wb}')#line:391get_ipython ().system (f'python {OO0O0OOO000OOO000} --share --api --disable-safe-unpickle --enable-insecure-extension-access --xformers --disable-console-progressbars --theme dark --upcast-sampling --cors-allow-origins=*')#line:392if os .path .exists (f'{wb}'):#line:395run (f'{w}.py')#line:396else :#line:397initLocal ()#line:399run (f'{w}.py')123456789101112133 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220import argparse #line:1import binascii #line:2import ipywidgets as widgets #line:3def str_to_bool (OO0O0O0000OO0O000 ):#line:7if OO0O0O0000OO0O000 .lower ()in ('yes','true','t','y','1'):#line:8return True #line:9elif OO0O0O0000OO0O000 .lower ()in ('no','false','f','n','0'):#line:10return False #line:11else :#line:12raise argparse .ArgumentTypeError ('Invalid boolean value: {}'.format (OO0O0O0000OO0O000 ))#line:13parser =argparse .ArgumentParser ()#line:16parser .add_argument ('--Animatediff',type =str_to_bool )#line:18parser .add_argument ('--ControlNet',type =str )#line:193 unmodified linesparser .add_argument ('--SadTalker',type =str_to_bool )#line:23parser .add_argument ('--Segment_Anything',type =str_to_bool )#line:24args =parser .parse_args ()#line:27Animatediff =args .Animatediff #line:29Roop =args .Roop #line:30ControlNet =args .ControlNet #line:31Drive_Map =args .Drive_Map #line:32Key_words =args .Key_words #line:33Segment_Anything =args .Segment_Anything #line:34SadTalker =args .SadTalker #line:35import sys #line:39import os #line:40import json #line:41import base64 #line:42import importlib .util #line:43from IPython import get_ipython #line:44from IPython .utils import capture #line:45from IPython .display import clear_output #line:46from google .colab import drive #line:47import tensorflow as tf #line:48print ("TensorFlow version:",tf .__version__ )#line:51if tf .test .gpu_device_name ():#line:52drive .mount ('/content/drive')#line:53else :#line:54raise Exception ("\n请在《代码执行程序》-《更改运行时类型》-设置为GPU~")#line:55w =binascii .unhexlify ("7765627569").decode ('ascii')#line:57sdw =binascii .unhexlify ("737461626c652d646966667573696f6e2d7765627569").decode ('ascii')#line:58wb =f'/root/main'#line:59sai =binascii .unhexlify ("737461626c652d646966667573696f6e2d73746162696c6974792d6169").decode ('ascii')#line:60sd =binascii .unhexlify ("537461626c652d646966667573696f6e").decode ('ascii')#line:61gwb =f'/content/drive/MyDrive/SD_DATA'#line:62def cloudDriveSync (OO0OO0OO00OO00OOO ,O0OOOOOO000OO0OOO ='',O00O0000OOO0O00OO =False ):#line:66if not os .path .exists (OO0OO0OO00OO00OOO ):#line:68get_ipython ().system (f'mkdir {OO0OO0OO00OO00OOO}')#line:70if not O00O0000OOO0O00OO :#line:73return #line:74get_ipython ().system (f'rm -rf {O0OOOOOO000OO0OOO}')#line:77get_ipython ().system (f'ln -s {OO0OO0OO00OO00OOO} {O0OOOOOO000OO0OOO}')#line:79def initCloudDrive ():#line:82cloudDriveSync (f'{gwb}')#line:83cloudDriveSync (f'{gwb}/Config')#line:84cloudDriveSync (f'{gwb}/Models',f'{wb}/models/{sd}',Drive_Map )#line:85cloudDriveSync (f'{gwb}/Lora',f'{wb}/models/Lora',Drive_Map )#line:86cloudDriveSync (f'{gwb}/Vae',f'{wb}/models/VAE',Drive_Map )#line:87cloudDriveSync (f'{gwb}/Outputs',f'{wb}/outputs',Drive_Map )#line:88cloudDriveSync (f'{gwb}/embeddings',f'{wb}/embeddings',Drive_Map )#line:89cloudDriveSync (f'{gwb}/hypernetworks',f'{wb}/models/hypernetworks',Drive_Map )#line:90if not os .path .exists (f'{gwb}/Config/config.json'):#line:94get_ipython ().system (f'wget -O {gwb}/Config/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:95if not os .path .exists (f'{gwb}/styles.csv'):#line:97get_ipython ().system (f'wget -O {gwb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:99def gitDownload (OOOOO0OOO000OOOO0 ,O0OO0OO0OO0O0000O ):#line:102if os .path .exists (O0OO0OO0OO0O0000O ):#line:103return #line:104get_ipython ().system (f'git clone {OOOOO0OOO000OOOO0} {O0OO0OO0OO0O0000O}')#line:106def installAdditional ():#line:109O0O00O000O000O0O0 =[f'https://github.com/AlUlkesh/{sdw}-images-browser',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/nonnonstop/sd-{w}-3d-open-pose-editor',f'https://github.com/IDEA-Research/DWPose',f'https://github.com/Physton/sd-{w}-prompt-all-in-one',f'https://github.com/adieyal/sd-dynamic-prompts',f'https://github.com/Bing-su/adetailer',f'https://github.com/Tencent/LightDiffusionFlow',f'https://github.com/picobyte/{sdw}-wd14-tagger',f'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',]#line:148for OO0OO0O00OOO00OO0 in O0O00O000O000O0O0 :#line:149O00OO00OO0OO0O000 =OO0OO0O00OOO00OO0 .split ('/')[-1 ]#line:151if 'github'in OO0OO0O00OOO00OO0 :#line:153get_ipython ().system (f'git clone {OO0OO0O00OOO00OO0} {wb}/extensions/{O00OO00OO0OO0O000}')#line:154cloudDriveSync (f'{gwb}/prompts',f'{wb}/extensions/sd-dynamic-prompts/wildcards',Drive_Map )#line:156get_ipython ().system (f'wget https://raw.githubusercontent.com/camenduru/{sdw}-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')#line:157get_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:158get_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')#line:159gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:163get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:164get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:165gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:167get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:168get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:169gitDownload (f'https://github.com/DominikDoom/a1111-sd-{w}-tagcomplete',f'{wb}/extensions/a1111-sd-{w}-tagcomplete')#line:172get_ipython ().system (f'rm -f {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')#line:173get_ipython ().system (f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-{w}-tagcomplete/tags/danbooru.csv')#line:174if Roop :#line:177gitDownload (f'https://github.com/s9roll7/ebsynth_utility',f'{wb}/extensions/ebsynth_utility')#line:179gitDownload (f'https://github.com/aigc-apps/sd-{w}-EasyPhoto',f'{wb}/extensions/sd-{w}-EasyPhoto')#line:180get_ipython ().system (f'pip install transparent-background color-matcher')#line:181get_ipython ().system (f'pip install modelscope')#line:182gitDownload (f'https://github.com/s0md3v/sd-{w}-roop',f'{wb}/extensions/sd-{w}-roop')#line:184get_ipython ().system (f'pip install insightface==0.7.3')#line:185get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:186get_ipython ().system (f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')#line:187print ('Roop换脸启用')#line:188else :#line:189print ('Roop换脸不启用')#line:190OO0OO0OO0O0O00O0O =['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',]#line:208get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-controlnet')#line:209if ControlNet =="Colab":#line:211gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')#line:212for O000O000OO0OO0O00 in OO0OO0OO0O0O00O0O :#line:213get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{O000O000OO0OO0O00} -d {wb}/extensions/sd-{w}-controlnet/models -o {O000O000OO0OO0O00}')#line:214elif ControlNet =="Google_Drive":#line:217cloudDriveSync (f'{gwb}/CntModels')#line:218gitDownload (f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/sd-{w}-controlnet')#line:219for O000O000OO0OO0O00 in OO0OO0OO0O0O00O0O :#line:220if not os .path .exists (f'{gwb}/CntModels/{O000O000OO0OO0O00}'):#line:221get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/{O000O000OO0OO0O00} -d {gwb}/CntModels -o {O000O000OO0OO0O00}')#line:222print ("创建扩展",f'{O000O000OO0OO0O00}')#line:223else :#line:224print ("扩展存在",f'{O000O000OO0OO0O00}')#line:225for O000O000OO0OO0O00 in os .listdir (f'{gwb}/CntModels'):#line:227get_ipython ().system (f'ln -s {gwb}/CntModels/{O000O000OO0OO0O00} {wb}/extensions/sd-{w}-controlnet/models')#line:229elif ControlNet =="No":#line:231print ("不使用 ControlNet")#line:232if Animatediff :#line:235gitDownload (f'https://github.com/continue-revolution/sd-{w}-animatediff',f'{wb}/extensions/sd-{w}-animatediff')#line:236get_ipython ().system (f'pip install pyav==11.4.1')#line:237gitDownload (f'https://github.com/deforum-art/sd-{w}-deforum',f'{wb}/extensions/sd-{w}-deforum')#line:239get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/lora/mm_sd15_v3_adapter.safetensors -d {wb}/models/Lora -o mm_sd15_v3_adapter.safetensors')#line:241get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v2.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sd15_v2.safetensors')#line:242get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v3.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sd15_v3.safetensors')#line:243get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sdxl_v10_beta.safetensors -d {wb}/extensions/sd-{w}-animatediff/model -o mm_sdxl_v10_beta.safetensors')#line:244print ("Animatediff动画制作插件启用")#line:245else :#line:246get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-animatediff')#line:247print ("Animatediff动画制作插件不启用")#line:248if Key_words :#line:251cloudDriveSync (f'{gwb}/Storage',f'{wb}/extensions/sd-{w}-prompt-all-in-one/storage',Drive_Map )#line:252print ("关键词插件启用")#line:253else :#line:254get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-prompt-all-in-one')#line:255print ("关键词插件不启用")#line:256if SadTalker :#line:259get_ipython ().system (f'git clone https://github.com/numz/sd-wav2lip-uhq {wb}/extensions/sd-wav2lip-uhq')#line:265get_ipython ().system (f'pip install bark')#line:266get_ipython ().system (f'wget https://huggingface.co/gmk123/wav2lip/resolve/main/wav2lip.pth -O {wb}/extensions/sd-wav2lip-uhq/scripts/wav2lip/checkpoints/wav2lip.pth')#line:267get_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')#line:268get_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')#line:269get_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')#line:270get_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')#line:271print ("数字人插件启用")#line:273else :#line:274get_ipython ().system (f'rm -rf {wb}/extensions/sd-wav2lip-uhq')#line:275print ("数字人插件不启用")#line:276if Segment_Anything :#line:279get_ipython ().system (f'git clone https://github.com/continue-revolution/sd-{w}-segment-anything {wb}/extensions/sd-{w}-segment-anything')#line:280get_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')#line:283get_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')#line:284print ("智能抠图插件启用")#line:286else :#line:287get_ipython ().system (f'rm -rf {wb}/extensions/sd-{w}-segment-anything')#line:288print ("智能抠图插件不启用")#line:289def initLocal ():#line:292get_ipython ().system ('apt -y install -qq aria2 git')#line:294get_ipython ().system (f'pip install lmdb')#line:296get_ipython ().system (f'pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 torchaudio==2.1.0 torchtext==0.16.0+cpu torchdata==0.7.0 --index-url https://download.pytorch.org/whl/cu121')#line:297get_ipython ().system (f'pip install xformers==0.0.23.post1')#line:298get_ipython ().run_line_magic ('cd','/content')#line:299with capture .capture_output ()as O000000OO0O00O0O0 :#line:301def O00OO00OO00O000OO (O0000OO0000OOO000 ,O000O0000OO00O0OO ,OOOO0OOO00O0O0O0O ):OO00O0OO000O000OO =widgets .Button (description =O0000OO0000OOO000 ,disabled =True ,button_style =O000O0000OO00O0OO ,layout =widgets .Layout (min_width =OOOO0OOO00O0O0O0O ));display (OO00O0OO000O000OO )#line:302get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/{sdw} /root/main')#line:304with capture .capture_output ()as O000000OO0O00O0O0 :#line:306get_ipython ().run_line_magic ('cd','/content')#line:307get_ipython ().system (f'mkdir -p {wb}/repositories/{sai}')#line:309get_ipython ().system ('wget -q -i https://huggingface.co/gmk123/run/raw/main/A1111.txt')#line:310get_ipython ().system ('dpkg -i *.deb')#line:311get_ipython ().system ('tar -C /content/ --zstd -xf sd_mrep.tar.zst')#line:312get_ipython ().system ('tar -C / --zstd -xf gcolabdeps.tar.zst')#line:313get_ipython ().system ('rm *.deb | rm *.zst | rm *.txt')#line:314get_ipython ().system (f'mv -n /content/sd/stablediffusion/* {wb}/repositories/{sai} && rm -rf /content/sd')#line:315os .environ ['TF_CPP_MIN_LOG_LEVEL']='3'#line:316os .environ ['PYTHONWARNINGS']='ignore'#line:317get_ipython ().system ('sed -i \'s@text = _formatwarnmsg(msg)@text =\"\"@g\' /usr/lib/python3.10/warnings.py')#line:318get_ipython ().system ('apt --fix-broken install')#line:320get_ipython ().system (f'pip install --force-reinstall charset-normalizer==3.1.0')#line:322get_ipython ().system (f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')#line:323get_ipython ().system (f'pip install -U dynamicprompts[attentiongrabber,magicprompt]')#line:325get_ipython ().system (f'pip install fake_useragent')#line:326get_ipython ().system (f'git -C {wb}/repositories/{sai} reset --hard')#line:328initCloudDrive ()#line:333installAdditional ()#line:336clear_output ()#line:338get_ipython ().system (f'rm -rf {wb}/config.json')#line:340get_ipython ().system (f'ln -s {gwb}/Config/config.json {wb}/config.json')#line:341if os .path .exists (f"{gwb}/styles.csv"):#line:344get_ipython ().system (f'ln -s {gwb}/styles.csv {wb}/styles.csv')#line:345if os .path .exists (f"{wb}/extensions/sd-{w}-additional-networks"):#line:348cloudDriveSync (f'{gwb}/Lora',f'{wb}/extensions/sd-{w}-additional-networks/models/lora',Drive_Map )#line:349if len (os .listdir (f"{gwb}/Models"))==0 :#line:352get_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')#line:354if len (os .listdir (f"{gwb}/Vae"))==0 :#line:357get_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:359get_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:362get_ipython ().run_line_magic ('cd',f'{wb}/modules')#line:366get_ipython ().system ('wget -q -O extras.py https://huggingface.co/gmk123/run/raw/main/extras.py')#line:367get_ipython ().system ('wget -q -O sd_models.py https://huggingface.co/gmk123/run/raw/main/sd_models.py')#line:368get_ipython ().system ('wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://huggingface.co/gmk123/run/raw/main/blocks.py')#line:369get_ipython ().run_line_magic ('cd',f'{wb}')#line:371get_ipython ().system (f'sed -i \'s@print(\\"No module.*@@\' {wb}/repositories/{sai}/ldm/modules/diffusionmodules/model.py')#line:372get_ipython ().system (f'sed -i \'s@\\["sd_model_checkpoint"\\]@\\["sd_model_checkpoint", "sd_vae", "CLIP_stop_at_last_layers", "inpainting_mask_weight", "initial_noise_multiplier"\\]@g\' {wb}/modules/shared.py')#line:373get_ipython ().system (f'sed -i \'s@possible_sd_paths =.*@possible_sd_paths = [\"{wb}/repositories/{sai}\"]@\' {wb}/modules/paths.py')#line:375get_ipython ().system (f'sed -i \'s@\\.\\.\\/@src/@g\' {wb}/modules/paths.py')#line:376get_ipython ().system (f'sed -i \'s@src/generative-models@generative-models@g\' {wb}/modules/paths.py')#line:377wise ="--share --api --disable-safe-unpickle --enable-insecure-extension-access --xformers --disable-console-progressbars --theme dark --upcast-sampling --cors-allow-origins=*"#line:380def run (OO000OO000OOO00OO ):#line:390clear_output ()#line:391get_ipython ().run_line_magic ('cd',f'{wb}')#line:394get_ipython ().system (f'python {OO000OO000OOO00OO} {wise}')#line:395if os .path .exists (f'{wb}'):#line:398run (f'{w}.py')#line:399else :#line:400initLocal ()#line:402run (f'{w}.py')#line:405
run.py+205-209