Transformers
Inference Endpoints
File size: 13,584 Bytes
2d1ecea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "##~ AutoCleaner V3.6 CODE | BY: ANXETY   ~##\n",
        "\n",
        "import os\n",
        "import time\n",
        "import ipywidgets as widgets\n",
        "from ipywidgets import Label, Button, VBox, HBox\n",
        "from IPython.display import display, HTML\n",
        "\n",
        "\n",
        "#  ================= DETECT ENV =================\n",
        "def detect_environment():\n",
        "    free_plan = (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
        "    environments = {\n",
        "        'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
        "        'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\")\n",
        "    }\n",
        "\n",
        "    for env_var, (environment, path) in environments.items():\n",
        "        if env_var in os.environ:\n",
        "            return environment, path, free_plan\n",
        "\n",
        "env, root_path, free_plan = detect_environment()\n",
        "webui_path = f\"{root_path}/sdw\"\n",
        "#  ----------------------------------------------\n",
        "\n",
        "\n",
        "# ==================== CSS ====================\n",
        "CSS_AC = \"\"\"\n",
        "<style>\n",
        "/* General Styles */\n",
        "\n",
        "hr {\n",
        "    border-color: grey;\n",
        "    background-color: grey;\n",
        "    opacity: 0.25;\n",
        "}\n",
        "\n",
        ".instruction_AC {\n",
        "    font-family: cursive;\n",
        "    font-size: 18px;\n",
        "    color: grey;\n",
        "    user-select: none;\n",
        "    cursor: default;\n",
        "}\n",
        "\n",
        "\n",
        "/* Container style */\n",
        "\n",
        ".container_AC {\n",
        "    position: relative;\n",
        "    background-color: #232323;\n",
        "    width: 800px;\n",
        "    height: auto;\n",
        "    padding: 15px;\n",
        "    border-radius: 15px;\n",
        "    box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);\n",
        "    margin-bottom: 5px;\n",
        "    overflow: visible;\n",
        "}\n",
        "\n",
        ".container_AC::before {\n",
        "    position: absolute;\n",
        "    top: 5px;\n",
        "    right: 10px;\n",
        "    content: \"AutoCleanerV3.6\";\n",
        "    font-weight: bold;\n",
        "    font-size: 24px;\n",
        "    color: rgba(0, 0, 0, 0.2);\n",
        "}\n",
        "\n",
        ".container_AC::after {\n",
        "    position: absolute;\n",
        "    top: 30px;\n",
        "    right: 10px;\n",
        "    content: \"ANXETY\";\n",
        "    font-weight: bold;\n",
        "    font-size: 18px;\n",
        "    color: rgba(0, 0, 0, 0.2);\n",
        "}\n",
        "\n",
        ".custom-select-multiple_AC select {\n",
        "    padding: 10px;\n",
        "    font-family: cursive;\n",
        "    border: 1px solid #262626 !important;\n",
        "    border-radius: 10px;\n",
        "    color: white;\n",
        "    background-color: #1c1c1c;\n",
        "    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
        "}\n",
        "\n",
        ".output_AC {\n",
        "    padding: 10px;\n",
        "    height: auto;\n",
        "    border: 1px solid #262626;\n",
        "    border-radius: 10px;\n",
        "    background-color: #1c1c1c;\n",
        "    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
        "    width: auto;\n",
        "    box-sizing: border-box;\n",
        "}\n",
        "\n",
        ".output_message_AC {\n",
        "    font-family: cursive;\n",
        "    color: white !important;\n",
        "    font-size: 14px;\n",
        "    user-select: none;\n",
        "    cursor: default\n",
        "}\n",
        "\n",
        "\n",
        ".storage_info_AC {\n",
        "    padding: 5px 20px;\n",
        "    height: auto;\n",
        "    border: 1px solid #262626;\n",
        "    border-radius: 10px;\n",
        "    background-color: #1c1c1c;\n",
        "    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.5);\n",
        "    width: auto;\n",
        "    font-family: cursive;\n",
        "    color: #B2B2B2 !important;\n",
        "    font-size: 14px;\n",
        "    user-select: none;\n",
        "    cursor: default\n",
        "}\n",
        "\n",
        "\n",
        "/* Button and storage info layout */\n",
        ".lower_information_panel_AC {\n",
        "    display: flex;\n",
        "    align-items: center;\n",
        "    justify-content: space-between;\n",
        "}\n",
        "\n",
        "\n",
        "/* Button style */\n",
        "\n",
        ".button_AC {\n",
        "    width: auto;\n",
        "    font-family: cursive;\n",
        "    color: white !important;\n",
        "    font-size: 14px;\n",
        "    font-weight: bold;\n",
        "    height: 35px;\n",
        "    border-radius: 15px;\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, violet 90%);\n",
        "    background-size: 200% 200%;\n",
        "    background-position: left bottom;\n",
        "    transition: background 0.5s ease-in-out, transform 0.3s ease;\n",
        "}\n",
        "\n",
        ".button_AC:hover {\n",
        "    cursor: pointer;\n",
        "    background-size: 200% 200%;\n",
        "    background-position: right bottom;\n",
        "    transform: translateY(1px);\n",
        "}\n",
        "\n",
        ".button_execute_AC:hover {\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, #93ac47 90%);\n",
        "}\n",
        "\n",
        ".button_clear_AC:hover {\n",
        "    background-image: radial-gradient(circle at top left, purple 10%, #fc3468 90%);\n",
        "}\n",
        "\n",
        ".button_execute_AC:active,\n",
        ".button_clear_AC:active {\n",
        "    filter: brightness(0.75);\n",
        "}\n",
        "\n",
        ".jupyter-widgets.lm-Widget:focus {\n",
        "    outline: none;\n",
        "}\n",
        "\n",
        "\n",
        "/* Animation of elements */\n",
        "\n",
        "/* Emergence */\n",
        ".container_AC {\n",
        "    animation-name: slideInTopBlur;\n",
        "    animation-duration: 0.7s;\n",
        "    animation-fill-mode: forwards;\n",
        "}\n",
        "\n",
        "@keyframes slideInTopBlur {\n",
        "    0% {\n",
        "        transform: translate3d(0, 50%, 0) scale(0.85) rotate3d(1, 0, 0, -85deg);\n",
        "        filter: blur(5px) grayscale(1) brightness(0.5);\n",
        "        opacity: 0;\n",
        "    }\n",
        "    100% {\n",
        "        transform: translate3d(0, 0, 0) scale(1) rotate3d(1, 0, 0, 0deg);\n",
        "        filter: blur(0) grayscale(0) brightness(1);\n",
        "        opacity: 1;\n",
        "    }\n",
        "}\n",
        "\n",
        "/* Leaving */\n",
        ".container_AC.hide {\n",
        "    animation-name: slideOutTopBlur;\n",
        "    animation-duration: 0.3s;\n",
        "    animation-fill-mode: forwards;\n",
        "}\n",
        "\n",
        "@keyframes slideOutTopBlur {\n",
        "    0% {\n",
        "        transform: translate3d(0, 0, 0) scale(1);\n",
        "        filter: blur(0) grayscale(0) brightness(1);\n",
        "        opacity: 1;\n",
        "    }\n",
        "    100% {\n",
        "        transform: translate3d(0, -100%, 0);\n",
        "        filter: blur(5px) grayscale(1) brightness(0);\n",
        "        opacity: 0;\n",
        "    }\n",
        "}\n",
        "</style>\n",
        "\"\"\"\n",
        "\n",
        "display(HTML(CSS_AC))\n",
        "# ==================== CSS ====================\n",
        "\n",
        "\n",
        "# ================ AutoCleaner function ================\n",
        "directories = {\n",
        "    \"Изображения\": f\"{webui_path}/outputs\",\n",
        "    \"Модели\": f\"{webui_path}/models/Stable-diffusion/\",\n",
        "    \"Vae\": f\"{webui_path}/models/VAE/\",\n",
        "    \"LoRa\": f\"{webui_path}/models/Lora/\",\n",
        "    \"ControlNet Модели\": f\"{webui_path}/models/ControlNet/\"\n",
        "}\n",
        "\n",
        "\"\"\" functions \"\"\"\n",
        "def clean_directory(directory):\n",
        "    deleted_files = 0\n",
        "    for root, dirs, files in os.walk(directory):\n",
        "        for file in files:\n",
        "            if file.endswith(\".txt\"):\n",
        "                continue\n",
        "            os.remove(os.path.join(root, file))\n",
        "            if not file.endswith(\".yaml\"):\n",
        "                deleted_files += 1\n",
        "    return deleted_files\n",
        "\n",
        "def update_memory_info():\n",
        "    disk_space = psutil.disk_usage(os.getcwd())\n",
        "    total = disk_space.total / (1024 ** 3)\n",
        "    used = disk_space.used / (1024 ** 3)\n",
        "    free = disk_space.free / (1024 ** 3)\n",
        "\n",
        "    storage_info.value = f'''\n",
        "    <div class=\"storage_info_AC\">Всего: {total:.2f} GB <span style=\"color: #555\">|</span> Используется: {used:.2f} GB <span style=\"color: #555\">|</span> Свободно: {free:.2f} GB</div>\n",
        "    '''\n",
        "\n",
        "def on_execute_button_press(button):\n",
        "    selected_cleaners = auto_cleaner_widget.value\n",
        "    deleted_files_dict = {}\n",
        "\n",
        "    for option in selected_cleaners:\n",
        "        if option in directories:\n",
        "            deleted_files_dict[option] = clean_directory(directories[option])\n",
        "\n",
        "    output.clear_output()\n",
        "\n",
        "    with output:\n",
        "        for message in generate_messages(deleted_files_dict):\n",
        "            message_widget = HTML(f'<p class=\"output_message_AC\">{message}</p>')\n",
        "            display(message_widget)\n",
        "\n",
        "    update_memory_info()\n",
        "\n",
        "def on_clear_button_press(button):\n",
        "    container.add_class(\"hide\")\n",
        "    time.sleep(0.5)\n",
        "    widgets.Widget.close_all()\n",
        "\n",
        "def generate_messages(deleted_files_dict):\n",
        "    messages = []\n",
        "    word_variants = {\n",
        "        \"Изображения\": \"Изображений\",\n",
        "        \"Модели\": \"Моделей\",\n",
        "        \"Vae\": \"Vae\",\n",
        "        \"LoRa\": \"LoRa\",\n",
        "        \"ControlNet Модели\": \"ControlNet Моделей\"\n",
        "    }\n",
        "    for key, value in deleted_files_dict.items():\n",
        "        object_word = word_variants.get(key)\n",
        "        messages.append(f\"Удалено {value} {object_word}\")\n",
        "    return messages\n",
        "# ================ AutoCleaner function ================\n",
        "\n",
        "\n",
        "# --- storage memory ---\n",
        "import psutil\n",
        "disk_space = psutil.disk_usage(os.getcwd())\n",
        "total = disk_space.total / (1024 ** 3)\n",
        "used = disk_space.used / (1024 ** 3)\n",
        "free = disk_space.free / (1024 ** 3)\n",
        "\n",
        "\n",
        "# UI Code\n",
        "AutoCleaner_options = AutoCleaner_options = list(directories.keys())\n",
        "instruction_label = widgets.HTML('''\n",
        "<span class=\"instruction_AC\">Используйте <span style=\"color: #B2B2B2;\">ctrl</span> или <span style=\"color: #B2B2B2;\">shift</span> для множественного выбора.</span>\n",
        "''')\n",
        "auto_cleaner_widget = widgets.SelectMultiple(options=AutoCleaner_options, layout=widgets.Layout(width=\"auto\")).add_class(\"custom-select-multiple_AC\")\n",
        "output = widgets.Output().add_class(\"output_AC\")\n",
        "# ---\n",
        "execute_button = Button(description='Выполнить Очистку').add_class(\"button_execute_AC\").add_class(\"button_AC\")\n",
        "execute_button.on_click(on_execute_button_press)\n",
        "clear_button = Button(description='Скрыть Виджет').add_class(\"button_clear_AC\").add_class(\"button_AC\")\n",
        "clear_button.on_click(on_clear_button_press)\n",
        "# ---\n",
        "storage_info = widgets.HTML(f'''\n",
        "<div class=\"storage_info_AC\">Всего: {total:.2f} GB <span style=\"color: #555\">|</span> Используется: {used:.2f} GB <span style=\"color: #555\">|</span> Свободно: {free:.2f} GB</div>\n",
        "''')\n",
        "# ---\n",
        "buttons = widgets.HBox([execute_button, clear_button])\n",
        "lower_information_panel = widgets.HBox([buttons, storage_info]).add_class(\"lower_information_panel_AC\")\n",
        "\n",
        "container = VBox([instruction_label, widgets.HTML('<hr>'), auto_cleaner_widget, output, widgets.HTML('<hr>'), lower_information_panel]).add_class(\"container_AC\")\n",
        "\n",
        "display(container)"
      ],
      "metadata": {
        "id": "I22dFg7F2j3G"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}