Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,47 +1,38 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from kokoro_onnx import Kokoro
|
| 3 |
import soundfile as sf
|
|
|
|
| 4 |
import os
|
| 5 |
-
import requests
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
print(f"Baixando {filename}...")
|
| 14 |
-
response = requests.get(url)
|
| 15 |
-
with open(filename, "wb") as f:
|
| 16 |
-
f.write(response.content)
|
| 17 |
-
print(f"{filename} baixado com sucesso.")
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Inicializa o modelo
|
| 24 |
-
model = Kokoro("kokoro-v0_19.onnx", "voices.bin")
|
| 25 |
-
|
| 26 |
-
def narrar_biblia(data):
|
| 27 |
-
# O JSON deve vir no formato {"texto": "Sua historia aqui"}
|
| 28 |
-
texto = data.get("texto", "")
|
| 29 |
if not texto:
|
| 30 |
return None
|
| 31 |
|
| 32 |
-
# 'am_michael' é
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
output_path = "narracao.wav"
|
| 36 |
sf.write(output_path, samples, sample_rate)
|
| 37 |
return output_path
|
| 38 |
|
| 39 |
-
# Interface
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=narrar_biblia,
|
| 42 |
-
inputs=gr.JSON(label="
|
| 43 |
-
outputs=gr.Audio(label="
|
| 44 |
api_name="predict"
|
| 45 |
)
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from kokoro_onnx import Kokoro
|
| 3 |
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 |
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
demo.launch()
|