From 7d48b49684485ea7e4de870929021c6ee72971b5 Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Wed, 23 Nov 2022 15:18:58 -0500 Subject: [PATCH 1/3] added support for ngrok, ngrok https, and ngrok enabled username/password for webui --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 47 +++++++++++++++++------ 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 09d88543..d9ffb0c9 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "cellView": "form", "id": "CFWtw-6EPrKi" @@ -277,7 +277,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "cellView": "form", "id": "ZGV_5H4xrOSp" @@ -390,9 +390,18 @@ "import sys\n", "import fileinput\n", "\n", + "\n", + "Tunneling_Provider = \"localtunnel\" #@param [\"localtunnel\", \"ngrok\"]\n", + "#@markdown - fill the below if you choose ngrok\n", + "\n", + "ngrok_auth_token = \"auth_token:webui_user:webui_pwd\" #@param {type:\"string\"}\n", + "ngrok_region = \"us\" #@param [\"us\", \"eu\", \"ap\", \"au\", \"sa\", \"jp\", \"in\"]\n", + "#@markdown - ngrok: recommended you manually enforce HTTPS, until this [webui PR](https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/4583/files) is approved, make the same edits in your own file. Make the edit and check the below:\n", + "ngrok_did_manually_edit_https = False #@param {type:\"boolean\"}\n", "Use_Gradio_Server = False #@param {type:\"boolean\"}\n", "#@markdown - Only if you have trouble connecting to the local server\n", "\n", + "\n", "Hypernetwork_Compatibility = False #@param {type:\"boolean\"}\n", "\n", "Enable_API = False #@param {type:\"boolean\"}\n", @@ -410,10 +419,6 @@ " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/ldm/modules\n", " !wget -O attention.py https://raw.githubusercontent.com/TheLastBen/fast-stable-diffusion/main/precompiled/attention.py\n", " \n", - " \n", - "with capture.capture_output() as cap: \n", - " if not os.path.exists('/tools/node/bin/lt'):\n", - " !npm install -g localtunnel\n", "\n", "with capture.capture_output() as cap: \n", " %cd /content/gdrive/MyDrive/sd/stable-diffusion-webui/\n", @@ -428,7 +433,14 @@ " !sed -i 's@min-height: 4.*@min-height: 5.5em;@g' /content/gdrive/MyDrive/sd/stable-diffusion-webui/style.css \n", " %cd /content\n", "\n", + "with capture.capture_output() as cap: \n", + " if not Use_Gradio_Server:\n", + " if Tunneling_Provider == 'localtunnel' and not os.path.exists('/tools/node/bin/lt'):\n", + " !npm install -g localtunnel\n", + " if Tunneling_Provider == 'ngrok' and not os.path.exists('/usr/local/bin/ngrok'):\n", + " !pip install pyngrok\n", "\n", + "ngrok=''\n", "share=''\n", "if Use_Gradio_Server:\n", " share='--share'\n", @@ -439,6 +451,20 @@ " line = ' self.server_port = server_port\\n'\n", " sys.stdout.write(line)\n", " clear_output()\n", + "\n", + "elif Tunneling_Provider == \"ngrok\":\n", + " share = ''\n", + " ngrok = f'--ngrok \"{ngrok_auth_token}\" --ngrok-region \"{ngrok_region}\"'\n", + " for line in fileinput.input('/usr/local/lib/python3.7/dist-packages/gradio/blocks.py', inplace=True):\n", + " if line.strip().startswith('self.server_name ='):\n", + " line = ' self.server_name = server_name\\n'\n", + " if line.strip().startswith('self.server_port ='):\n", + " line = f' self.server_port = \"{\"443\" if manually_set_ngrok_https else \"server_port\"}\" \\n'\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab') and manually_set_ngrok_https:\n", + " line = '' \n", + " if line.strip().startswith('else \"http\"') and manually_set_ngrok_https:\n", + " line = '' \n", + " sys.stdout.write(line)\n", " \n", "else:\n", " share=''\n", @@ -474,18 +500,17 @@ "try:\n", " model\n", " if os.path.isfile(model):\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --no-half-vae --ckpt \"$model\"\n", + " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $ngrok $api --disable-safe-unpickle --no-half-vae --ckpt \"$model\"\n", " else:\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --no-half-vae --ckpt-dir \"$model\"\n", + " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $ngrok $api --disable-safe-unpickle --no-half-vae --ckpt-dir \"$model\"\n", "except:\n", - " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $api --disable-safe-unpickle --no-half-vae " + " !python /content/gdrive/MyDrive/sd/stable-diffusion-webui/webui.py $share $ngrok $api --disable-safe-unpickle --no-half-vae " ] } ], "metadata": { "accelerator": "GPU", "colab": { - "collapsed_sections": [], "provenance": [] }, "kernelspec": { @@ -498,4 +523,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} +} \ No newline at end of file From 62087c4cc3a281179332dd900fa5eac6a759f420 Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Wed, 23 Nov 2022 16:08:26 -0500 Subject: [PATCH 2/3] better https name/understanding ngrok_did_manually_edit_https --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index d9ffb0c9..0e559e9c 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -459,10 +459,10 @@ " if line.strip().startswith('self.server_name ='):\n", " line = ' self.server_name = server_name\\n'\n", " if line.strip().startswith('self.server_port ='):\n", - " line = f' self.server_port = \"{\"443\" if manually_set_ngrok_https else \"server_port\"}\" \\n'\n", + " line = f' self.server_port = \"{\"443\" if ngrok_did_manually_edit_https else \"server_port\"}\" \\n'\n", " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab') and manually_set_ngrok_https:\n", " line = '' \n", - " if line.strip().startswith('else \"http\"') and manually_set_ngrok_https:\n", + " if line.strip().startswith('else \"http\"') and ngrok_did_manually_edit_https:\n", " line = '' \n", " sys.stdout.write(line)\n", " \n", From 3de531e552a6b6020996e7aa7eb0888b225db41c Mon Sep 17 00:00:00 2001 From: Michael Ramos Date: Wed, 23 Nov 2022 16:27:50 -0500 Subject: [PATCH 3/3] better handling of gradio files --- fast_stable_diffusion_AUTOMATIC1111.ipynb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fast_stable_diffusion_AUTOMATIC1111.ipynb b/fast_stable_diffusion_AUTOMATIC1111.ipynb index 0e559e9c..d5485248 100644 --- a/fast_stable_diffusion_AUTOMATIC1111.ipynb +++ b/fast_stable_diffusion_AUTOMATIC1111.ipynb @@ -460,11 +460,13 @@ " line = ' self.server_name = server_name\\n'\n", " if line.strip().startswith('self.server_port ='):\n", " line = f' self.server_port = \"{\"443\" if ngrok_did_manually_edit_https else \"server_port\"}\" \\n'\n", - " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab') and manually_set_ngrok_https:\n", + " if line.strip().startswith('if self.local_url.startswith(\"https\") or self.is_colab') and ngrok_did_manually_edit_https:\n", " line = '' \n", " if line.strip().startswith('else \"http\"') and ngrok_did_manually_edit_https:\n", " line = '' \n", " sys.stdout.write(line)\n", + "\n", + " !sed -i '13s@.*@ \"PUBLIC_SHARE_TRUE\": \"\u001b[32mConnected\",@' /usr/local/lib/python3.7/dist-packages/gradio/strings.py\n", " \n", "else:\n", " share=''\n",