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 main.py
Browse files
main.py
CHANGED
|
@@ -1,172 +1,66 @@
|
|
| 1 |
-
import sys
|
| 2 |
-
import os
|
| 3 |
-
from IPython import get_ipython
|
| 4 |
-
from IPython.utils import capture
|
| 5 |
-
from IPython.display import clear_output
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def
|
| 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 |
-
get_ipython().system(f'wget https://raw.githubuserhome/studio-lab-user.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')
|
| 68 |
-
get_ipython().system(f'wget https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -O {wb}/models/ESRGAN/4x-UltraSharp.pth')
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
# 优化embeddings
|
| 72 |
-
gitDownload(f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')
|
| 73 |
-
get_ipython().system(f'rm -rf {wb}/embeddings/negative/.git')
|
| 74 |
-
get_ipython().system(f'rm {wb}/embeddings/negative/.gitattributes')
|
| 75 |
-
|
| 76 |
-
gitDownload(f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')
|
| 77 |
-
get_ipython().system(f'rm -rf {wb}/models/Lora/positive/.git')
|
| 78 |
-
get_ipython().system(f'rm {wb}/models/Lora/positive/.gitattributes')
|
| 79 |
-
|
| 80 |
-
#Tag插件
|
| 81 |
-
gitDownload(f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')
|
| 82 |
-
get_ipython().system(f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')
|
| 83 |
-
get_ipython().system(f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')
|
| 84 |
-
|
| 85 |
-
#Roop换脸插件
|
| 86 |
-
gitDownload(f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')
|
| 87 |
-
get_ipython().system(f'pip install insightface==0.7.3') # 换脸插件
|
| 88 |
-
get_ipython().system(f'mkdir -p {wb}/models/roop')
|
| 89 |
-
get_ipython().system(f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')
|
| 90 |
-
print('Roop换脸启用')
|
| 91 |
-
|
| 92 |
-
# 部署conda环境
|
| 93 |
-
# import subprocess
|
| 94 |
-
# def run_command(command, message):
|
| 95 |
-
# print(f"Please wait, {message} is loading...")
|
| 96 |
-
# subprocess.run(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 97 |
-
# print(f"{message} completed!")
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
# 初始化本地环境
|
| 101 |
-
def initLocal():
|
| 102 |
-
#部署环境变量
|
| 103 |
-
# run_command('conda install conda -y', 'Conda')
|
| 104 |
-
# run_command('conda update -n base conda -y', 'Update')
|
| 105 |
-
# run_command('conda install -n base python=3.10 -y', 'Python')
|
| 106 |
-
# run_command('conda install -q -y glib=2.51.0', 'glib')
|
| 107 |
-
|
| 108 |
-
# run_command('conda install -y conda glib psutil gperftools aria2 gdown', 'Installing Conda')
|
| 109 |
-
# run_command('conda install -y -n base python=3.10.12', 'Installing Python')
|
| 110 |
-
# run_command('conda clean -y --all', 'Cleaning Conda')
|
| 111 |
-
# run_command('pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 --extra-index-url https://download.pytorch.org/whl/cu118', 'Installing Torch')
|
| 112 |
-
# run_command('pip install xformers==0.0.20 triton==2.0.0', 'Installing xformers')
|
| 113 |
-
|
| 114 |
-
#配置conda环境
|
| 115 |
-
get_ipython().system('conda install -c conda-forge libglib -y && conda update -n base conda -y')
|
| 116 |
-
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')
|
| 117 |
-
get_ipython().system('conda install -q -y aria2')
|
| 118 |
-
get_ipython().system('pip install tqdm')
|
| 119 |
-
|
| 120 |
-
clear_output()
|
| 121 |
-
get_ipython().run_line_magic('cd', '/home/studio-lab-user')
|
| 122 |
-
|
| 123 |
-
#安装sd包
|
| 124 |
-
get_ipython().system(f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')
|
| 125 |
-
|
| 126 |
-
get_ipython().system(f'pip install -qq pycloudflared ngrok') # ngrok网络加速
|
| 127 |
-
get_ipython().system(f'pip install --force-reinstall charset-normalizer==3.1.0') # 字符编码处理基础工具包
|
| 128 |
-
get_ipython().system(f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')
|
| 129 |
-
|
| 130 |
-
get_ipython().system(f'pip install fake_useragent') # civi、插件模块
|
| 131 |
-
|
| 132 |
-
########################################################
|
| 133 |
-
|
| 134 |
-
# 安装附加功能
|
| 135 |
-
installAdditional()
|
| 136 |
-
|
| 137 |
-
clear_output()
|
| 138 |
-
# 链接用户配置
|
| 139 |
-
get_ipython().system(f'rm -rf {wb}/config.json')
|
| 140 |
-
get_ipython().system(f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')
|
| 141 |
-
get_ipython().system(f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')
|
| 142 |
-
|
| 143 |
-
# 下载主模型
|
| 144 |
-
get_ipython().system(f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/192916 -d {wb}/models/Stable-diffusion -o MoyouArtificial_v1060.safetensors')
|
| 145 |
-
# 下载VAE
|
| 146 |
-
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')
|
| 147 |
-
# 放大脚本
|
| 148 |
-
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')
|
| 149 |
-
|
| 150 |
-
wise = "--listen --api --enable-insecure-extension-access --xformers --theme dark --gradio-queue --disable-console-progressbars --upcast-sampling --cors-allow-origins=*"
|
| 151 |
-
|
| 152 |
-
# Ngrok内网加速
|
| 153 |
-
ngrok_token = os.environ.get('NGROK_TOKEN')
|
| 154 |
-
wise += f" --ngrok {ngrok_token}"
|
| 155 |
-
|
| 156 |
-
# 运行
|
| 157 |
-
def run(script):
|
| 158 |
-
clear_output()
|
| 159 |
-
print(f'Ngrok内网令牌:{ngrok_token}')
|
| 160 |
-
print(f'参数:{wise}')
|
| 161 |
-
get_ipython().run_line_magic('cd', f'{wb}')
|
| 162 |
-
get_ipython().system(f'python {script} {wise}')
|
| 163 |
-
|
| 164 |
-
# 运行脚本
|
| 165 |
-
if os.path.exists(f'{wb}'):
|
| 166 |
-
run(f'webui.py')
|
| 167 |
-
else:
|
| 168 |
-
# 初化本地环境
|
| 169 |
-
initLocal()
|
| 170 |
-
|
| 171 |
-
# 运行
|
| 172 |
-
run(f'launch.py')
|
|
|
|
| 1 |
+
import sys #line:1
|
| 2 |
+
import os #line:2
|
| 3 |
+
from IPython import get_ipython #line:3
|
| 4 |
+
from IPython .utils import capture #line:4
|
| 5 |
+
from IPython .display import clear_output #line:5
|
| 6 |
+
wb =f'/home/studio-lab-user/stable-diffusion-webui'#line:8
|
| 7 |
+
def gitDownload (OO000O00O000O000O ,O00O0O00OOOOO0000 ):#line:11
|
| 8 |
+
if os .path .exists (O00O0O00OOOOO0000 ):#line:12
|
| 9 |
+
return #line:13
|
| 10 |
+
get_ipython ().system (f'git clone {OO000O00O000O000O} {O00O0O00OOOOO0000}')#line:15
|
| 11 |
+
def installAdditional ():#line:18
|
| 12 |
+
O0000OOOOOO0O0000 =[f'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',f'https://github.com/etherealxx/batchlinks-webui',f'https://github.com/camenduru/sd-civitai-browser',f'https://github.com/thomasasfk/sd-webui-aspect-ratio-helper',f'https://github.com/kohya-ss/sd-webui-additional-networks',f'https://github.com/fkunn1326/openpose-editor',f'https://github.com/nonnonstop/sd-webui-3d-open-pose-editor',f'https://github.com/Physton/sd-webui-prompt-all-in-one',f'https://github.com/Bing-su/adetailer',f'https://github.com/picobyte/stable-diffusion-webui-wd14-tagger',f'https://github.com/Mikubill/sd-webui-controlnet',f'https://github.com/IDEA-Research/DWPose',f'https://github.com/hanamizuki-ai/stable-diffusion-webui-localization-zh_Hans',]#line:59
|
| 13 |
+
for OO0O000O0OOO00O0O in O0000OOOOOO0O0000 :#line:60
|
| 14 |
+
O0O00000OO000000O =OO0O000O0OOO00O0O .split ('/')[-1 ]#line:62
|
| 15 |
+
if 'github'in OO0O000O0OOO00O0O :#line:64
|
| 16 |
+
get_ipython ().system (f'git clone --depth 1 {OO0O000O0OOO00O0O} {wb}/extensions/{O0O00000OO000000O}')#line:65
|
| 17 |
+
get_ipython ().system (f'wget https://raw.githubuserhome/studio-lab-user.com/camenduru/stable-diffusion-webui-scripts/main/run_n_times.py -O {wb}/scripts/run_n_times.py')#line:67
|
| 18 |
+
get_ipython ().system (f'wget https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -O {wb}/models/ESRGAN/4x-UltraSharp.pth')#line:68
|
| 19 |
+
gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:72
|
| 20 |
+
get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:73
|
| 21 |
+
get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:74
|
| 22 |
+
gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:76
|
| 23 |
+
get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:77
|
| 24 |
+
get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:78
|
| 25 |
+
gitDownload (f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')#line:81
|
| 26 |
+
get_ipython ().system (f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:82
|
| 27 |
+
get_ipython ().system (f'wget https://huggingface.co/gmk123/colab/raw/main/danbooru.csv -O {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:83
|
| 28 |
+
gitDownload (f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')#line:86
|
| 29 |
+
get_ipython ().system (f'pip install insightface==0.7.3')#line:87
|
| 30 |
+
get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:88
|
| 31 |
+
get_ipython ().system (f'wget https://huggingface.co/ezioruan/inswapper_128.onnx/resolve/main/inswapper_128.onnx -O {wb}/models/roop/inswapper_128.onnx')#line:89
|
| 32 |
+
print ('Roop换脸启用')#line:90
|
| 33 |
+
def initLocal ():#line:101
|
| 34 |
+
get_ipython ().system ('conda install -c conda-forge libglib -y && conda update -n base conda -y')#line:115
|
| 35 |
+
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')#line:116
|
| 36 |
+
get_ipython ().system ('conda install -q -y aria2')#line:117
|
| 37 |
+
get_ipython ().system ('pip install tqdm')#line:118
|
| 38 |
+
clear_output ()#line:120
|
| 39 |
+
get_ipython ().run_line_magic ('cd','/home/studio-lab-user')#line:121
|
| 40 |
+
get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')#line:124
|
| 41 |
+
get_ipython ().system (f'pip install -qq pycloudflared ngrok')#line:126
|
| 42 |
+
get_ipython ().system (f'pip install --force-reinstall charset-normalizer==3.1.0')#line:127
|
| 43 |
+
get_ipython ().system (f'pip install -qq translators chardet openai boto3 aliyun-python-sdk-core aliyun-python-sdk-alimt python-dotenv image-reward pyfunctional')#line:128
|
| 44 |
+
get_ipython ().system (f'pip install fake_useragent')#line:130
|
| 45 |
+
installAdditional ()#line:135
|
| 46 |
+
clear_output ()#line:137
|
| 47 |
+
get_ipython ().system (f'rm -rf {wb}/config.json')#line:139
|
| 48 |
+
get_ipython ().system (f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:140
|
| 49 |
+
get_ipython ().system (f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:141
|
| 50 |
+
get_ipython ().system (f'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://civitai.com/api/download/models/192916 -d {wb}/models/Stable-diffusion -o MoyouArtificial_v1060.safetensors')#line:144
|
| 51 |
+
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')#line:146
|
| 52 |
+
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')#line:148
|
| 53 |
+
wise ="--listen --api --enable-insecure-extension-access --xformers --theme dark --gradio-queue --disable-console-progressbars --upcast-sampling --cors-allow-origins=*"#line:150
|
| 54 |
+
ngrok_token =os .environ .get ('NGROK_TOKEN')#line:153
|
| 55 |
+
wise +=f" --ngrok {ngrok_token}"#line:154
|
| 56 |
+
def run (O0000OOO00O00O000 ):#line:157
|
| 57 |
+
clear_output ()#line:158
|
| 58 |
+
print (f'Ngrok内网令牌:{ngrok_token}')#line:159
|
| 59 |
+
print (f'参数:{wise}')#line:160
|
| 60 |
+
get_ipython ().run_line_magic ('cd',f'{wb}')#line:161
|
| 61 |
+
get_ipython ().system (f'python {O0000OOO00O00O000} {wise}')#line:162
|
| 62 |
+
if os .path .exists (f'{wb}'):#line:165
|
| 63 |
+
run (f'webui.py')#line:166
|
| 64 |
+
else :#line:167
|
| 65 |
+
initLocal ()#line:169
|
| 66 |
+
run (f'launch.py')#line:172
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|