Skip to content

Commit

Permalink
feat: ⚡ Minimal things
Browse files Browse the repository at this point in the history
  • Loading branch information
Vidalnt committed Nov 20, 2024
1 parent 2e50385 commit 92dfe5a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
46 changes: 23 additions & 23 deletions assets/Applio.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -249,26 +256,19 @@
" 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",
" last_backup_timestamp is None\n",
" 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",
Expand All @@ -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",
Expand Down
48 changes: 22 additions & 26 deletions assets/Applio_NoUI.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@
"outputs": [],
"source": [
"# @title Train\n",
"# @markdown ### ➡️ Model Information\n",
"import threading\n",
"import time\n",
"import os\n",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -546,26 +550,19 @@
" 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",
" last_backup_timestamp is None\n",
" 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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 92dfe5a

Please sign in to comment.