AlexandreScriptsMT commited on
Commit
b6eacae
·
verified ·
1 Parent(s): b49bd76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -17
app.py CHANGED
@@ -4,33 +4,38 @@ import soundfile as sf
4
  from huggingface_hub import hf_hub_download
5
  import os
6
 
7
- # Download oficial e seguro (Método recomendado em 2026)
8
- print("Baixando arquivos do modelo via HF Hub...")
9
- model_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="kokoro-v0_19.onnx")
10
- voices_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="voices.bin")
 
 
 
 
 
 
11
 
12
- # Inicializa o modelo usando os caminhos locais seguros
13
  model = Kokoro(model_path, voices_path)
14
 
15
- def narrar_biblia(json_input):
16
- # O JSON recebido deve ser: {"texto": "O conteúdo aqui"}
17
- texto = json_input.get("texto", "")
18
  if not texto:
19
  return None
20
 
21
- # 'am_michael' é uma voz masculina profunda e solene, ideal para a Bíblia
22
- # speed 0.9 deixa a fala mais pausada e épica
23
  samples, sample_rate = model.create(texto, voice="am_michael", speed=0.9)
24
 
25
- output_path = "narracao.wav"
26
- sf.write(output_path, samples, sample_rate)
27
- return output_path
28
 
29
- # Configuração da Interface e Endpoint da API
30
  demo = gr.Interface(
31
- fn=narrar_biblia,
32
- inputs=gr.JSON(label="Entrada JSON"),
33
- outputs=gr.Audio(label="Áudio Gerado"),
34
  api_name="predict"
35
  )
36
 
 
4
  from huggingface_hub import hf_hub_download
5
  import os
6
 
7
+ # Download seguro - Apontando para o repositório estável
8
+ print("Baixando modelos...")
9
+ try:
10
+ # Usando o repositório que contém os arquivos ONNX confirmados
11
+ model_path = hf_hub_download(repo_id="v006/kokoro", filename="kokoro-v0_19.onnx")
12
+ voices_path = hf_hub_download(repo_id="v006/kokoro", filename="voices.bin")
13
+ except Exception:
14
+ # Fallback para o repositório principal caso o acima falhe
15
+ model_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="kokoro-v0_19.onnx")
16
+ voices_path = hf_hub_download(repo_id="hexgrad/Kokoro-82M", filename="voices.bin")
17
 
18
+ # Inicializa o motor TTS
19
  model = Kokoro(model_path, voices_path)
20
 
21
+ def narrar(data):
22
+ texto = data.get("texto", "")
 
23
  if not texto:
24
  return None
25
 
26
+ # 'am_michael' é a voz masculina ideal: profunda, clara e solene
27
+ # speed=0.9 para dar o ritmo de leitura bíblica
28
  samples, sample_rate = model.create(texto, voice="am_michael", speed=0.9)
29
 
30
+ output_file = "audio.wav"
31
+ sf.write(output_file, samples, sample_rate)
32
+ return output_file
33
 
34
+ # Interface Gradio configurada como API JSON
35
  demo = gr.Interface(
36
+ fn=narrar,
37
+ inputs=gr.JSON(label="Input JSON"),
38
+ outputs=gr.Audio(label="Narração"),
39
  api_name="predict"
40
  )
41