File size: 5,363 Bytes
eae4fd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "VBDPqhYnyBL1"
      },
      "source": [
        "Check GPU"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "woQCdVO8x-Kt"
      },
      "outputs": [],
      "source": [
        "!nvidia-smi"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OHCtG9MT0jLq"
      },
      "source": [
        "Clone webui repository and download the model."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ZzRNMT42Gw_p"
      },
      "outputs": [],
      "source": [
        "%cd /content\n",
        "!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n",
        "%cd stable-diffusion-webui\n",
        "!git pull\n",
        "!mkdir -p /content/stable-diffusion-webui/models/Stable-diffusion\n",
        "%cd /content/stable-diffusion-webui/models/Stable-diffusion/\n",
        "!apt install -y -qq aria2\n",
        "!aria2c --summary-interval=10 -x 16 -s 16 --allow-overwrite=true -Z https://huggingface.co./JosephusCheung/ACertainModel/resolve/main/ACertainModel-half.ckpt\n",
        "%cd /content\n",
        "!aria2c --summary-interval=10 -x 16 -s 16 --allow-overwrite=true -Z https://huggingface.co./JosephusCheung/ACertainModel/resolve/main/animevae.pt"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "xt8lbdmC04ox"
      },
      "source": [
        "Launch web ui. You will get a link to nnn.gradio.app, follow it.\n",
        "\n",
        "Commandline arguments are:\n",
        "  - `--share` - create online gradio.app link\n",
        "  - `--gradio-debug` - print outputs to console\n",
        "  - `--gradio-auth me:qwerty` - add authentication to gradio: username me, password qwerty"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "R-xAdMA5wxXd",
        "outputId": "c3f7f6fe-7769-452d-9433-3023c156a244"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Interrupted with signal 2 in <frame at 0x7f1864c71cf0, file '/usr/local/lib/python3.8/dist-packages/gradio/blocks.py', line 1559, code block_thread>\n"
          ]
        }
      ],
      "source": [
        "%cd /content/stable-diffusion-webui\n",
        "\n",
        "# hacks to load model in colab\n",
        "!sed -i 's/map_location=\"cpu\"/map_location=\"cuda\"/g' /content/stable-diffusion-webui/modules/sd_models.py\n",
        "\n",
        "!pip install -U -qq pip\n",
        "!pip install -qq -r requirements.txt\n",
        "!pip install -qq -U --pre triton\n",
        "!pip install -qq pytorch_lightning==1.7.7\n",
        "!pip install https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+189828c.d20221207-cp38-cp38-linux_x86_64.whl\n",
        "!echo \"\" > /tmp/requirements_empty.txt\n",
        "!COMMANDLINE_ARGS=\"--xformers --share --gradio-debug --vae-path /content/animevae.pt\" REQS_FILE=\"/tmp/requirements_empty.txt\" python launch.py"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "T3957x2AY7iP"
      },
      "source": [
        "commands for ***after*** you have gotten done with a session\n",
        "============================================================================"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "aCtJffM2ZE06"
      },
      "source": [
        "Zip images for downloading on local drive (click the folder icon on the left, the one below {x})"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "TmRqNyiAZCHu"
      },
      "outputs": [],
      "source": [
        "!zip -r /content/stable-diffusion-webui /content/stable-diffusion-webui/outputs "
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tcslU-S2ZNr9"
      },
      "source": [
        "Save images to Google Drive **Warning: this will cause google to scan your drive, so if you intend to use this and worry about that kind of stuff, probablly just set this up on a clean account that's just for this colab**"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "-N0lnu-TZOTW"
      },
      "outputs": [],
      "source": [
        "from google.colab import drive # type: ignore\n",
        "\n",
        "try:\n",
        "   drive_path = \"/content/drive\"\n",
        "   drive.mount(drive_path,force_remount=False)\n",
        "except:\n",
        "   print(\"...error mounting drive or with drive path variables\")\n",
        "\n",
        "!cp -r \"/content/stable-diffusion-webui/outputs\" \"/content/drive/MyDrive\""
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "provenance": []
    },
    "gpuClass": "premium",
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}