File size: 5,956 Bytes
2b53eee |
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 |
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4",
"authorship_tag": "ABX9TyP4Z6m49+bXNW/J1fP7ZIEB",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/DrewThomasson/xtts-finetune-webui/blob/main/notebook/xtts_finetune_webui.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"## Welcome to the *xtts*-finetune-webui gradio gui!\n",
"\n",
"This webui is a slightly modified copy of the official webui for finetune xtts.\n",
"\n",
"If you are looking for an option for normal XTTS use look here https://github.com/daswer123/xtts-webui"
],
"metadata": {
"id": "OVjEG_yGoC2W"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "44HpAIVRfJve"
},
"outputs": [],
"source": [
"# @title 🛠️ Install requirments\n",
"#!DEBIAN_FRONTEND=noninteractive\n",
"!sudo apt-get update # && sudo apt-get -y upgrade\n",
"!sudo apt-get -y install libegl1\n",
"!sudo apt-get -y install libopengl0\n",
"!sudo apt-get -y install libxcb-cursor0\n",
"!pip install -r https://raw.githubusercontent.com/daswer123/xtts-finetune-webui/main/requirements.txt\n",
"!pip install gradio==4.44.1\n",
"!pip install fastapi==0.103.1\n",
"!pip install pydantic==2.3.0"
]
},
{
"cell_type": "code",
"source": [
"# @title 🚀 Run interface\n",
"%cd /content/\n",
"!git clone https://github.com/DrewThomasson/xtts-finetune-webui.git\n",
"%cd /content/xtts-finetune-webui\n",
"!python xtts_demo.py --share"
],
"metadata": {
"cellView": "form",
"id": "62Da1Q5AgN3W"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import shutil\n",
"import requests\n",
"import os\n",
"from tqdm import tqdm # Progress bar library\n",
"\n",
"# Define the paths\n",
"finetune_dir = '/content/xtts-finetune-webui/finetune_models/ready' # @param {type:\"string\"}\n",
"dataset_dir = '/content/xtts-finetune-webui/finetune_models/dataset' # @param {type:\"string\"}\n",
"\n",
"# Create a temporary directory to collect both folders before zipping\n",
"temp_dir = \"/content/temp_finetune_dataset\"\n",
"os.makedirs(temp_dir, exist_ok=True)\n",
"\n",
"# Copy both directories into the temporary directory with a progress bar\n",
"def copy_with_progress(src, dst):\n",
" total_files = sum(len(files) for _, _, files in os.walk(src))\n",
" with tqdm(total=total_files, desc=f\"Copying {os.path.basename(src)}\") as pbar:\n",
" for root, _, files in os.walk(src):\n",
" rel_path = os.path.relpath(root, src)\n",
" target_path = os.path.join(dst, rel_path)\n",
" os.makedirs(target_path, exist_ok=True)\n",
" for file in files:\n",
" shutil.copy(os.path.join(root, file), target_path)\n",
" pbar.update(1)\n",
"\n",
"copy_with_progress(finetune_dir, os.path.join(temp_dir, \"ready\"))\n",
"copy_with_progress(dataset_dir, os.path.join(temp_dir, \"dataset\"))\n",
"\n",
"# Create a zip file of the combined directories with progress\n",
"zip_filename = \"finetune_and_dataset.zip\"\n",
"with tqdm(total=100, desc=\"Zipping files\") as pbar:\n",
" shutil.make_archive(\"finetune_and_dataset\", 'zip', root_dir=temp_dir)\n",
" pbar.update(100)\n",
"\n",
"# Define a function to stream the upload with a progress bar\n",
"def upload_with_progress(file_path, url):\n",
" file_size = os.path.getsize(file_path)\n",
" with open(file_path, 'rb') as f, tqdm(\n",
" total=file_size, unit='B', unit_scale=True, desc=\"Uploading\"\n",
" ) as progress:\n",
" response = requests.post(\n",
" url,\n",
" files={\"file\": (file_path, f)},\n",
" stream=True,\n",
" headers={\"Connection\": \"keep-alive\"},\n",
" )\n",
" # Update the progress bar as chunks are sent\n",
" for chunk in response.iter_content(chunk_size=4096):\n",
" if chunk:\n",
" progress.update(len(chunk))\n",
" return response\n",
"\n",
"# Upload the zip file to file.io with a progress bar\n",
"response = upload_with_progress(zip_filename, \"https://file.io/?expires=1d\")\n",
"\n",
"# Parse the response and display the download link\n",
"if response.status_code == 200:\n",
" download_link = response.json().get('link', 'Error: No link found.')\n",
" print(f\"Your file is ready: {download_link}\")\n",
"else:\n",
" print(f\"Failed to upload: {response.status_code} - {response.text}\")\n"
],
"metadata": {
"cellView": "form",
"id": "MYBWgKevr6S3"
},
"execution_count": null,
"outputs": []
}
]
} |