Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import requests | |
| import tempfile, os, uuid | |
| from langdetect import detect | |
| HF_API_KEY = "COLE_SUA_CHAVE_AQUI" | |
| MODEL = "fishaudio/openaudio-s1-mini" | |
| def gerar_audio(texto): | |
| idioma = detect(texto) | |
| headers = { | |
| "Authorization": f"Bearer {HF_API_KEY}", | |
| "Content-Type": "application/json" | |
| } | |
| payload = { | |
| "inputs": texto, | |
| "parameters": { | |
| "language": idioma | |
| } | |
| } | |
| r = requests.post( | |
| f"https://api-inference.huggingface.co/models/{MODEL}", | |
| headers=headers, | |
| json=payload | |
| ) | |
| nome = f"{uuid.uuid4()}.wav" | |
| caminho = os.path.join(tempfile.gettempdir(), nome) | |
| with open(caminho, "wb") as f: | |
| f.write(r.content) | |
| return caminho | |
| with gr.Blocks() as app: | |
| gr.Markdown("## 🎙️ Motor de Voz - Narrador Profissional") | |
| texto = gr.Textbox(label="Roteiro", lines=6) | |
| botao = gr.Button("Gerar Narração") | |
| saida = gr.Audio(type="filepath") | |
| botao.click(gerar_audio, texto, saida) | |
| app.launch() |