Upload start.ipynb
Browse files- start.ipynb +115 -0
start.ipynb
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "code",
|
| 5 |
+
"execution_count": null,
|
| 6 |
+
"metadata": {},
|
| 7 |
+
"outputs": [],
|
| 8 |
+
"source": [
|
| 9 |
+
"#@markdown # Start Stable-Diffusion\n",
|
| 10 |
+
"from IPython.utils import capture\n",
|
| 11 |
+
"import time\n",
|
| 12 |
+
"import sys\n",
|
| 13 |
+
"import fileinput\n",
|
| 14 |
+
"from pyngrok import ngrok, conf\n",
|
| 15 |
+
"import re\n",
|
| 16 |
+
"\n",
|
| 17 |
+
"\n",
|
| 18 |
+
"Use_Cloudflare_Tunnel = False #@param {type:\"boolean\"}\n",
|
| 19 |
+
"#@markdown - Offers better gradio responsivity\n",
|
| 20 |
+
"\n",
|
| 21 |
+
"Ngrok_token = \"\" #@param {type:\"string\"}\n",
|
| 22 |
+
"\n",
|
| 23 |
+
"#@markdown - Input your ngrok token if you want to use ngrok server\n",
|
| 24 |
+
"\n",
|
| 25 |
+
"User = \"\" #@param {type:\"string\"}\n",
|
| 26 |
+
"Password= \"\" #@param {type:\"string\"}\n",
|
| 27 |
+
"#@markdown - Add credentials to your Gradio interface (optional)\n",
|
| 28 |
+
"\n",
|
| 29 |
+
"auth=f\"--gradio-auth {User}:{Password}\"\n",
|
| 30 |
+
"if User ==\"\" or Password==\"\":\n",
|
| 31 |
+
" auth=\"\"\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"\n",
|
| 34 |
+
"with capture.capture_output() as cap:\n",
|
| 35 |
+
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/\n",
|
| 36 |
+
" !wget -q -O extras.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/extras.py\n",
|
| 37 |
+
" !wget -q -O sd_models.py https://raw.githubusercontent.com/AUTOMATIC1111/stable-diffusion-w$blsaphemy/master/modules/sd_models.py\n",
|
| 38 |
+
" !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",
|
| 39 |
+
" %cd /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/\n",
|
| 40 |
+
"\n",
|
| 41 |
+
" !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",
|
| 42 |
+
" !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",
|
| 43 |
+
" !sed -i \"s@map_location='cpu'@map_location='cuda'@\" /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/extras.py\n",
|
| 44 |
+
"\n",
|
| 45 |
+
" !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",
|
| 46 |
+
" !sed -i 's@\\.\\.\\/@src/@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n",
|
| 47 |
+
" !sed -i 's@src/generative-models@generative-models@g' /content/gdrive/$mainpth/sd/stable-diffusion-w$blsaphemy/modules/paths.py\n",
|
| 48 |
+
"\n",
|
| 49 |
+
" !sed -i 's@print(\\\"No module.*@@' /content/gdrive/$mainpth/sd/stablediffusion/ldm/modules/diffusionmodules/model.py\n",
|
| 50 |
+
" !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",
|
| 51 |
+
"\n",
|
| 52 |
+
"share=''\n",
|
| 53 |
+
"if Ngrok_token!=\"\":\n",
|
| 54 |
+
" ngrok.kill()\n",
|
| 55 |
+
" srv=ngrok.connect(7860, pyngrok_config=conf.PyngrokConfig(auth_token=Ngrok_token) , bind_tls=True).public_url\n",
|
| 56 |
+
"\n",
|
| 57 |
+
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
|
| 58 |
+
" if line.strip().startswith('self.server_name ='):\n",
|
| 59 |
+
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
|
| 60 |
+
" if line.strip().startswith('self.protocol = \"https\"'):\n",
|
| 61 |
+
" line = ' self.protocol = \"https\"\\n'\n",
|
| 62 |
+
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
|
| 63 |
+
" line = ''\n",
|
| 64 |
+
" if line.strip().startswith('else \"http\"'):\n",
|
| 65 |
+
" line = ''\n",
|
| 66 |
+
" sys.stdout.write(line)\n",
|
| 67 |
+
"\n",
|
| 68 |
+
"elif Use_Cloudflare_Tunnel:\n",
|
| 69 |
+
" with capture.capture_output() as cap:\n",
|
| 70 |
+
" !pkill cloudflared\n",
|
| 71 |
+
" time.sleep(4)\n",
|
| 72 |
+
" !nohup cloudflared tunnel --url http://localhost:7860 > /content/srv.txt 2>&1 &\n",
|
| 73 |
+
" time.sleep(4)\n",
|
| 74 |
+
" with open('/content/srv.txt', \"r\") as file: text = file.read()\n",
|
| 75 |
+
" srv= re.findall(r\"https?://(?:\\S+?\\.)?trycloudflare\\.com\\S*\", text)[0]\n",
|
| 76 |
+
"\n",
|
| 77 |
+
" for line in fileinput.input('/usr/local/lib/python3.10/dist-packages/gradio/blocks.py', inplace=True):\n",
|
| 78 |
+
" if line.strip().startswith('self.server_name ='):\n",
|
| 79 |
+
" line = f' self.server_name = \"{srv[8:]}\"\\n'\n",
|
| 80 |
+
" if line.strip().startswith('self.protocol = \"https\"'):\n",
|
| 81 |
+
" line = ' self.protocol = \"https\"\\n'\n",
|
| 82 |
+
" if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab'):\n",
|
| 83 |
+
" line = ''\n",
|
| 84 |
+
" if line.strip().startswith('else \"http\"'):\n",
|
| 85 |
+
" line = ''\n",
|
| 86 |
+
" sys.stdout.write(line)\n",
|
| 87 |
+
"\n",
|
| 88 |
+
" !rm /content/srv.txt\n",
|
| 89 |
+
"\n",
|
| 90 |
+
"else:\n",
|
| 91 |
+
" share='--share'\n",
|
| 92 |
+
"\n",
|
| 93 |
+
"ckptdir=''\n",
|
| 94 |
+
"if os.path.exists('/content/temp_models'):\n",
|
| 95 |
+
" ckptdir='--ckpt-dir /content/temp_models'\n",
|
| 96 |
+
"\n",
|
| 97 |
+
"try:\n",
|
| 98 |
+
" model\n",
|
| 99 |
+
" if os.path.isfile(model):\n",
|
| 100 |
+
" !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",
|
| 101 |
+
" else:\n",
|
| 102 |
+
" !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",
|
| 103 |
+
"except:\n",
|
| 104 |
+
" !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"
|
| 105 |
+
]
|
| 106 |
+
}
|
| 107 |
+
],
|
| 108 |
+
"metadata": {
|
| 109 |
+
"language_info": {
|
| 110 |
+
"name": "python"
|
| 111 |
+
}
|
| 112 |
+
},
|
| 113 |
+
"nbformat": 4,
|
| 114 |
+
"nbformat_minor": 2
|
| 115 |
+
}
|