Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ngrok tunneling and authentication support #598

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions fast_stable_diffusion_AUTOMATIC1111.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "CFWtw-6EPrKi"
Expand Down Expand Up @@ -277,7 +277,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "ZGV_5H4xrOSp"
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -439,6 +451,22 @@
" 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 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 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",
Expand Down Expand Up @@ -474,18 +502,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": {
Expand All @@ -498,4 +525,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}