Spaces:
Runtime error
Runtime error
File size: 2,098 Bytes
8f78501 e7a429e 54638f8 f2b2c12 b009c70 e7a429e a7c3599 e7a429e ef5bfac f13b775 ef5bfac f13b775 ef5bfac f13b775 ef5bfac f13b775 ef5bfac f13b775 e7a429e c746161 40457d3 e7a429e f2b2c12 e7a429e f2b2c12 8f78501 e7a429e |
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 |
import os
import subprocess
from huggingface_hub import HfApi, HfFolder, upload_folder, snapshot_download
# === Configuración ===
HF_MODEL_ID = "tu_usuario/xtts-v2-finetuned" # <--- cambia con tu repo en HF
HF_TOKEN = os.environ.get("HF_TOKEN") # Debe estar definido en tu Space/entorno
DATASET_PATH = "/home/user/app/dataset" # Ruta a tu dataset
OUTPUT_PATH = "/tmp/output_model"
BASE_MODEL = "coqui/XTTS-v2"
os.makedirs("./xtts_model", exist_ok=True)
os.makedirs("./output", exist_ok=True)
local_cache = "/tmp/hf_cache"
os.makedirs(local_cache, exist_ok=True)
print("=== Descargando modelo base desde Hugging Face ===")
model_dir = snapshot_download(
repo_id="coqui/XTTS-v2",
local_dir="xtts_model",
cache_dir=local_cache, # 👈 Forzamos el caché aquí
local_dir_use_symlinks=False,
resume_download=True
)
print(f"Modelo descargado en: {model_dir}")
CONFIG_PATH = "./xtts_model/config.json"
RESTORE_PATH = "./xtts_model/model.pth"
# === 2. Editar configuración para tu dataset VoxPopuli ===
print("=== Editando configuración para fine-tuning con VoxPopuli ===")
import json
with open(CONFIG_PATH, "r") as f:
config = json.load(f)
config["output_path"] = OUTPUT_PATH
config["datasets"] = [
{
"formatter": "voxpopuli",
"path": DATASET_PATH,
"meta_file_train": "metadata.json"
}
]
config["run_name"] = "xtts-finetune-voxpopuli"
config["lr"] = 1e-5 # más bajo para fine-tuning
with open(CONFIG_PATH, "w") as f:
json.dump(config, f, indent=2)
# === 3. Lanzar entrenamiento ===
print("=== Iniciando fine-tuning de XTTS-v2 ===")
subprocess.run([
"python", "TTS/bin/train_tts.py",
"--config_path", CONFIG_PATH,
"--restore_path", RESTORE_PATH
], check=True)
# === 4. Subir modelo resultante a HF ===
print("=== Subiendo modelo fine-tuneado a Hugging Face Hub ===")
api = HfApi()
HfFolder.save_token(HF_TOKEN)
upload_folder(
repo_id=HF_MODEL_ID,
repo_type="model",
folder_path=OUTPUT_PATH,
token=HF_TOKEN
)
print("✅ Fine-tuning completado y modelo subido a Hugging Face.")
|