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:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("gmk123/colab", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 9,165 Bytes
0b43475 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | 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')
l = base64.b64decode(("bGF1bmNo").encode('ascii')).decode('ascii')
# sdw = binascii.a2b_uu("6<W1A8FQE+61I9F9U<VEO;BUW96)U:0``").decode('utf-8')
# w = binascii.a2b_uu("%=V5B=6D`").decode('utf-8')
wb = f'/root/main'
sai = binascii.a2b_uu("=<W1A8FQE+61I9F9U<VEO;BUS=&%B:6QI='DM86D`").decode('utf-8')
sd = binascii.a2b_uu("04W1A8FQE+61I9F9U<VEO;@``").decode('utf-8')
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/camenduru/{sdw}-images-browser', # 图像浏览器
f'https://github.com/camenduru/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}/extensions/{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}/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://github.com/zanllp/sd-{w}-infinite-image-browsing -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')
# 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}/extensions/sd-{w}-controlnet')
# 模型下载到Colab
if ControlNet:
gitDownload(f'https://github.com/Mikubill/sd-{w}-controlnet',f'{wb}/extensions/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}/extensions/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}/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')
# 初始化本地环境
def initLocal():
#部署 env 环境变量
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')
#设置 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 -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/colab/raw/main/config.json"')
get_ipython().system(f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')
#下载主模型
model_dir = f"{wb}/models/{sd}"
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')
# #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} --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=*')
# 运行脚本
if os.path.exists(f'{wb}'):
run(f'{w}.py')
else:
# 初化本地环境
initLocal()
# 运行
run(f'{l}.py') |