Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,26 @@ import os
|
|
| 3 |
import soundfile as sf
|
| 4 |
import gradio as gr
|
| 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 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
@spaces.GPU(duration=60)
|
| 19 |
def clone_voice(text: str):
|
| 20 |
if not text or not text.strip():
|
| 21 |
return None
|
| 22 |
-
|
|
|
|
| 23 |
ref_file=REF_AUDIO_PATH,
|
| 24 |
ref_text="",
|
| 25 |
gen_text=text.strip(),
|
|
@@ -29,6 +32,7 @@ def clone_voice(text: str):
|
|
| 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!",
|
|
@@ -38,23 +42,4 @@ with gr.Blocks(title="Praieiro Vox 路 Clonagem de Voz") as demo:
|
|
| 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 |
-
|
| 43 |
-
class TTSRequest(BaseModel):
|
| 44 |
-
input: str
|
| 45 |
-
|
| 46 |
-
@app.post("/v1/audio/speech")
|
| 47 |
-
def generate_speech_endpoint(req: TTSRequest, authorization: str = Header(None)):
|
| 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")
|
| 57 |
-
buf.seek(0)
|
| 58 |
-
return Response(content=buf.read(), media_type="audio/wav")
|
| 59 |
-
|
| 60 |
demo.launch()
|
|
|
|
| 3 |
import soundfile as sf
|
| 4 |
import gradio as gr
|
| 5 |
import spaces
|
|
|
|
|
|
|
| 6 |
from huggingface_hub import hf_hub_download
|
| 7 |
from f5_tts.api import F5TTS
|
| 8 |
|
|
|
|
| 9 |
REF_AUDIO_PATH = "PraieiroVox.wav"
|
| 10 |
+
f5tts_instance = None
|
| 11 |
|
| 12 |
+
def get_model():
|
| 13 |
+
global f5tts_instance
|
| 14 |
+
if f5tts_instance is None:
|
| 15 |
+
print("Carregando modelo F5-TTS pt-br na GPU...")
|
| 16 |
+
ckpt = hf_hub_download("firstpixel/F5-TTS-pt-br", "pt-br/model_last.safetensors")
|
| 17 |
+
f5tts_instance = F5TTS(model="F5TTS_Base", ckpt_file=ckpt, device="cuda")
|
| 18 |
+
return f5tts_instance
|
| 19 |
|
| 20 |
@spaces.GPU(duration=60)
|
| 21 |
def clone_voice(text: str):
|
| 22 |
if not text or not text.strip():
|
| 23 |
return None
|
| 24 |
+
model = get_model()
|
| 25 |
+
wav, sr, _ = model.infer(
|
| 26 |
ref_file=REF_AUDIO_PATH,
|
| 27 |
ref_text="",
|
| 28 |
gen_text=text.strip(),
|
|
|
|
| 32 |
|
| 33 |
with gr.Blocks(title="Praieiro Vox 路 Clonagem de Voz") as demo:
|
| 34 |
gr.Markdown("# 馃寠 Praieiro Vox 路 Voz Oficial do Praieiro Bot")
|
| 35 |
+
gr.Markdown("Motor de clonagem F5-TTS (pt-BR) rodando na GPU do Praieiro.")
|
| 36 |
text_input = gr.Textbox(
|
| 37 |
label="Texto a ser falado",
|
| 38 |
value="Fala meu brother! Seu pedido na praia j谩 t谩 sendo preparado e chega voando!",
|
|
|
|
| 42 |
audio_output = gr.Audio(label="脕udio Gerado", type="numpy")
|
| 43 |
btn.click(fn=clone_voice, inputs=[text_input], outputs=[audio_output], api_name="clone_voice")
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
demo.launch()
|