Spaces:
Sleeping
Sleeping
File size: 1,039 Bytes
527924f | 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 | 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() |