{ "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", "# --change log--\n", "\"\"\"\n", "V3.6 | 13.03.24\n", "Fixed selection window\n", "Dynamic update of memory display\n", "\"\"\"\n", "\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", " 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/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", "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", "\n", "# ==================== CSS ====================\n", "CSS_AC = \"\"\"\n", "\n", "\"\"\"\n", "\n", "display(HTML(CSS_AC))\n", "# ==================== CSS ====================\n", "\n", "\n", "# ================ AutoCleaner function ================\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", "\n", "def get_word_variant(n, variants):\n", " unit = abs(n) % 10\n", " tens = abs(n) % 100\n", " if tens in range(11, 15):\n", " return variants[2]\n", " elif unit == 1:\n", " return variants[0]\n", " elif unit in range(2, 5):\n", " return variants[1]\n", " else:\n", " return variants[2]\n", "\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", "