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 (O0O0OO0O00O00O0OO ,O0O00OO00O0O000OO ):#line:11 if os .path .exists (O0O00OO00O0O000OO ):#line:12 return #line:13 get_ipython ().system (f'git clone {O0O0OO0O00O00O0OO} {O0O00OO00O0O000OO}')#line:15 def installAdditional ():#line:18 OOO0O0O0000O0000O =['https://github.com/AlUlkesh/stable-diffusion-webui-images-browser','https://github.com/etherealxx/batchlinks-webui','https://github.com/camenduru/sd-civitai-browser','https://github.com/thomasasfk/sd-webui-aspect-ratio-helper','https://github.com/fkunn1326/openpose-editor','https://github.com/nonnonstop/sd-webui-3d-open-pose-editor','https://github.com/Physton/sd-webui-prompt-all-in-one','https://github.com/Bing-su/adetailer','https://github.com/picobyte/stable-diffusion-webui-wd14-tagger','https://github.com/Mikubill/sd-webui-controlnet','https://github.com/IDEA-Research/DWPose','https://github.com/Tencent/LightDiffusionFlow','https://github.com/continue-revolution/sd-webui-segment-anything','https://github.com/hanamizuki-ai/stable-diffusion-webui-localization-zh_Hans','https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',]#line:59 for OOOO00O0000O0OOOO in OOO0O0O0000O0000O :#line:60 OO0O0OOOO0O0O0O0O =OOOO00O0000O0OOOO .split ('/')[-1 ]#line:62 if 'github'in OOOO00O0000O0OOOO :#line:64 get_ipython ().system (f'git clone --depth 1 {OOOO00O0000O0OOOO} {wb}/extensions/{OO0O0OOOO0O0O0O0O}')#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 clear_output ()#line:69 gitDownload (f'https://huggingface.co/embed/negative',f'{wb}/embeddings/negative')#line:71 get_ipython ().system (f'rm -rf {wb}/embeddings/negative/.git')#line:72 get_ipython ().system (f'rm {wb}/embeddings/negative/.gitattributes')#line:73 gitDownload (f'https://huggingface.co/embed/lora',f'{wb}/models/Lora/positive')#line:75 get_ipython ().system (f'rm -rf {wb}/models/Lora/positive/.git')#line:76 get_ipython ().system (f'rm {wb}/models/Lora/positive/.gitattributes')#line:77 gitDownload (f'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',f'{wb}/extensions/a1111-sd-webui-tagcomplete')#line:80 get_ipython ().system (f'rm -rf {wb}/extensions/a1111-sd-webui-tagcomplete/tags/danbooru.csv')#line:81 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:82 gitDownload (f'https://github.com/s0md3v/sd-webui-roop',f'{wb}/extensions/sd-webui-roop')#line:85 get_ipython ().system (f'pip install -q insightface==0.7.3 onnx')#line:86 get_ipython ().system (f'mkdir -p {wb}/models/roop')#line:87 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:88 print ('Roop换脸启用')#line:89 import subprocess #line:91 def sync_tmp_folder ():#line:93 O0O00O0O0OOO00O00 =[['rm','-rf','~/tmp/*','~/tmp','~/stable-diffusion-webui/models/Stable-diffusion/tmp_models','~/stable-diffusion-webui/models/ControlNet','~/stable-diffusion-webui/models/sam'],['ln','-vs','/tmp','~/tmp'],['ln','-vs','/tmp/models','~/stable-diffusion-webui/models/Stable-diffusion/tmp_models'],['ln','-vs','/tmp/ControlNet','~/stable-diffusion-webui/models/ControlNet'],['ln','-vs','/tmp/sam','~/stable-diffusion-webui/models/sam']]#line:100 for O0000O00O00OOO0OO in O0O00O0O0OOO00O00 :#line:102 O0OOOOOO00OOO0000 =[os .path .expanduser (OOOO00OO00OO0O0OO )for OOOO00OO00OO0O0OO in O0000O00O00OOO0OO ]#line:103 subprocess .run (O0OOOOOO00OOO0000 ,check =True )#line:104 def run_command (O00O0OOOOOOO0O0OO ,OO000OO0OOOO00O00 ):#line:107 print (f"Please wait, {OO000OO0OOOO00O00} is loading...")#line:108 subprocess .run (O00O0OOOOOOO0O0OO ,shell =True ,stdout =subprocess .DEVNULL ,stderr =subprocess .DEVNULL )#line:109 print (f"{OO000OO0OOOO00O00} ok!")#line:110 def zrok ():#line:113 try :#line:114 OOO0OO00000O000OO ="/home/studio-lab-user/.zrok/bin"#line:115 os .makedirs (OOO0OO00000O000OO ,exist_ok =True )#line:116 subprocess .run (["curl","-sLO","https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz"],check =True )#line:117 subprocess .run (["tar","-xzf","zrok_0.4.23_linux_amd64.tar.gz","-C",OOO0OO00000O000OO ,"--wildcards","*zrok"],check =True )#line:118 os .remove ("zrok_0.4.23_linux_amd64.tar.gz")#line:119 except Exception as O000000OOO0000OOO :#line:121 print (f"An error occurred: {O000000OOO0000OOO}")#line:122 def initLocal ():#line:126 run_command ('conda install -y conda glib psutil gperftools aria2 gdown wget','【 Installing Conda 】')#line:128 run_command ('conda install -y -n base python=3.10.12','【 Installing Python 3.10 】')#line:129 run_command ('conda clean -y --all','【 Cleaning Conda 】')#line:130 run_command ('pip install torch==2.1.2+cu121 torchvision==0.16.2+cu121 torchaudio==2.1.2 --extra-index-url https://download.pytorch.org/whl/cu121','【 Installing Torch 】')#line:131 run_command ('pip install xformers==0.0.23.post1 triton==2.1.0','【 Installing xformers 】')#line:132 get_ipython ().system ('pip install -q tqdm')#line:134 clear_output ()#line:136 get_ipython ().run_line_magic ('cd','/home/studio-lab-user')#line:137 with capture .capture_output ()as OOOOOO000OOOOOOOO :#line:140 def OOOO00000000OO00O (O00000O00O0O0OO0O ,OO00O0O00O00O0OOO ,OOO00OO00OOOO00O0 ):OO0O0O0OO0OO00OO0 =widgets .Button (description =O00000O00O0O0OO0O ,disabled =True ,button_style =OO00O0O00O00O0OOO ,layout =widgets .Layout (min_width =OOO00OO00OOOO00O0 ));display (OO0O0O0OO0OO00OO0 )#line:141 get_ipython ().system (f'git clone -q --branch master https://github.com/AUTOMATIC1111/stable-diffusion-webui {wb}')#line:143 with capture .capture_output ()as OOOOOO000OOOOOOOO :#line:145 get_ipython ().run_line_magic ('cd',f'{wb}')#line:146 get_ipython ().system ('pip install -q -r requirements.txt')#line:148 get_ipython ().system (f'pip install -q basicsr')#line:150 get_ipython ().system (f'pip install -q fake_useragent')#line:151 sync_tmp_folder ()#line:154 clear_output ()#line:156 zrok ()#line:160 get_ipython ().system (f'wget https://huggingface.co/gmk123/run/raw/main/zrun.py -O {wb}/zrun.py')#line:161 get_ipython ().system (f'wget https://huggingface.co/gmk123/run/raw/main/zrok.py -O {wb}/zrok.py')#line:162 installAdditional ()#line:165 get_ipython ().system (f'rm -rf {wb}/config.json')#line:168 get_ipython ().system (f'wget -O {wb}/config.json "https://huggingface.co/gmk123/colab/raw/main/config.json"')#line:169 get_ipython ().system (f'wget -O {wb}/styles.csv "https://huggingface.co/gmk123/colab/raw/main/styles.csv"')#line:170 clear_output ()#line:172 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:174 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:176 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:178 wise ="--xformers --enable-insecure-extension-access --theme dark --disable-console-progressbars --upcast-sampling"#line:180 ngrok_token =os .environ .get ('NGROK_TOKEN')#line:183 wise +=f" --ngrok {ngrok_token}"#line:184 def run (OO00000OO0O0O0O0O ):#line:187 clear_output ()#line:188 print (f'建议使用第二步:zrok部署,无需魔法,没有流量限制')#line:189 print (f'Ngrok注意事项:每个账号每月1G流量!需配合魔法使用')#line:190 get_ipython ().system (f'mkdir -p /tmp/ControlNet')#line:191 get_ipython ().run_line_magic ('cd',f'{wb}')#line:193 get_ipython ().system (f'python {OO00000OO0O0O0O0O} {wise}')#line:194 if os .path .exists (f'{wb}'):#line:197 run (f'webui.py')#line:199 else :#line:200 initLocal ()#line:202 run (f'launch.py')#line:205