Maicondds commited on
Commit
527924f
·
verified ·
1 Parent(s): c18edb0
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import tempfile, os, uuid
4
+ from langdetect import detect
5
+
6
+ HF_API_KEY = "COLE_SUA_CHAVE_AQUI"
7
+ MODEL = "fishaudio/openaudio-s1-mini"
8
+
9
+ def gerar_audio(texto):
10
+ idioma = detect(texto)
11
+
12
+ headers = {
13
+ "Authorization": f"Bearer {HF_API_KEY}",
14
+ "Content-Type": "application/json"
15
+ }
16
+
17
+ payload = {
18
+ "inputs": texto,
19
+ "parameters": {
20
+ "language": idioma
21
+ }
22
+ }
23
+
24
+ r = requests.post(
25
+ f"https://api-inference.huggingface.co/models/{MODEL}",
26
+ headers=headers,
27
+ json=payload
28
+ )
29
+
30
+ nome = f"{uuid.uuid4()}.wav"
31
+ caminho = os.path.join(tempfile.gettempdir(), nome)
32
+
33
+ with open(caminho, "wb") as f:
34
+ f.write(r.content)
35
+
36
+ return caminho
37
+
38
+ with gr.Blocks() as app:
39
+ gr.Markdown("## 🎙️ Motor de Voz - Narrador Profissional")
40
+
41
+ texto = gr.Textbox(label="Roteiro", lines=6)
42
+ botao = gr.Button("Gerar Narração")
43
+ saida = gr.Audio(type="filepath")
44
+
45
+ botao.click(gerar_audio, texto, saida)
46
+
47
+ app.launch()