Spaces:
No application file
No application file
File size: 1,193 Bytes
23f321d 5774bbe 23f321d 5774bbe 23f321d 21b9e96 5774bbe 21b9e96 5774bbe 21b9e96 5774bbe 44aa1b2 5774bbe |
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 |
import os
import gradio as gr
from huggingface_hub import InferenceClient
from dotenv import load_dotenv
# Cargar variables de entorno
load_dotenv()
TOKEN = os.getenv("TOKEN")
if TOKEN is None:
raise ValueError("❌ No se encontró la variable HF_TOKEN en el .env")
# Inicializar cliente de inferencia con Fal-AI
client = InferenceClient(provider="fal-ai", api_key=TOKEN)
def generar_audio(texto):
if not texto.strip():
return None
# Llamada a la API
audio_bytes = client.text_to_speech(texto, model="hexgrad/Kokoro-82M")
# Guardar temporalmente para que Gradio lo reproduzca
filename = "voz_generada.wav"
with open(filename, "wb") as f:
f.write(audio_bytes)
return filename
# Interfaz Gradio
with gr.Blocks() as demo:
gr.Markdown("# 🗣️ Texto a Voz con Kokoro-82M")
gr.Markdown("Escribe un texto y escucha el audio generado usando Inference Provider Fal-AI.")
texto = gr.Textbox(label="Escribe tu texto aquí", lines=4)
boton = gr.Button("Generar Audio")
audio_output = gr.Audio(label="Resultado", type="filepath")
boton.click(fn=generar_audio, inputs=texto, outputs=audio_output)
demo.launch()
|