{ "cells": [ { "cell_type": "markdown", "id": "cde84736-33ea-41fb-97d6-801331d0cf88", "metadata": {}, "source": [ "# Automatic1111's Stable Diffusion WebUI - SageMaker Studio Lab Notebook\n", "\n", "This notebook on GitHub: https://github.com/wandaweb/stable-diffusion-webui-sagemaker \n", "Automatic1111's WebUI: https://github.com/AUTOMATIC1111/stable-diffusion-webui \n", "\n", "---\n", "Connect with us for updates! - https://pogscafe.bio.link" ] }, { "cell_type": "markdown", "id": "f137a625-b2e1-48d4-b115-74ff2fb0585a", "metadata": {}, "source": [ "## Installation" ] }, { "cell_type": "code", "execution_count": 2, "id": "b4e76687-4bd8-4c44-92d5-780c78741a1f", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "fatal: destination path 'stable-diffusion-webui' already exists and is not an empty directory.\n", "/home/studio-lab-user/Auto1111/stable-diffusion-webui\n", "HEAD is now at adadb4e3 Merge branch 'release_candidate'\n", "\u001b[31mERROR: Could not open requirements file: [Errno 2] No such file or directory: '-q'\u001b[0m\n", "Collecting package metadata (current_repodata.json): done\n", "Solving environment: done\n", "\n", "\n", "==> WARNING: A newer version of conda exists. <==\n", " current version: 4.10.3\n", " latest version: 24.3.0\n", "\n", "Please update conda by running\n", "\n", " $ conda update -n base conda\n", "\n", "\n", "\n", "# All requested packages already installed.\n", "\n" ] } ], "source": [ "!mkdir /home/studio-lab-user/Auto1111\n", "%cd /home/studio-lab-user/Auto1111\n", "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n", "%cd stable-diffusion-webui\n", "!git checkout tags/v1.9.0 # Remove this line to use the latest code\n", "!pip install -r -q requirements.txt\n", "!conda install -y conda-forge::glib" ] }, { "cell_type": "code", "execution_count": 3, "id": "c12a9940-8c09-4a1b-8ae0-c2ab77adb291", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Python 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:39:03) \n", "[GCC 11.3.0]\n", "Version: v1.9.0\n", "Commit hash: adadb4e3c7382bf3e4f7519126cd6c70f4f8557b\n", "Launching Web UI with arguments: --skip-torch-cuda-test --share\n", "no module 'xformers'. Processing without...\n", "no module 'xformers'. Processing without...\n", "No module 'xformers'. Proceeding without it.\n", "Loading weights [6ce0161689] from /home/studio-lab-user/Auto1111/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.safetensors\n", "Running on local URL: http://127.0.0.1:7860\n", "Creating model from config: /home/studio-lab-user/Auto1111/stable-diffusion-webui/configs/v1-inference.yaml\n", "Applying attention optimization: Doggettx... done.\n", "Model loaded in 34.3s (load weights from disk: 1.5s, create model: 0.5s, apply weights to model: 31.2s, apply half(): 0.1s, load textual inversion embeddings: 0.4s, calculate empty prompt: 0.5s).\n", "^C\n", "Interrupted with signal 2 in \n" ] } ], "source": [ "#!python launch.py --skip-torch-cuda-test --share # This won't work" ] }, { "cell_type": "markdown", "id": "d7eea923-e295-4eac-8b55-ecf774741aae", "metadata": {}, "source": [ "## Download a model to the temporary folder\n", "\n", "How to download any model from CivitAI - https://youtu.be/mbNZ5AWy0sc" ] }, { "cell_type": "code", "execution_count": 9, "id": "c51281d5-fbfb-42ed-8b34-c79ab58c6e0b", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "--2024-04-18 09:50:50-- https://civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com/model/2896350/wildcardxXLFusion.d8pf.safetensors?X-Amz-Expires=86400&response-content-disposition=attachment%3B%20filename%3D%22wildcardxXLFusion_fusionOG.safetensors%22&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=e01358d793ad6966166af8b3064953ad/20240418/us-east-1/s3/aws4_request&X-Amz-Date=20240418T094733Z&X-Amz-SignedHeaders=host&X-Amz-Signature=1f37579eb6cee65e1fa0667a7f88ecc1db5af3043ce0197a666f7f9dd74b7ed3\n", "Resolving civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com (civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com)... 104.18.8.90, 104.18.9.90, 2606:4700::6812:95a, ...\n", "Connecting to civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com (civitai-delivery-worker-prod.5ac0637cfd0766c97916cefa3764fbdf.r2.cloudflarestorage.com)|104.18.8.90|:443... connected.\n", "HTTP request sent, awaiting response... 200 OK\n", "Length: 7105370872 (6.6G)\n", "Saving to: '/tmp/model.safetensors'\n", "\n", "/tmp/model.safetens 100%[===================>] 6.62G 44.8MB/s in 2m 29s \n", "\n", "2024-04-18 09:53:19 (45.4 MB/s) - '/tmp/model.safetensors' saved [7105370872/7105370872]\n", "\n" ] } ], "source": [ "!wget \"https://civitai.com/api/download/models/456751\" \\\n", " -O /tmp/model.safetensors\n", "!ln -s /tmp/model.safetensors /home/studio-lab-user/Auto1111/stable-diffusion-webui/models/Stable-diffusion/" ] }, { "cell_type": "markdown", "id": "43c5d45d-40f0-465c-88a8-a525af3fa57a", "metadata": {}, "source": [ "# Start with Pinggy" ] }, { "cell_type": "code", "execution_count": null, "id": "e55f7804-de11-4a70-a489-d11177449346", "metadata": {}, "outputs": [], "source": [ "# Install SSH (only needs to run once)\n", "!conda config --add channels conda-forge\n", "!conda config --set channel_priority strict\n", "!conda install -y openssh" ] }, { "cell_type": "code", "execution_count": 10, "id": "856cc160-1cbf-408a-9298-a88ca4115de8", "metadata": { "collapsed": true, "jupyter": { "outputs_hidden": true }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/studio-lab-user/Auto1111/stable-diffusion-webui\n", "waiting for output\n", "Python 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:39:03) \n", "[GCC 11.3.0]\n", "Version: v1.9.0\n", "Commit hash: adadb4e3c7382bf3e4f7519126cd6c70f4f8557b\n", "Launching Web UI with arguments: --skip-torch-cuda-test\n", "Allocated port 6 for remote forward to localhost:7860\n", "😁 😁 😁\n", "URL: http://rnaup-3-20-229-229.a.free.pinggy.link\n", "😁 😁 😁\n", "\u001b[?1000l\u001b[?1002l\u001b[?1003l\u001b[?1006l\u001b[?2004l\u001b7\u001b[?47h\u001b[?1h\u001b=\u001b)0\u001b[H\u001b[2J\u001b[25;81H\u001b[1;1H\u001b[m\u001b]8;;\u001b\\ \u001b[2;1H \u001b[3;1H \u001b[4;1H \u001b[5;1H \u001b[6;1H \u001b[7;1H \u001b[8;1H \u001b[9;1H ┌────────────────────────────┐ \u001b[10;1H │ │ \u001b[11;1H │ Wait while we prepare the │ \u001b[12;1H │ UI │ \u001b[13;1H │ │ \u001b[14;1H │ │ \u001b[15;1H │ │ \u001b[16;1H └────────────────────────────┘ \u001b[17;1H \u001b[18;1H \u001b[19;1H \u001b[20;1H \u001b[21;1H \u001b[22;1H \u001b[23;1H \u001b[24;1H \u001b[25;81H\u001b[25;81H\u001b[25;81H\u001b[25;81H\u001b[m\u001b]8;;\u001b\\\u001b[H\u001b[2J\u001b[9;26H\u001b[m\u001b]8;;\u001b\\┌────────────────────────────┐\u001b[10;26H│\u001b[10;55H│\u001b[11;26H│\u001b[11;28HWait\u001b[11;33Hwhile\u001b[11;39Hwe\u001b[11;42Hprepare\u001b[11;50Hthe\u001b[11;55H│\u001b[12;26H│\u001b[12;40HUI\u001b[12;55H│\u001b[13;26H│\u001b[13;55H│\u001b[14;26H│\u001b[14;55H│\u001b[15;26H│\u001b[15;55H│\u001b[16;26H└────────────────────────────┘\u001b[25;81H\u001b[25;81H\u001b[1;28H\u001b[m\u001b]8;;\u001b\\You\u001b[1;32Hare\u001b[1;36Hnot\u001b[1;40Hauthenticated.\u001b[2;1HYour\u001b[2;6Htunnel\u001b[2;13Hwill\u001b[2;18Hexpire\u001b[2;25Hin\u001b[2;28H60\u001b[2;31Hminutes.\u001b[2;40HUpgrade\u001b[2;48Hto\u001b[2;51HPinggy\u001b[2;58HPro\u001b[2;62Hto\u001b[2;65Hget\u001b[2;69Hunrestricted\u001b[3;23Htunnels.\u001b[3;32Hhttps://dashboard.pinggy.io\u001b[5;4Hhttp://rnaup-3-20-229-229.a.free.pinggy.link\u001b[6;4Hhttps://rnaup-3-20-229-229.a.free.pinggy.link\u001b[9;26H \u001b[10;26H \u001b[10;55H \u001b[11;26H \u001b[11;28H \u001b[11;33H \u001b[11;39H \u001b[11;42H \u001b[11;50H \u001b[11;55H \u001b[12;26H \u001b[12;40H \u001b[12;55H \u001b[13;26H \u001b[13;55H \u001b[14;26H \u001b[14;55H \u001b[15;26H \u001b[15;55H \u001b[16;26H \u001b[24;28HPress\u001b[24;34H`h`\u001b[24;38Hfor\u001b[24;42Hkeybindings\u001b[25;81H\u001b[25;81H\u001b[25;81H\n", "connect_to localhost port 7860: failed.\n", "connect_to localhost port 7860: failed.\n", "connect_to localhost port 7860: failed.\n", "connect_to localhost port 7860: failed.\n", "no module 'xformers'. Processing without...\n", "no module 'xformers'. Processing without...\n", "No module 'xformers'. Proceeding without it.\n", "Calculating sha256 for /home/studio-lab-user/Auto1111/stable-diffusion-webui/models/Stable-diffusion/model.safetensors: Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n", "Startup time: 20.2s (prepare environment: 0.2s, import torch: 9.5s, import gradio: 2.2s, setup paths: 5.1s, initialize shared: 0.6s, other imports: 1.4s, load scripts: 0.4s, create ui: 0.6s, gradio launch: 0.1s).\n", "changing setting sd_model_checkpoint to model.safetensors: AttributeError\n", "Traceback (most recent call last):\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/options.py\", line 165, in set\n", " option.onchange()\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/call_queue.py\", line 13, in f\n", " res = func(*args, **kwargs)\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/initialize_util.py\", line 181, in \n", " shared.opts.onchange(\"sd_model_checkpoint\", wrap_queued_call(lambda: sd_models.reload_model_weights()), call=False)\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/sd_models.py\", line 860, in reload_model_weights\n", " sd_model = reuse_model_from_already_loaded(sd_model, checkpoint_info, timer)\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/sd_models.py\", line 793, in reuse_model_from_already_loaded\n", " send_model_to_cpu(sd_model)\n", " File \"/home/studio-lab-user/Auto1111/stable-diffusion-webui/modules/sd_models.py\", line 662, in send_model_to_cpu\n", " if m.lowvram:\n", "AttributeError: 'NoneType' object has no attribute 'lowvram'\n", "\n", "22ebc61141bb5afbe0520ceb498cbdfea747096b88438e13837485466ce9b972\n", "Loading weights [22ebc61141] from /home/studio-lab-user/Auto1111/stable-diffusion-webui/models/Stable-diffusion/model.safetensors\n", "Creating model from config: /home/studio-lab-user/Auto1111/stable-diffusion-webui/repositories/generative-models/configs/inference/sd_xl_base.yaml\n", "vocab.json: 100%|████████████████████████████| 961k/961k [00:00<00:00, 38.0MB/s]\n", "merges.txt: 100%|████████████████████████████| 525k/525k [00:00<00:00, 22.0MB/s]\n", "special_tokens_map.json: 100%|██████████████████| 389/389 [00:00<00:00, 244kB/s]\n", "tokenizer_config.json: 100%|████████████████████| 905/905 [00:00<00:00, 570kB/s]\n", "config.json: 100%|██████████████████████████| 4.52k/4.52k [00:00<00:00, 773kB/s]\n", "Applying attention optimization: Doggettx... done.\n", "Model loaded in 26.5s (calculate hash: 20.7s, create model: 1.2s, apply weights to model: 2.7s, apply half(): 0.1s, load textual inversion embeddings: 0.6s, calculate empty prompt: 1.0s).\n", "Downloading VAEApprox model to: /home/studio-lab-user/Auto1111/stable-diffusion-webui/models/VAE-approx/vaeapprox-sdxl.pt\n", "100%|████████████████████████████████████████| 209k/209k [00:00<00:00, 63.2MB/s]\n", " 0%| | 0/20 [00:00\u001b[0;34m()\u001b[0m\n\u001b[1;32m 43\u001b[0m \u001b[0mp_app\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 44\u001b[0m \u001b[0mp_url\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 45\u001b[0;31m \u001b[0mp_app\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 46\u001b[0m \u001b[0mp_url\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/.conda/envs/default/lib/python3.9/multiprocessing/process.py\u001b[0m in \u001b[0;36mjoin\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 147\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_pid\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a child process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 148\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a started process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 149\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 150\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 151\u001b[0m \u001b[0m_children\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdiscard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/.conda/envs/default/lib/python3.9/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 41\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[0;31m# This shouldn't block if wait() returned successfully.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 43\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mWNOHANG\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0.0\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 44\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m~/.conda/envs/default/lib/python3.9/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mpoll\u001b[0;34m(self, flag)\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 27\u001b[0;31m \u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflag\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 28\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0;31m# Child process not yet created. See #1731717\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mKeyboardInterrupt\u001b[0m: " ] }, { "name": "stdout", "output_type": "stream", "text": [ "Connection to a.pinggy.io closed by remote host.\n", "Connection to a.pinggy.io closed.\n" ] } ], "source": [ "# Start the WebUI with Pinggy\n", "%cd /home/studio-lab-user/Auto1111/stable-diffusion-webui\n", "command = 'python launch.py --skip-torch-cuda-test'\n", "port = '7860'\n", "# ------------------------\n", "\n", "from multiprocessing import Process\n", "import sys\n", "import time\n", "\n", "!touch log.txt\n", "open('log.txt', 'w').close()\n", "\n", "def run_app():\n", " get_ipython().system(f'{command} & ssh -o StrictHostKeyChecking=no -p 80 -R0:localhost:{port} a.pinggy.io > log.txt')\n", " \n", "def print_url():\n", " print(\"waiting for output\")\n", " time.sleep(2)\n", " sys.stdout.flush()\n", " \n", " found = False\n", " with open('log.txt', 'r') as file:\n", " end_word = '.pinggy.link'\n", " for line in file:\n", " #print(line)\n", " start_index = line.find('http:')\n", " if start_index != -1:\n", " end_index = line.find(end_word, start_index)\n", " if end_index != -1:\n", " print('😁 😁 😁')\n", " print('URL: ' + line[start_index:end_index + len(end_word)])\n", " print('😁 😁 😁')\n", " found = True\n", " if not found:\n", " print_url()\n", " else:\n", " with open('log.txt', 'r') as file:\n", " for line in file:\n", " print(line)\n", " \n", "p_app = Process(target=run_app)\n", "p_url = Process(target=print_url)\n", "p_app.start()\n", "p_url.start()\n", "p_app.join()\n", "p_url.join()" ] }, { "cell_type": "markdown", "id": "728f0f89-deb5-490c-8a0a-21190067fa68", "metadata": {}, "source": [ "# Start with Zrok" ] }, { "cell_type": "markdown", "id": "f4391dac-9f37-4e87-bfcc-9d70b7c051ca", "metadata": {}, "source": [ "### Install Zrok (only needs to run once)" ] }, { "cell_type": "code", "execution_count": null, "id": "d3f761df-f02d-47d8-8588-b5118d11f8f1", "metadata": {}, "outputs": [], "source": [ "# Install Zrok (only needs to run once)\n", "\n", "!mkdir /home/studio-lab-user/zrok\n", "%cd /home/studio-lab-user/zrok\n", "!wget https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz\n", "!tar -xvf ./zrok*.gz \n", "!chmod a+x /home/studio-lab-user/zrok/zrok " ] }, { "cell_type": "markdown", "id": "bf602587-2ea5-4726-a662-3d89ec82cd97", "metadata": {}, "source": [ "### Create a Zrok account\n", "Enter your email address in the email variable" ] }, { "cell_type": "code", "execution_count": null, "id": "80d0d756-9a6e-4aac-bdc7-4bee9647d528", "metadata": {}, "outputs": [], "source": [ "email = '####@gmail.com' # replace with your email\n", "\n", "cmd = '/home/studio-lab-user/zrok/zrok invite'\n", "log = '/home/studio-lab-user/zrok/log.txt'\n", "\n", "!pip install pexpect\n", "!touch $log\n", "\n", "import pexpect\n", "import time\n", "child = pexpect.spawn('bash')\n", "child.sendline(f'{cmd} | tee {log}')\n", "child.expect('enter and confirm your email address...')\n", "time.sleep(1); child.sendline(email); time.sleep(1); child.send(chr(9)); time.sleep(1)\n", "child.sendline(email); time.sleep(1); child.send('\\n'); time.sleep(1); child.send(chr(9))\n", "time.sleep(1); child.send('\\r\\n'); time.sleep(2); child.close()\n", "!cat $log\n", "!rm $log" ] }, { "cell_type": "markdown", "id": "0fd14c5f-918c-4f99-8b82-f99780e39e48", "metadata": {}, "source": [ "### Enable Zrok (only needs to run once)\n", "Paste your Zrok token in the token variable" ] }, { "cell_type": "code", "execution_count": null, "id": "b7befdfa-3c1b-41cc-9619-51f2c168bad9", "metadata": {}, "outputs": [], "source": [ "# Enable Zrok (only neeeds to run once)\n", "# Paste your Zrok token in the token variable\n", "\n", "token = \"\"\n", "\n", "!/home/studio-lab-user/zrok/zrok enable $token" ] }, { "cell_type": "markdown", "id": "ce49c4d6-f959-4655-9832-d890746db1c0", "metadata": {}, "source": [ "### Start the WebUI with Zrok" ] }, { "cell_type": "code", "execution_count": null, "id": "a08e5d9b-4cea-4179-99ac-951ec9b6485e", "metadata": {}, "outputs": [], "source": [ "# Start the WebUI with Zrok\n", "%cd /home/studio-lab-user/Auto1111/stable-diffusion-webui\n", "command = 'python launch.py --skip-torch-cuda-test'\n", "port = '7860'\n", "# ------------------------\n", "\n", "cmd = f'{command} & /home/studio-lab-user/zrok/zrok share public http://localhost:{port} --headless'\n", "get_ipython().system(cmd)" ] } ], "metadata": { "kernelspec": { "display_name": "default:Python", "language": "python", "name": "conda-env-default-py" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.16" } }, "nbformat": 4, "nbformat_minor": 5 }