{"metadata":{"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[],"dockerImageVersionId":30699,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.13"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## Updated (25 May 2024) - V13\n## Read all instructions very carefully\n### Beging installing with executing first cell always\n### Only legal usage source of this notebook downloaded from :\n### https://www.patreon.com/posts/run-sd-web-ui-on-88714330\n### Join discord : https://discord.com/servers/software-engineering-courses-secourses-772774097734074388\n","metadata":{}},{"cell_type":"code","source":"!apt update --yes\n!yes | apt install libgoogle-perftools-dev\n!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n%cd /kaggle/working/stable-diffusion-webui\n!chmod +x webui.sh\n\n# To be able to use Face ID Adapter or InstantId after executed below cell and web UI started cancel run\n# And then execute this cell 1 time and restart Web UI\n%cd /kaggle/working/stable-diffusion-webui\n!wget https://huggingface.co/MonsterMMORPG/SECourses/resolve/main/styles.csv -O styles.csv\n\n# File path\nfile_path = '/kaggle/working/stable-diffusion-webui/requirements.txt'\n\ntext_to_append = 'insightface==0.7.3\\nxformers==0.0.26.post1\\ntorch==2.3.0'\n\nwith open(file_path, 'a') as file:\n    file.write('\\n' + text_to_append)  # Add a newline before appending\n    \nfile_path = '/kaggle/working/stable-diffusion-webui/requirements_versions.txt'\n\nwith open(file_path, 'a') as file:\n    file.write('\\n' + text_to_append)  # Add a newline before appending\n     \n# generates missing new folder\n!mkdir -p /kaggle/temp/models\n\n# we will download controlnet models into very slow temp directory since working directory space very limited\n!mkdir -p /kaggle/temp/cnmodels\n!mkdir -p /kaggle/working/stable-diffusion-webui/models/ESRGAN\n\n%cd /kaggle/working/stable-diffusion-webui/extensions\n!git clone https://github.com/Gourieff/sd-webui-reactor\n!git clone https://github.com/Bing-su/adetailer\n%cd /kaggle/working/stable-diffusion-webui\n!pip install flask\n!pip install pyngrok","metadata":{"_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# downloads SDXL base model\n!wget https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors -O /kaggle/temp/models/sd_xl_base_1.0.safetensors\n\n# real vis XL model one of the most realistic\n# !wget https://huggingface.co/SG161222/RealVisXL_V4.0/resolve/main/RealVisXL_V4.0.safetensors -O /kaggle/working/models/RealVisXL_V4.0.safetensors\n\n# downloads SDXL best VAE file FP16 and we name it same as base model so it will be auto used\n!wget https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors -O /kaggle/working/stable-diffusion-webui/models/VAE/sd_xl_base_1.0.safetensors\n\n# downloads Hyper_Realism_V3 into models folder - best SD 1.5 realism model\n!wget https://huggingface.co/MonsterMMORPG/Stable-Diffusion/resolve/main/best_realism.safetensors -O /kaggle/temp/models/Hyper_Realism_V3.safetensors\n\n# downloads 4x_NMKD-Superscale-SP_178000_G  upscaler into the RESGRAN folder\n!wget https://huggingface.co/gemasai/4x_NMKD-Superscale-SP_178000_G/resolve/main/4x_NMKD-Superscale-SP_178000_G.pth -O /kaggle/working/stable-diffusion-webui/models/ESRGAN/4x_NMKD-Superscale-SP_178000_G.pth\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# this below code will clone and install controlnet with all of its models for SDXL\n# dont download both SDXL and SD 1.5 Controlnet Models at the same - you would get out of disk space\n# execute this line before starting the automatic1111 web ui via webui.sh\n# after web ui started we need to manually set the model folder path from settings\n# from ControlNet settings we will set Extra path to scan for ControlNet models\n# the model path will be /kaggle/temp/cnmodels\n# but the /kaggle/temp/ works much slower than /kaggle/working/ \n# so you can set certain ones as working directory and use them if you prefer\n%cd /kaggle/working/stable-diffusion-webui/extensions\n!git clone https://github.com/Mikubill/sd-webui-controlnet\n%cd /kaggle/working/stable-diffusion-webui\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_blur.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_blur_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur_anime.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_blur_anime_beta.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_blur_anime_beta.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_canny.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_depth.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_depth.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_canny.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_depth_midas.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_depth_midas.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_depth_zoe.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_depth_zoe.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_lineart.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_lineart.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_openpose.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_diffusers_xl_sketch.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_diffusers_xl_sketch.safetensors\"\n\n\n!wget -O /kaggle/temp/cnmodels/diffusers_xl_canny_full.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_canny_full.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/diffusers_xl_depth_full.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/diffusers_xl_depth_full.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/ioclab_sd15_recolor.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ioclab_sd15_recolor.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter_sd15_plus.pth \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ip-adapter_sd15_plus.pth\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter_xl.pth \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/ip-adapter_xl.pth\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_canny_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_canny_anime.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_depth_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_depth_anime.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_openpose_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_openpose_anime.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_openpose_anime_v2.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_openpose_anime_v2.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/kohya_controllllite_xl_scribble_anime.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/kohya_controllllite_xl_scribble_anime.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sai_xl_canny_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_canny_256lora.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sai_xl_depth_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_depth_256lora.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sai_xl_recolor_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_recolor_256lora.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sai_xl_sketch_256lora.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sai_xl_sketch_256lora.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sargezt_xl_depth.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sargezt_xl_depth_faid_vidit.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth_faid_vidit.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sargezt_xl_depth_zeed.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_depth_zeed.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/sargezt_xl_softedge.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/sargezt_xl_softedge.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_xl_canny.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_canny.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_openpose.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/t2i-adapter_xl_sketch.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/t2i-adapter_xl_sketch.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/thibaud_xl_openpose.safetensors \"https://huggingface.co/lllyasviel/sd_control_collection/resolve/main/thibaud_xl_openpose.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter-plus-face_sdxl_vit-h.safetensors \"https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus-face_sdxl_vit-h.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter-plus_sdxl_vit-h.safetensors \"https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter-faceid-plusv2_sdxl.bin \"https://huggingface.co/h94/IP-Adapter-FaceID/resolve/main/ip-adapter-faceid-plusv2_sdxl.bin\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter_sdxl.safetensors \"https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter_sdxl.safetensors\"\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# this below code will clone and install controlnet with all of its models For SD 1.5 based models\n# execute this line before starting the automatic1111 web ui via webui.sh\n# after web ui started we need to manually set the model folder path from settings\n# from ControlNet settings we will set Extra path to scan for ControlNet models\n# the model path will be /kaggle/temp/cnmodels\n%cd /kaggle/working/stable-diffusion-webui/extensions\n!git clone https://github.com/Mikubill/sd-webui-controlnet\n%cd /kaggle/working/stable-diffusion-webui\n!wget -O /kaggle/temp/cnmodels/control_v11e_sd15_ip2p.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_ip2p.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11e_sd15_shuffle.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11e_sd15_shuffle.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11f1e_sd15_tile.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1e_sd15_tile.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11f1p_sd15_depth.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11f1p_sd15_depth.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_canny.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_canny.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_inpaint.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_inpaint.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_lineart.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_lineart.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_mlsd.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_mlsd.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_normalbae.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_normalbae.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_openpose.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_openpose.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_scribble.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_scribble.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_seg.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_seg.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15_softedge.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15_softedge.pth\"\n\n!wget -O /kaggle/temp/cnmodels/control_v11p_sd15s2_lineart_anime.pth \"https://huggingface.co/lllyasviel/ControlNet-v1-1/resolve/main/control_v11p_sd15s2_lineart_anime.pth\"\n\n!wget -O /kaggle/temp/cnmodels/t2iadapter_style_sd14v1.pth \"https://huggingface.co/TencentARC/T2I-Adapter/resolve/main/models/t2iadapter_style_sd14v1.pth\"\n\n!wget -O /kaggle/temp/cnmodels/ip-adapter-faceid-plusv2_sd15.bin \"https://huggingface.co/h94/IP-Adapter-FaceID/resolve/main/ip-adapter-faceid-plusv2_sd15.bin\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# this below code will download pixel art SDXL lora from civit AI. this is the format to download others\n# right click download button and copy link and replace yours as below\n# download loras into working directory for fast access \n!mkdir -p /kaggle/working/stable-diffusion-webui/models/Lora\n!wget https://civitai.com/api/download/models/135931 -O /kaggle/working/stable-diffusion-webui/models/Lora/Pixel_Art_XL_1_1.safetensors","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### First you need to register and get a token. \n### I used gmail register >\n### https://dashboard.ngrok.com/get-started/your-authtoken\n### Skipped authenticator not necessary\n### How to use NGROK on Kaggle video : https://youtu.be/iBT6rhH0Fjs\n### [Click here](https://cdn-uploads.huggingface.co/production/uploads/6345bd89fe134dfd7a0dba40/eRmm7HjCcKhqsTNTJXy9E.png) to see how a token looks like you need to get","metadata":{}},{"cell_type":"code","source":"\n## first put your ngrok token to the below and then run this code\n## it will give a link like this at below : https://2fc5-34-134-226-xxx.ngrok-free.app\n## open it and then run web ui and once web ui started that link will start working\n## How to use NGROK on Kaggle new video : https://youtu.be/iBT6rhH0Fjs\nimport os\nimport threading\n\nfrom flask import Flask\nfrom pyngrok import ngrok, conf\n\nconf.get_default().auth_token = \"2VRmUXz0nMus2Bdj6gY128KB8sZ_78yw6cjqaCnv8jZkoMzR\"\n\nos.environ[\"FLASK_ENV\"] = \"development\"\n\napp = Flask(__name__)\n\npublic_url = ngrok.connect(7860).public_url\nprint(\" * ngrok tunnel \\\"{}\\\" -> \\\"http://127.0.0.1:{}/\\\"\".format(public_url, 7860))\n\napp.config[\"BASE_URL\"] = public_url\n\n@app.route(\"/\")\ndef index():\n    return \"Hello from Colab!\"\n\nthreading.Thread(target=app.run, kwargs={\"use_reloader\": False}).start()\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# DONT FORGET TO REGISTER NGROK AND GET YOUR TOKEN AND REPLACE YOUR --ngrok TOKEN BELOW\n# WE NEED ngrok NOW SINCE GRADIO SHARE IS BANNED FOR FREE ACCOUNTS\n# TESTED 10 MINUTES GENERATE FOREVER WORKED PERFECT\n# If you turn off your session or restart it will delete everything\n# this below code will start Automatic1111 Web UI. You can stop and start this cell again to restart Web UI\n# but this is leaving some residual RAM usage so turn off and on session may be better\n# remove --no-half-vae if you use SD 1.5 based models - use only if SDXL\n# if you want to use your own trained LoRAs and saved as kaggle dataset give path like below\n# \"/kaggle/input/my-loras\" is the path of my LoRA dataset I uploaded\n# so remove dash(#) in front of --lora-dir \"/kaggle/input/my-loras\" \\ and enter your dataset path\n# for ControlNet we set folder from settings of Web UI /kaggle/temp/cnmodels - just apply and refresh\n!./webui.sh \\\n    -f \\\n    --xformers \\\n    --ckpt-dir \"/kaggle/temp/models\" \\\n    --enable-insecure-extension-access \\\n    #--lora-dir \"/kaggle/input/my-loras\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### INFO: If you see AttributeError: 'NoneType' object has no attribute 'lowvram' error try to reload model several times until get fixed","metadata":{}},{"cell_type":"code","source":"# this below code will zip all the images you generated into generated_images.zip file inside working main directory\n# you can download\n!rm -r /kaggle/working/generated_images.zip\n%cd /kaggle/working/stable-diffusion-webui/outputs/\n!zip -r /kaggle/working/generated_images.zip *\n%cd -\n","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#patron requested models\n#this way you can download any civitAI models\n\n!wget \"https://civitai.com/api/download/models/138176?type=Model&format=SafeTensor&size=full&fp=fp32\" -O \"/kaggle/working/models/CyberRealistic_v3_3.safetensors\"\n    \n!wget \"https://civitai.com/api/download/models/132760?type=Model&format=SafeTensor&size=pruned&fp=fp16\" -O \"/kaggle/working/models/AbsoluteReality_v181.safetensors\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#patron requested models\n#this way you can download any civitAI models\n!wget \"https://civitai.com/api/download/models/157603\" -O \"/kaggle/working/models/AlbedoBase_XL.safetensors\"","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}