Spaces:
Running
Running
| 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() |