Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,47 +5,38 @@ import gradio as gr
|
|
| 5 |
import spaces
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from fastapi import HTTPException, Header, Response
|
|
|
|
| 8 |
from f5_tts.api import F5TTS
|
| 9 |
|
| 10 |
SHARED_SECRET = os.environ.get("PRAIEIRO_SECRET", "praieiro-voz-2026")
|
| 11 |
REF_AUDIO_PATH = "PraieiroVox.wav"
|
| 12 |
|
| 13 |
-
print("Carregando modelo F5-TTS
|
| 14 |
-
|
|
|
|
| 15 |
|
| 16 |
-
@spaces.GPU(duration=
|
| 17 |
def clone_voice(text: str):
|
| 18 |
if not text or not text.strip():
|
| 19 |
return None
|
| 20 |
-
|
| 21 |
-
# Gera a fala imitando exatamente o áudio PraieiroVox.wav
|
| 22 |
wav, sr, _ = f5tts.infer(
|
| 23 |
ref_file=REF_AUDIO_PATH,
|
| 24 |
ref_text="",
|
| 25 |
gen_text=text.strip(),
|
| 26 |
-
remove_silence=True
|
| 27 |
)
|
| 28 |
return sr, wav
|
| 29 |
|
| 30 |
with gr.Blocks(title="Praieiro Vox · Clonagem de Voz") as demo:
|
| 31 |
-
gr.Markdown("# 🌊 Praieiro Vox ·
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
value="Fala meu brother! Seu pedido na praia já tá sendo preparado e chega voando!",
|
| 38 |
-
lines=3
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
btn = gr.Button("🎤 Gerar Fala com a Voz Clonada", variant="primary")
|
| 42 |
audio_output = gr.Audio(label="Áudio Gerado", type="numpy")
|
| 43 |
-
|
| 44 |
-
btn.click(
|
| 45 |
-
fn=clone_voice,
|
| 46 |
-
inputs=[text_input],
|
| 47 |
-
outputs=[audio_output]
|
| 48 |
-
)
|
| 49 |
|
| 50 |
app = demo.app
|
| 51 |
|
|
@@ -57,11 +48,9 @@ def generate_speech_endpoint(req: TTSRequest, authorization: str = Header(None))
|
|
| 57 |
token = authorization.replace("Bearer ", "") if authorization else ""
|
| 58 |
if token != SHARED_SECRET:
|
| 59 |
raise HTTPException(status_code=401, detail="Não autorizado")
|
| 60 |
-
|
| 61 |
res = clone_voice(req.input)
|
| 62 |
if res is None:
|
| 63 |
raise HTTPException(status_code=400, detail="Texto vazio ou inválido")
|
| 64 |
-
|
| 65 |
sr, audio_data = res
|
| 66 |
buf = io.BytesIO()
|
| 67 |
sf.write(buf, audio_data, sr, format="WAV")
|
|
|
|
| 5 |
import spaces
|
| 6 |
from pydantic import BaseModel
|
| 7 |
from fastapi import HTTPException, Header, Response
|
| 8 |
+
from huggingface_hub import hf_hub_download
|
| 9 |
from f5_tts.api import F5TTS
|
| 10 |
|
| 11 |
SHARED_SECRET = os.environ.get("PRAIEIRO_SECRET", "praieiro-voz-2026")
|
| 12 |
REF_AUDIO_PATH = "PraieiroVox.wav"
|
| 13 |
|
| 14 |
+
print("Carregando modelo F5-TTS em português...")
|
| 15 |
+
ckpt = hf_hub_download("firstpixel/F5-TTS-pt-br", "pt-br/model_last.safetensors")
|
| 16 |
+
f5tts = F5TTS(model="F5TTS_Base", ckpt_file=ckpt)
|
| 17 |
|
| 18 |
+
@spaces.GPU(duration=60)
|
| 19 |
def clone_voice(text: str):
|
| 20 |
if not text or not text.strip():
|
| 21 |
return None
|
|
|
|
|
|
|
| 22 |
wav, sr, _ = f5tts.infer(
|
| 23 |
ref_file=REF_AUDIO_PATH,
|
| 24 |
ref_text="",
|
| 25 |
gen_text=text.strip(),
|
| 26 |
+
remove_silence=True,
|
| 27 |
)
|
| 28 |
return sr, wav
|
| 29 |
|
| 30 |
with gr.Blocks(title="Praieiro Vox · Clonagem de Voz") as demo:
|
| 31 |
+
gr.Markdown("# 🌊 Praieiro Vox · Voz Oficial do Praieiro Bot")
|
| 32 |
+
text_input = gr.Textbox(
|
| 33 |
+
label="Texto a ser falado",
|
| 34 |
+
value="Fala meu brother! Seu pedido na praia já tá sendo preparado e chega voando!",
|
| 35 |
+
lines=3,
|
| 36 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
btn = gr.Button("🎤 Gerar Fala com a Voz Clonada", variant="primary")
|
| 38 |
audio_output = gr.Audio(label="Áudio Gerado", type="numpy")
|
| 39 |
+
btn.click(fn=clone_voice, inputs=[text_input], outputs=[audio_output], api_name="clone_voice")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
app = demo.app
|
| 42 |
|
|
|
|
| 48 |
token = authorization.replace("Bearer ", "") if authorization else ""
|
| 49 |
if token != SHARED_SECRET:
|
| 50 |
raise HTTPException(status_code=401, detail="Não autorizado")
|
|
|
|
| 51 |
res = clone_voice(req.input)
|
| 52 |
if res is None:
|
| 53 |
raise HTTPException(status_code=400, detail="Texto vazio ou inválido")
|
|
|
|
| 54 |
sr, audio_data = res
|
| 55 |
buf = io.BytesIO()
|
| 56 |
sf.write(buf, audio_data, sr, format="WAV")
|