raw
history blame
1.19 kB
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()