readme: ## 1 -  配置环境
  
  ### 1.0 测试显卡
  
  !nvidia-smi -L
  
  ### 1.1 下载安装依赖
  setup miniconda
  
  
  import sys
  !wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
  !chmod +x Miniconda3-latest-Linux-x86_64.sh
  !bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local
  sys.path.append('/usr/local/lib/python3.7/site-packages/')
  !rm Miniconda3-latest-Linux-x86_64.sh
  
  ### 1.2 设置环境
  Setup environment, Gfpgan and Real-ESRGAN. Takes about 5-6 minutes
  
  #@markdown ### Set up conda environment - Takes a while
  !conda env update -n base -f /content/stable-diffusion/environment.yaml 
  
  ### 1.3 设置CFPGan和ESRGAN
  
  
  #@markdown ### Build upscalers support
  #@markdown **GFPGAN** Automatically correct distorted faces with a built-in GFPGAN option, fixes them in less than half a second
  #@markdown **ESRGAN** Boosts the resolution of images with a built-in RealESRGAN option
  #@markdown LDSR and GoBig enable amazing upscale options in the new Image Lab
  
  add_CFP = True #@param {type:"boolean"} 
  add_ESR = True #@param {type:"boolean"}
  add_LDSR = False #@param {type:"boolean"} 
  #@markdown ⚠️ LDSR is 1.9GB and make take time to download
  
  if add_CFP:
    %cd /content/stable-diffusion/src/gfpgan/
    !pip install basicsr facexlib yapf lmdb opencv-python pyyaml tb-nightly --no-deps
    !python setup.py develop
    !pip install realesrgan
    !wget https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth -P experiments/pretrained_models
  if add_ESR:
    %cd /content/stable-diffusion/src/realesrgan/
    !wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P experiments/pretrained_models
    !wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P experiments/pretrained_models
  if add_LDSR:
    %cd /content/stable-diffusion/src
    !git clone https://github.com/devilismyfriend/latent-diffusion
    %cd latent-diffusion
    %mkdir -p experiments/
    %cd experiments/
    %mkdir -p pretrained_models
    %cd pretrained_models
    #project.yaml download
    !wget -O project.yaml https://heibox.uni-heidelberg.de/f/31a76b13ea27482981b4/?dl=1
    #model.ckpt model download
    !wget -O model.ckpt https://heibox.uni-heidelberg.de/f/578df07c8fc04ffbadf3/?dl=1
  
  %cd /content/stable-diffusion/
  !wget https://github.com/matomo-org/travis-scripts/blob/master/fonts/Arial.ttf?raw=true -O arial.ttf
  
  #2.配置NovelAI
  
  **可以展开配置密码**，否则自动随机生成一个
  
  每次更改需要运行一席下面单元格代码
  
  ## 下载复制文件
  
  最快也得4分钟，稍等
  
  如果执行失败，重新执行第二步和第三步即可
  
  !sudo apt-get install aria2
  !sudo apt-get install file
  
  !mkdir /content/time
  !git clone https://github.com/pnpnpn/timeout-decorator.git /content/time
  %cd /content/time
  !pwd
  !ls -l
  
  # 下载NA
  %cd /content/time
  
  import timeout_decorator
  
  outTime=180
  
  @timeout_decorator.timeout(outTime)
  def downNovelAI():
    !rm -rf /content/n2
    !mkdir /content/n2
    %cd /content/n2
    !aria2c "magnet:?xt=urn:btih:4a4b483d4a5840b6e1fee6b0ca1582c979434e4d&dn=naifu&tr=udp%3a%2f%2ftracker.opentrackr.org%3a1337%2fannounce"
  
  def checkFile():
    !file /content/n2/naifu/models/animefull-final-pruned/model.ckpt>fileinfo
    !file /content/n2/naifu/models/animevae.pt>fileinfo2
    f1=open("fileinfo")
    res1=f1.read()
    f1.close
    f2=open("fileinfo2")
    res2=f2.read()
    f2.close
    return "Zip" in res1 and "Zip" in res2
  
  while 1:
    try:
      downNovelAI()
    except:
      if checkFile():
        print("下载完成")
        outTime+=60
        break
      else:
        print("下载未完成，自动重试")
  
  # 下载WebUI
  
  !mkdir /content/novelai
  %cd /content/novelai
  !git clone https://github.com/RyensX/stable-diffusion-webui-zh /content/novelai
  %cd /content/novelai
  !git checkout -b master
  
  # 复制模型
  
  !cp /content/n2/naifu/models/animefull-final-pruned/model.ckpt /content/novelai/models/Stable-diffusion/
  !cp /content/n2/naifu/models/animevae.pt /content/novelai/models/Stable-diffusion/model.pt
  
  !mkdir -p /content/novelai/train_images/raw/
  !mkdir -p /content/novelai/train_images/des/
  
  ## 设置密码
  若不设置则随机生成一个
  
  每次更改需要运行一下下面单元格代码
  
  import random
  keys="abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
  
  #@markdown # 服务账号
  user="Iris" #@param {type:"string"}
  if len(user)==0:
    user="".join([random.choice(keys) for i in range(random.randint(4,6))])
  #@markdown # 服务密码
  pwd="212121" #@param {type:"string"}
  if len(pwd)==0:
    pwd="".join([random.choice(keys) for i in range(random.randint(6,8))]) 
  
  #3.运行NovelAI
  
  * 运行成功时会显示两个蓝色的地址
  
  * 点击**类似** ~https://xxxx.gradio.app/~ 的网址即可外部访问，支持分享给别人用
  
  * 有时候运行成功但是没给出链接可能是因为太多人在生成链接了，**重新运行一下**这一步试试
  * 有时候生成图片进度条都没动就直接出图而且界面一直没有重新出来gen也是因为太多人用，刷新一下就好
  
  **可主动停止和多次运行下列单元格代码**控制NovelAI运行状态
  
  %cd /content/novelai
  print("#####################################################################################################################")
  print(f"* 账号密码分别是{user}和{pwd}")
  print("#######################################")
  print("!!!运行成功时会显示两个蓝色的地址，点击下方类似 https://xxxx.gradio.app/ 的网址即可外部访问，支持分享给别人用")
  print("!!!注意看上面文本提示")
  print("#####################################################################################################################")
  !python launch.py --shar