{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "JKTCrY9LU7Oq" }, "outputs": [], "source": [ "##~ AutoCleaner V3.7 CODE | BY: ANXETY ~##\n", "\n", "from directory_setup import models_dir, vaes_dir, control_dir, loras_dir, output_dir\n", "\n", "import os\n", "import time\n", "from ipywidgets import widgets\n", "from IPython.display import display, HTML\n", "\n", "\n", "# Setup Env\n", "env = os.getenv('ENV_NAME')\n", "root_path = os.getenv('ROOT_PATH')\n", "webui_path = os.getenv('WEBUI_PATH')\n", "free_plan = os.getenv('FREE_PLAN')\n", "\n", "\n", "# ==================== CSS ====================\n", "# Main CSS\n", "css_file_path = f\"{root_path}/CSS/auto_cleaner.css\"\n", "with open(css_file_path , \"r\") as f:\n", " CSS_AC = f.read()\n", "display(HTML(f\"\"))\n", "\n", "\n", "# ================ AutoCleaner function ================\n", "directories = {\n", " \"Изображения\": output_dir,\n", " \"Модели\": models_dir,\n", " \"Vae\": vaes_dir,\n", " \"LoRa\": loras_dir,\n", " \"ControlNet Модели\": control_dir\n", "}\n", "\n", "\"\"\" functions \"\"\"\n", "def clean_directory(directory, directory_type):\n", " deleted_files = 0\n", "\n", " for root, dirs, files in os.walk(directory):\n", " for file in files:\n", " file_path = os.path.join(root, file)\n", "\n", " if file.endswith(\".txt\"):\n", " continue\n", " if file.endswith((\".safetensors\", \".pt\")) or directory_type == \"Images\":\n", " deleted_files += 1\n", "\n", " os.remove(file_path)\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", "