{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#@markdown # Start Stable-Diffusion\n", "from IPython.utils import capture\n", "import time\n", "import sys\n", "import fileinput\n", "from pyngrok import ngrok, conf\n", "import re\n", "\n", "\n", "Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n", "#@markdown - Offers better gradio responsivity\n", "\n", "Ngrok_token = \"\" #@param {type:\"string\"}\n", "\n", "#@markdown - Input your ngrok token if you want to use ngrok server\n", "\n", "User = \"\" #@param {type:\"string\"}\n", "Password= \"\" #@param {type:\"string\"}\n", "#@markdown - Add credentials to your Gradio interface (optional)\n", "\n", "auth=f\"--gradio-auth {User}:{Password}\"\n", "if User ==\"\" or Password==\"\":\n", " auth=\"\"\n", "\n", "\n", "with capture.capture_output() as cap:\n", " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n", " !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/extras.py\n", " !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n", " !wget -q -O /usr/local/lib/python3.10/dist-packages/gradio/blocks.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/AUTOMATIC1111_files/blocks.py\n", " %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n", "\n", " !sed -i 's@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title@shared.opts.data\\[\"sd_model_checkpoint\"] = checkpoint_info.title;model.half()@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/sd_models.py\n", " !sed -i 's@ui.create_ui().*@ui.create_ui();shared.demo.queue(concurrency_count=999999,status_update_rate=0.1)@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py\n", " !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n", "\n", " !sed -i 's@possible_sd_paths =.*@possible_sd_paths = [\\\"/content/gdrive/{mainpth}/sd/stablediffusion\\\"]@' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", " !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", " !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n", "\n", " !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n", " !sed -i 's@\\[\"sd_model_checkpoint\"\\]@\\[\"sd_model_checkpoint\", \"sd_vae\", \"CLIP_stop_at_last_layers\", \"inpainting_mask_weight\", \"initial_noise_multiplier\"\\]@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/shared.py\n", "\n", "share=''\n", "if Ngrok_token!=\"\":\n", " ngrok.kill()\n", " srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n", "\n", " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", " if line.strip().startswith('self.server_name ='):\n", " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", " if line.strip().startswith('self.protocol = \"https\"'):\n", " line = ' self.protocol = \"https\"\\n'\n", " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", " line = ''\n", " if line.strip().startswith('else \"http\"'):\n", " line = ''\n", " sys.stdout.write(line)\n", "\n", "elif Use_Cloudflare_Tunnel:\n", " with capture.capture_output() as cap:\n", " !pkill cloudflared\n", " time.sleep(4)\n", " !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n", " time.sleep(4)\n", " with open('/content/srv.txt', \"r\") as file: text = file.read()\n", " srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n", "\n", " for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n", " if line.strip().startswith('self.server_name ='):\n", " line = f' self.server_name = \"{srv[8:]}\"\\n'\n", " if line.strip().startswith('self.protocol = \"https\"'):\n", " line = ' self.protocol = \"https\"\\n'\n", " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n", " line = ''\n", " if line.strip().startswith('else \"http\"'):\n", " line = ''\n", " sys.stdout.write(line)\n", "\n", " !rm /content/srv.txt\n", "\n", "else:\n", " share='--share'\n", "\n", "ckptdir=''\n", "if os.path.exists('/content/temp_models'):\n", " ckptdir='--ckpt-dir /content/temp_models'\n", "\n", "try:\n", " model\n", " if os.path.isfile(model):\n", " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt \"$model\" --xformers $auth --disable-console-progressbars --upcast-sampling $ckptdir\n", " else:\n", " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --ckpt-dir \"$model\" --xformers $auth --disable-console-progressbars --upcast-sampling\n", "except:\n", " !python /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/webui.py $share --api --disable-safe-unpickle --enable-insecure-extension-access --no-download-sd-model --no-half-vae --xformers $auth --disable-console-progressbars --upcast-sampling $ckptdir" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }