Skip to content

Commit

Permalink
add ngrok tunnel feature, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddPn08 committed Sep 28, 2022
1 parent 8a2cfc8 commit 65ebe94
Showing 1 changed file with 90 additions and 17 deletions.
107 changes: 90 additions & 17 deletions automatic1111.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"id": "A6OFCYOzNjDX"
},
"source": [
"# Stable Diffusion WebUI Colab by [ddPn08](https://github.com/ddpn08/)\n",
"# [Stable Diffusion WebUI Colab](https://github.com/ddPn08/stable-diffusion-webui-colab) by [ddPn08](https://github.com/ddpn08/)\n",
"\n",
"This colab runs from the repo [`automatic1111`](https://github.com/AUTOMATIC1111/stable-diffusion-webui) \n",
"このColabは[`automatic1111`](https://github.com/AUTOMATIC1111/stable-diffusion-webui) を使用しています。\n"
Expand Down Expand Up @@ -75,7 +75,9 @@
"! git clone https://github.com/CompVis/taming-transformers.git repositories/taming-transformers\n",
"! git clone https://github.com/sczhou/CodeFormer.git repositories/CodeFormer\n",
"! git clone https://github.com/salesforce/BLIP.git repositories/BLIP\n",
"! pip install -r repositories/CodeFormer/requirements.txt"
"! pip install -r repositories/CodeFormer/requirements.txt\n",
"\n",
"! pip install pyngrok"
]
},
{
Expand All @@ -89,12 +91,31 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"cellView": "form",
"id": "Mls4_48XOrTd"
"id": "Mls4_48XOrTd",
"outputId": "e3c6d40b-f1a9-4b78-a580-adc9976f3103",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Local Path Variables:\n",
"\n",
"/content\n",
"Mounted at /content/drive\n",
"models_path: /content/drive/MyDrive/AI/models\n",
"output_path: /content/drive/MyDrive/AI/automatic1111/outputs\n",
"config_path: /content/drive/MyDrive/AI/automatic1111/config\n",
"embeddings_path: /content/drive/MyDrive/AI/textual-inversion/embeddings\n"
]
}
],
"source": [
"# @markdown # Load the stable-diffusion model\n",
"# @markdown > ### stable-diffusionのモデルをロード\n",
Expand All @@ -107,6 +128,7 @@
"models_path = \"/content/models\" # @param {type:\"string\"}\n",
"output_path = \"/content/output\" # @param {type:\"string\"}\n",
"config_path = \"/content/config\" # @param {type:\"string\"}\n",
"embeddings_path = \"/content/embeddings\" # @param {type:\"string\"}\n",
"\n",
"# @markdown **Download the model if it isn't already in the `models_path` folder (Optional)**\n",
"# @markdown > モデルが`models_path`フォルダーにない場合に、モデルをダウンロードする\n",
Expand Down Expand Up @@ -137,9 +159,11 @@
" models_path_gdrive = \"/content/drive/MyDrive/AI/models\" # @param {type:\"string\"}\n",
" output_path_gdrive = \"/content/drive/MyDrive/AI/automatic1111/outputs\" # @param {type:\"string\"}\n",
" config_path_gdrive = \"/content/drive/MyDrive/AI/automatic1111/config\" # @param {type:\"string\"}\n",
" embeddings_path_gdrive = \"/content/drive/MyDrive/AI/textual-inversion/embeddings\" # @param {type:\"string\"}\n",
" models_path = models_path_gdrive\n",
" output_path = output_path_gdrive\n",
" config_path = config_path_gdrive\n",
" embeddings_path = embeddings_path_gdrive\n",
" except:\n",
" print(\"...error mounting drive or with drive path variables\")\n",
" print(\"...reverting to default path variables\")\n",
Expand All @@ -148,6 +172,7 @@
"os.makedirs(models_path, exist_ok=True)\n",
"os.makedirs(output_path, exist_ok=True)\n",
"os.makedirs(config_path, exist_ok=True)\n",
"os.makedirs(embeddings_path, exist_ok=True)\n",
"\n",
"if not os.path.exists(f'{config_path}/config.json'):\n",
" with open(f'{config_path}/config.json', mode='w') as f:\n",
Expand All @@ -167,17 +192,36 @@
"\n",
"print(f\"models_path: {models_path}\")\n",
"print(f\"output_path: {output_path}\")\n",
"print(f\"config_path: {config_path}\")"
"print(f\"config_path: {config_path}\")\n",
"print(f\"embeddings_path: {embeddings_path}\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"cellView": "form",
"id": "DzMlOhl0Rerq"
"id": "DzMlOhl0Rerq",
"outputId": "057a6c25-8ff2-41b8-99b5-dc99d7eea537",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"outputs": [],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/content/stable-diffusion-webui\n",
" % Total % Received % Xferd Average Speed Time Time Time Current\n",
" Dload Upload Total Spent Left Speed\n",
" 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0\n",
" 71 332M 71 237M 0 0 35.1M 0 0:00:09 0:00:06 0:00:03 0\n",
"curl: Saved to filename 'GFPGANv1.3.pth'\n",
"curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err 1)\n"
]
}
],
"source": [
"# @markdown ## Download GFPGAN model\n",
"# @markdown **GFPGAN** Automatically correct distorted faces with a built-in GFPGAN option, fixes them in less than half a second\n",
Expand All @@ -198,7 +242,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"cellView": "form",
"id": "goUvyTZ4zd4l"
Expand All @@ -224,6 +268,8 @@
"# @markdown * Force-disables cross-attention layer optimization\n",
"# @markdown > クロスアテンションレイヤーの最適化を強制的に無効にします\n",
"\n",
"ngrok_proc = None\n",
"\n",
"run_string_with_variables = {\n",
" \"--no-half\": f\"{no_half}\",\n",
" \"--no-progressbar-hiding\": f\"{no_progressbar_hiding}\",\n",
Expand All @@ -232,8 +278,7 @@
" \"--disable-opt-split-attention\": f\"{disable_opt_split_attention}\"\n",
"}\n",
"\n",
"only_true_vars = {k for (k, v) in run_string_with_variables.items() if v == \"True\"}\n",
"vars = \" \".join(only_true_vars)"
"only_true_vars = {k for (k, v) in run_string_with_variables.items() if v == \"True\"}"
]
},
{
Expand All @@ -246,11 +291,31 @@
]
},
{
"cell_type": "markdown",
"source": [],
"cell_type": "code",
"source": [
"#@markdown # Start Ngrok Tunnel\n",
"#@markdown > Ngrokのトンネルを起動する\n",
"\n",
"use_ngrok = True # @param {type: \"boolean\"}\n",
"ngrok_auth_token = \"\" # @param {type: \"string\"}\n",
"ngrok_region = \"us\" # @param [\"us\", \"eu\", \"au\", \"ap\", \"sa\", \"jp\", \"in\"]\n",
"port = 7860 # @param {type: \"number\"}\n",
"\n",
"if use_ngrok:\n",
" from pyngrok import ngrok\n",
" if ngrok_proc:\n",
" ngrok_proc.proc.kill()\n",
" pyngrok_config = ngrok.conf.PyngrokConfig(auth_token=ngrok_auth_token,region=ngrok_region)\n",
" tunnel = ngrok.connect(f'localhost:{port}', pyngrok_config=pyngrok_config)\n",
" ngrok_proc = ngrok.get_ngrok_process()\n",
" print(tunnel)"
],
"metadata": {
"id": "Lo6vv603TiaF"
}
"cellView": "form",
"id": "Nfxj7FhHTVF8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
Expand All @@ -269,9 +334,17 @@
"\n",
"#@markdown ![](https://user-images.githubusercontent.com/71378929/189563599-6df78bcf-133b-41e8-a55d-8ca3783cd933.png)\n",
"\n",
"import os\n",
"\n",
"transformers_offline = True # @param {type: \"boolean\"}\n",
"os.environ['TRANSFORMERS_OFFLINE'] = \"1\" if transformers_offline else \"0\"\n",
"\n",
"vars = \" \".join(only_true_vars)\n",
"if not ngrok_proc:\n",
" vars += \" --share\"\n",
"\n",
"! git pull\n",
"! python webui.py \\\n",
" --share \\\n",
" --ckpt-dir {models_path} \\\n",
" --ckpt {models_path}/{model_filename} \\\n",
" --ui-config-file {config_path}/ui-config.json \\\n",
Expand Down

0 comments on commit 65ebe94

Please sign in to comment.