File size: 2,579 Bytes
478642e
 
4c63b06
379f9e2
5b7944f
 
 
207f7a0
379f9e2
 
 
 
 
 
 
 
c02e83b
71b3990
207f7a0
5b7944f
8512af1
236c4b0
90b80e5
5bebe98
 
90b80e5
8512af1
236c4b0
 
5bebe98
236c4b0
 
 
 
71b3990
236c4b0
5bebe98
236c4b0
207f7a0
5bebe98
 
207f7a0
 
 
236c4b0
 
 
 
71b3990
 
9994a98
236c4b0
71b3990
236c4b0
 
207f7a0
236c4b0
207f7a0
 
236c4b0
207f7a0
236c4b0
 
8512af1
236c4b0
 
55d30ef
71b3990
236c4b0
 
71b3990
 
 
8512af1
478642e
8512af1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import os
from tts import synthesize_and_save_audio
import time

def generate_tts(input_text, reference_audio_path):
    output_path = "cloned.wav"
    for i in range(3):
        try:
            result = synthesize_and_save_audio(
                input_text=input_text,
                voice_id=reference_audio_path,
                model="voxtral-mini-tts-2603",
                api_key=os.getenv("MISTRAL_API_KEY"),
                output_path=output_path,
            )
            if result == 0: return output_path
        except Exception:
            time.sleep(1)
    return None

# Ajustado: Chaves exatas que o seu site envia
voice_mapping = {
    "lateinos-1": "guia_lateinos.wav (1).mp3",
    "lateinos-2": "guia_lateinos.wav (1).mp3"
}

# FUNÇÃO PARA O SITE (2 Entradas)
def api_lateinos_tts(text, voice_key):
    ref = voice_mapping.get(voice_key, "guia_lateinos.wav (1).mp3")
    return generate_tts(text, ref)

# FUNÇÃO PARA A INTERFACE (3 Entradas)
def ui_lateinos_lab(text, voice_dropdown, upload_file):
    if upload_file is not None:
        return generate_tts(text, upload_file)
    ref = voice_mapping.get(voice_dropdown, "guia_lateinos.wav (1).mp3")
    return generate_tts(text, ref)

with gr.Blocks(title="Evolution-Voice-App") as demo:
    gr.Markdown("# Estúdio Lab")
    
    with gr.Row():
        with gr.Column():
            txt = gr.Textbox(label="Letra", lines=4)
            with gr.Tabs():
                with gr.Tab("Vozes Fixas"):
                    # Use os nomes visíveis aqui, a função traduz pela chave depois
                    voice_select = gr.Dropdown(
                        choices=list(voice_mapping.keys()), 
                        value="lateinos-1", 
                        label="Voz Nativa"
                    )
                with gr.Tab("Upload PC"):
                    audio_upload = gr.Audio(label="Subir do PC (10-30s)", type="filepath")
            
            btn = gr.Button("CRIAR GUIA", variant="primary")

        with gr.Column():
            out = gr.Audio(label="Download Liberado")

    # Click da Interface (3 inputs)
    btn.click(fn=ui_lateinos_lab, inputs=[txt, voice_select, audio_upload], outputs=out)

    # PORTA VIP PARA O RENDER (predict_1)
    # CORREÇÃO: Esta função recebe apenas 2 inputs para bater com o seu Render
    api_btn = gr.Button("API", visible=False)
    api_btn.click(
        fn=api_lateinos_tts, 
        inputs=[txt, voice_select], 
        outputs=[out], 
        api_name="predict_1"
    )

if __name__ == "__main__":
    demo.launch()