colab / main.py
gmk123's picture
Update main.py
3fc6d0b verified
Raw
History Blame Contribute Delete
6.16 kB
import sys #line:1
import os #line:2
from IPython import get_ipython #line:3
from IPython .utils import capture #line:4
from IPython .display import clear_output #line:5
wb =f'/home/studio-lab-user/stable-diffusion-webui'#line:8
def gitDownload (OO000O00O000O000O ,O00O0O00OOOOO0000 ):#line:11
if os .path .exists (O00O0O00OOOOO0000 ):#line:12
return #line:13
get_ipython ().system (f'git clone {OO000O00O000O000O} {O00O0O00OOOOO0000}')#line:15
def installAdditional ():#line:18
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
for OO0O000O0OOO00O0O in O0000OOOOOO0O0000 :#line:60
O0O00000OO000000O =OO0O000O0OOO00O0O .split ('/')[-1 ]#line:62
if 'github'in OO0O000O0OOO00O0O :#line:64
get_ipython ().system (f'git clone --depth 1 {OO0O000O0OOO00O0O} {wb}/extensions/{O0O00000OO000000O}')#line:65
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
get_ipython ().system (f'wget https://huggingface.co/embed/upscale/resolve/main/4x-UltraSharp.pth -O {wb}/models/ESRGAN/4x-UltraSharp.pth')#line:68
gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:72
get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:73
get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:74
gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:76
get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:77
get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:78
gitDownload (f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')#line:81
get_ipython ().system (f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:82
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
gitDownload (f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')#line:86
get_ipython ().system (f'pip install insightface==0.7.3')#line:87
get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:88
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
print ('Roop换脸启用')#line:90
def initLocal ():#line:101
get_ipython ().system ('conda install -c conda-forge libglib -y && conda update -n base conda -y')#line:115
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
get_ipython ().system ('conda install -q -y aria2')#line:117
get_ipython ().system ('pip install tqdm')#line:118
clear_output ()#line:120
get_ipython ().run_line_magic ('cd','/home/studio-lab-user')#line:121
get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')#line:124
get_ipython ().system (f'pip install -qq pycloudflared ngrok')#line:126
get_ipython ().system (f'pip install --force-reinstall charset-normalizer==3.1.0')#line:127
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
get_ipython ().system (f'pip install fake_useragent')#line:130
installAdditional ()#line:135
clear_output ()#line:137
get_ipython ().system (f'rm -rf {wb}/config.json')#line:139
get_ipython ().system (f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:140
get_ipython ().system (f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:141
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
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
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
wise ="--listen --api --enable-insecure-extension-access --xformers --theme dark --gradio-queue --disable-console-progressbars --upcast-sampling --cors-allow-origins=*"#line:150
ngrok_token =os .environ .get ('NGROK_TOKEN')#line:153
wise +=f" --ngrok {ngrok_token}"#line:154
def run (O0000OOO00O00O000 ):#line:157
clear_output ()#line:158
print (f'Ngrok内网令牌:{ngrok_token}')#line:159
print (f'参数:{wise}')#line:160
get_ipython ().run_line_magic ('cd',f'{wb}')#line:161
get_ipython ().system (f'python {O0000OOO00O00O000} {wise}')#line:162
if os .path .exists (f'{wb}'):#line:165
run (f'webui.py')#line:166
else :#line:167
initLocal ()#line:169
run (f'launch.py')#line:172