Spaces:
Runtime error
Runtime error
File size: 1,961 Bytes
8f78501 3b36d05 9499f80 f2b2c12 40457d3 f2b2c12 b009c70 40457d3 b009c70 f2b2c12 b009c70 f2b2c12 40457d3 9499f80 40457d3 dd069ba 40457d3 9499f80 40457d3 b009c70 8f78501 3b36d05 b009c70 3b36d05 b009c70 8f78501 b009c70 8f78501 f2b2c12 b009c70 8f78501 b009c70 f2b2c12 8f78501 9499f80 40457d3 |
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 |
import os
import subprocess
import json
from huggingface_hub import HfApi, HfFolder
from datasets import load_dataset
# === Configuración ===
HF_TOKEN = os.environ.get("HF_TOKEN") # define en los Secrets del Space
HF_REPO_ID = "sob111/xttsv2-es-finetuned" # tu repo de 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)
# === Descargar dataset desde Hugging Face ===
print("=== Descargando dataset sob111/voxpopuli_es_500 ===")
ds = load_dataset("sob111/voxpopuli_es_500", split="train", token=HF_TOKEN)
# Guardar metadata.json en el formato esperado por Coqui TTS
os.makedirs("./voxpopuli_es_500", exist_ok=True)
meta_file = "./voxpopuli_es_500/metadata.json"
with open(meta_file, "w", encoding="utf-8") as f:
for sample in ds:
entry = {
"audio_file": sample["audio_file"],
"text": sample["text"],
"speaker_name": sample.get("speaker_name", "speaker")
}
f.write(json.dumps(entry, ensure_ascii=False) + "\n")
print("✅ Metadata guardada en {meta_file}")
# === 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("✅ Fine-tuning completado y subido a {HF_REPO_ID}")
|