From 92dfe5ae7a6a5389659327f4b86b8a4b591a561c Mon Sep 17 00:00:00 2001 From: Vidalnt Date: Wed, 20 Nov 2024 17:10:39 -0500 Subject: [PATCH] feat: :zap: Minimal things --- assets/Applio.ipynb | 46 +++++++++++++++++++------------------- assets/Applio_NoUI.ipynb | 48 ++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/assets/Applio.ipynb b/assets/Applio.ipynb index c733c471..48099fb3 100644 --- a/assets/Applio.ipynb +++ b/assets/Applio.ipynb @@ -207,13 +207,17 @@ "source": [ "# @title Auto Backup\n", "# @markdown When running it, it will be activated or deactivated previously to start up together with Applio.\n", + "import os\n", + "import shutil\n", + "import time\n", + "\n", "LOGS_FOLDER = \"/content/program_ml/logs/\"\n", "GOOGLE_DRIVE_PATH = \"/content/drive/MyDrive/ApplioBackup\"\n", "\n", "if \"autobackups\" not in globals():\n", " autobackups = False\n", "\n", - "\n", + "cooldown = 15 # @param {type:\"slider\", min:0, max:100, step:0}\n", "def backup_files():\n", " print(\"\\nStarting backup loop...\")\n", " last_backup_timestamps_path = os.path.join(\n", @@ -223,7 +227,9 @@ "\n", " while True:\n", " try:\n", - " updated = False\n", + " updated_files = 0\n", + " deleted_files = 0\n", + " new_files = 0\n", " last_backup_timestamps = {}\n", "\n", " try:\n", @@ -233,11 +239,12 @@ " pass\n", "\n", " for root, dirs, files in os.walk(LOGS_FOLDER):\n", - " # Excluding \"zips\" directory\n", + " # Excluding \"zips\" and \"mute\" directories\n", " if \"zips\" in dirs:\n", " dirs.remove(\"zips\")\n", " if \"mute\" in dirs:\n", " dirs.remove(\"mute\")\n", + "\n", " for filename in files:\n", " if filename != \"last_backup_timestamps.txt\":\n", " filepath = os.path.join(root, filename)\n", @@ -249,10 +256,6 @@ " backup_folderpath = os.path.dirname(backup_filepath)\n", " if not os.path.exists(backup_folderpath):\n", " os.makedirs(backup_folderpath)\n", - " print(\n", - " f\"Created backup folder: {backup_folderpath}\",\n", - " flush=True,\n", - " )\n", " last_backup_timestamp = last_backup_timestamps.get(filepath)\n", " current_timestamp = os.path.getmtime(filepath)\n", " if (\n", @@ -260,15 +263,12 @@ " or float(last_backup_timestamp) < current_timestamp\n", " ):\n", " shutil.copy2(filepath, backup_filepath)\n", - " last_backup_timestamps[filepath] = str(\n", - " current_timestamp\n", - " )\n", + " last_backup_timestamps[filepath] = str(current_timestamp)\n", " if last_backup_timestamp is None:\n", - " print(f\"Backed up file: {filename}\")\n", + " new_files += 1\n", " else:\n", - " print(f\"Updating backed up file: {filename}\")\n", - " updated = True\n", - " fully_updated = False\n", + " updated_files += 1\n", + "\n", "\n", " for filepath in list(last_backup_timestamps.keys()):\n", " if not os.path.exists(filepath):\n", @@ -277,26 +277,26 @@ " )\n", " if os.path.exists(backup_filepath):\n", " os.remove(backup_filepath)\n", - " print(f\"Deleted file: {filepath}\")\n", + " deleted_files += 1\n", " del last_backup_timestamps[filepath]\n", - " updated = True\n", - " fully_updated = False\n", "\n", - " if not updated and not fully_updated:\n", + "\n", + " if updated_files > 0 or deleted_files > 0 or new_files > 0:\n", + " print(f\"Backup Complete: {new_files} new, {updated_files} updated, {deleted_files} deleted.\")\n", + " fully_updated = False\n", + " elif not fully_updated:\n", " print(\"Files are up to date.\")\n", " fully_updated = True\n", - " sleep_time = 15\n", - " else:\n", - " sleep_time = 0.1\n", "\n", " with open(last_backup_timestamps_path, \"w\") as f:\n", " for filepath, timestamp in last_backup_timestamps.items():\n", " f.write(f\"{filepath}:{timestamp}\\n\")\n", "\n", - " time.sleep(sleep_time)\n", + " time.sleep(cooldown if fully_updated else 0.1)\n", + "\n", "\n", " except Exception as error:\n", - " print(f\"An error occurred during backup: {error}\", flush=True)\n", + " print(f\"An error occurred during backup: {error}\")\n", "\n", "\n", "if autobackups:\n", diff --git a/assets/Applio_NoUI.ipynb b/assets/Applio_NoUI.ipynb index 27167f66..02574ad1 100644 --- a/assets/Applio_NoUI.ipynb +++ b/assets/Applio_NoUI.ipynb @@ -470,7 +470,6 @@ "outputs": [], "source": [ "# @title Train\n", - "# @markdown ### ➡️ Model Information\n", "import threading\n", "import time\n", "import os\n", @@ -510,8 +509,9 @@ "\n", "if \"autobackups\" not in globals():\n", " autobackups = False\n", - "\n", - "\n", + "# @markdown ### 💾 AutoBackup\n", + "cooldown = 15 # @param {type:\"slider\", min:0, max:100, step:0}\n", + "auto_backups = True # @param{type:\"boolean\"}\n", "def backup_files():\n", " print(\"\\nStarting backup loop...\")\n", " last_backup_timestamps_path = os.path.join(\n", @@ -521,7 +521,9 @@ "\n", " while True:\n", " try:\n", - " updated = False\n", + " updated_files = 0\n", + " deleted_files = 0\n", + " new_files = 0\n", " last_backup_timestamps = {}\n", "\n", " try:\n", @@ -531,10 +533,12 @@ " pass\n", "\n", " for root, dirs, files in os.walk(LOGS_FOLDER):\n", + " # Excluding \"zips\" and \"mute\" directories\n", " if \"zips\" in dirs:\n", " dirs.remove(\"zips\")\n", " if \"mute\" in dirs:\n", " dirs.remove(\"mute\")\n", + "\n", " for filename in files:\n", " if filename != \"last_backup_timestamps.txt\":\n", " filepath = os.path.join(root, filename)\n", @@ -546,10 +550,6 @@ " backup_folderpath = os.path.dirname(backup_filepath)\n", " if not os.path.exists(backup_folderpath):\n", " os.makedirs(backup_folderpath)\n", - " print(\n", - " f\"Created backup folder: {backup_folderpath}\",\n", - " flush=True,\n", - " )\n", " last_backup_timestamp = last_backup_timestamps.get(filepath)\n", " current_timestamp = os.path.getmtime(filepath)\n", " if (\n", @@ -557,15 +557,12 @@ " or float(last_backup_timestamp) < current_timestamp\n", " ):\n", " shutil.copy2(filepath, backup_filepath)\n", - " last_backup_timestamps[filepath] = str(\n", - " current_timestamp\n", - " )\n", + " last_backup_timestamps[filepath] = str(current_timestamp)\n", " if last_backup_timestamp is None:\n", - " print(f\"Backed up file: {filename}\")\n", + " new_files += 1\n", " else:\n", - " print(f\"Updating backed up file: {filename}\")\n", - " updated = True\n", - " fully_updated = False\n", + " updated_files += 1\n", + "\n", "\n", " for filepath in list(last_backup_timestamps.keys()):\n", " if not os.path.exists(filepath):\n", @@ -574,26 +571,26 @@ " )\n", " if os.path.exists(backup_filepath):\n", " os.remove(backup_filepath)\n", - " print(f\"Deleted file: {filepath}\")\n", + " deleted_files += 1\n", " del last_backup_timestamps[filepath]\n", - " updated = True\n", - " fully_updated = False\n", "\n", - " if not updated and not fully_updated:\n", + "\n", + " if updated_files > 0 or deleted_files > 0 or new_files > 0:\n", + " print(f\"Backup Complete: {new_files} new, {updated_files} updated, {deleted_files} deleted.\")\n", + " fully_updated = False\n", + " elif not fully_updated:\n", " print(\"Files are up to date.\")\n", " fully_updated = True\n", - " sleep_time = 15\n", - " else:\n", - " sleep_time = 0.1\n", "\n", " with open(last_backup_timestamps_path, \"w\") as f:\n", " for filepath, timestamp in last_backup_timestamps.items():\n", " f.write(f\"{filepath}:{timestamp}\\n\")\n", "\n", - " time.sleep(sleep_time)\n", + " time.sleep(cooldown if fully_updated else 0.1)\n", + "\n", "\n", " except Exception as error:\n", - " print(f\"An error occurred during backup: {str(error)}\")\n", + " print(f\"An error occurred during backup: {error}\")\n", "\n", "\n", "if autobackups:\n", @@ -602,12 +599,11 @@ "else:\n", " autobackups = True\n", " print(\"Autobackup Enabled\") \n", - "\n", + "# @markdown ### ⚙️ Train Settings\n", "total_epoch = 800 # @param {type:\"integer\"}\n", "batch_size = 15 # @param {type:\"slider\", min:1, max:25, step:0}\n", "gpu = 0\n", "sr = int(sample_rate.rstrip(\"k\")) * 1000\n", - "auto_backups = True # @param{type:\"boolean\"}\n", "pretrained = True # @param{type:\"boolean\"}\n", "cleanup = False # @param{type:\"boolean\"}\n", "cache_data_in_gpu = False # @param{type:\"boolean\"}\n",