xtts-castellano / finetune_xtts_hf.py
sob111's picture
Update finetune_xtts_hf.py
b009c70 verified
raw
history blame
1.23 kB
import os
import subprocess
from huggingface_hub import HfApi, HfFolder
# === Configuración ===
HF_TOKEN = os.environ.get("HF_TOKEN") # asegúrate de tenerlo en Secrets del Space
HF_REPO_ID = "sob111/xttsv2-es-finetuned" # cambia por tu repo destino
OUTPUT_PATH = "./output_model"
CONFIG_PATH = "./config.json"
# === Guardar token de Hugging Face ===
print("=== Guardando token de Hugging Face ===")
HfFolder.save_token(HF_TOKEN)
# === Iniciar entrenamiento XTTSv2 ===
print("=== Iniciando entrenamiento XTTSv2 ===")
try:
subprocess.run(
[
"python",
"TTS/bin/train_tts.py",
"--config_path", CONFIG_PATH
],
check=True
)
except subprocess.CalledProcessError:
raise RuntimeError("❌ El entrenamiento XTTSv2 falló. Revisa los logs anteriores.")
print("=== Entrenamiento finalizado ===")
# === Subir modelo fine-tune a Hugging Face ===
print("=== Subiendo modelo fine-tune a Hugging Face ===")
api = HfApi()
api.create_repo(repo_id=HF_REPO_ID, exist_ok=True, token=HF_TOKEN)
api.upload_folder(
folder_path=OUTPUT_PATH,
repo_id=HF_REPO_ID,
repo_type="model",
token=HF_TOKEN
)
print(f"✅ Fine-tuning completado y subido a {HF_REPO_ID}")