Download app.py from XSify/coquiTTS: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/XSify/coquiTTS/resolve/main/app.py
- Command line
-
hf download hf://spaces/XSify/coquiTTS/app.py
-
curl -L -o app.py https://huggingface.co/spaces/XSify/coquiTTS/resolve/main/app.py
1.19 kB
| import os | |
| import gradio as gr | |
| import torch | |
| import numpy as np | |
| # ✅ Forzar consentimiento de licencia | |
| os.environ["COQUI_TOS_AGREED"] = "1" | |
| # ✅ Monkey patch: Sobrescribir torch.load temporalmente para desactivar weights_only | |
| original_torch_load = torch.load | |
| def patched_torch_load(f, *args, **kwargs): | |
| kwargs["weights_only"] = False # 👈 Fuerza que no sea weights_only | |
| return original_torch_load(f, *args, **kwargs) | |
| torch.load = patched_torch_load # 🚨 Peligroso en general, pero necesario aquí | |
| # ✅ Cargar el modelo después del parche | |
| from TTS.api import TTS | |
| tts = TTS(model_name="tts_models/multilingual/multi-dataset/xtts_v2") | |
| # 🎤 Función principal | |
| def generate_audio(text, language, speaker_wav): | |
| if speaker_wav is not None: | |
| audio = tts.tts(text=text, speaker_wav=speaker_wav, language=language) | |
| audio_np = np.array(audio, dtype=np.float16) | |
| return (24000, audio_np) | |
| # 🎛️ Interfaz | |
| iface = gr.Interface( | |
| fn=generate_audio, | |
| inputs=[ | |
| gr.Text(label="Texto"), | |
| gr.Text(label="Idioma (ej: 'es', 'en')"), | |
| gr.Audio(type="filepath", label="Audio de voz") | |
| ], | |
| outputs="audio" | |
| ) | |
| iface.launch() | |