DHEIVER commited on
Commit
0e9d1bc
·
verified ·
1 Parent(s): bd8bee9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -63
app.py CHANGED
@@ -8,7 +8,10 @@ REPO_ID = "mbarnig/lb-de-fr-en-pt-coqui-vits-tts"
8
 
9
  # Configurações da interface
10
  my_title = "🇵🇹 Sintetizador de Fala em Português com Coqui TTS"
11
- my_description = "Um sintetizador de fala em português baseado no modelo YourTTS da Coqui.ai. Insira o texto e gere o áudio!"
 
 
 
12
 
13
  # Texto de exemplo com o máximo de tokens (500 tokens)
14
  max_tokens_text = """
@@ -25,23 +28,9 @@ TTS_VOICES = [
25
  "Linda" # Voz feminina
26
  ]
27
 
28
- # Exemplo de uso
29
- my_examples = [
30
- [max_tokens_text, "Ed"],
31
- [max_tokens_text, "Linda"]
32
- ]
33
-
34
- # Artigo com informações adicionais
35
- my_article = """
36
- <h3>Guia do Usuário</h3>
37
- <p>1. Insira o texto em português no campo de entrada (até 500 tokens).</p>
38
- <p>2. Selecione a voz desejada (masculina ou feminina).</p>
39
- <p>3. Clique em "Gerar Áudio" para criar o áudio correspondente.</p>
40
- <p>4. Ouça o áudio gerado ou faça o download diretamente do player.</p>
41
- """
42
-
43
  # Função para sintetizar a fala
44
  def tts(text: str, speaker_idx: str):
 
45
  best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
46
  config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
47
  speakers_path = hf_hub_download(repo_id=REPO_ID, filename="speakers.pth")
@@ -49,6 +38,7 @@ def tts(text: str, speaker_idx: str):
49
  speaker_encoder_model_path = hf_hub_download(repo_id=REPO_ID, filename="model_se.pth")
50
  speaker_encoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="config_se.json")
51
 
 
52
  synthesizer = Synthesizer(
53
  best_model_path,
54
  config_path,
@@ -61,45 +51,26 @@ def tts(text: str, speaker_idx: str):
61
  False
62
  )
63
 
64
- wavs = synthesizer.tts(text, speaker_idx, "Português")
 
65
 
 
66
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
67
  synthesizer.save_wav(wavs, fp)
68
  return fp.name
69
 
70
- # Criar a interface Gradio aprimorada
71
- with gr.Blocks(title=my_title, css="""
72
- .gradio-container {
73
- max-width: 800px;
74
- margin: auto;
75
- font-family: 'Arial', sans-serif;
76
- }
77
- .header {
78
- text-align: center;
79
- margin-bottom: 20px;
80
- }
81
- .footer {
82
- font-size: 0.85rem;
83
- color: gray;
84
- text-align: center;
85
- margin-top: 30px;
86
- }
87
- """) as demo:
88
- # Cabeçalho
89
- with gr.Row(variant="compact"):
90
- gr.Markdown(f"<h1 class='header'>{my_title}</h1>")
91
  gr.Markdown(my_description)
92
-
93
- # Entrada do usuário
94
  with gr.Row():
95
  with gr.Column(scale=1):
96
  text_input = gr.Textbox(
97
  lines=10,
98
  label="Texto em Português",
99
- placeholder="Insira o texto aqui... (até 500 tokens)",
100
- max_length=500
101
  )
102
- token_counter = gr.Label(value="Tokens usados: 0 / 500", label="Progresso")
103
  voice_selector = gr.Radio(
104
  label="Voz",
105
  choices=TTS_VOICES,
@@ -107,28 +78,26 @@ with gr.Blocks(title=my_title, css="""
107
  )
108
  submit_button = gr.Button("Gerar Áudio", variant="primary")
109
  with gr.Column(scale=1):
110
- audio_output = gr.Audio(type="filepath", label="Áudio Gerado", interactive=False)
111
- download_button = gr.File(label="Download do Áudio")
112
- gr.Markdown(my_article)
113
-
114
- # Exemplo de uso
115
- gr.Examples(
116
- examples=my_examples,
117
- inputs=[text_input, voice_selector],
118
- outputs=[audio_output],
119
- cache_examples=True
120
- )
121
-
122
- # Feedback e progresso
 
 
123
  submit_button.click(
124
  fn=tts,
125
  inputs=[text_input, voice_selector],
126
- outputs=[audio_output],
127
- show_progress=True
128
  )
129
 
130
- # Rodapé
131
- gr.Markdown("<p class='footer'>Desenvolvido com ❤️ usando Gradio e Coqui TTS</p>")
132
-
133
- # Iniciar
134
- demo.launch(share=True)
 
8
 
9
  # Configurações da interface
10
  my_title = "🇵🇹 Sintetizador de Fala em Português com Coqui TTS"
11
+ my_description = """
12
+ Um sintetizador de fala em português baseado no modelo YourTTS da Coqui.ai.
13
+ Insira o texto e gere o áudio com a voz desejada (masculina ou feminina)!
14
+ """
15
 
16
  # Texto de exemplo com o máximo de tokens (500 tokens)
17
  max_tokens_text = """
 
28
  "Linda" # Voz feminina
29
  ]
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  # Função para sintetizar a fala
32
  def tts(text: str, speaker_idx: str):
33
+ # Baixar os arquivos do modelo
34
  best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
35
  config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
36
  speakers_path = hf_hub_download(repo_id=REPO_ID, filename="speakers.pth")
 
38
  speaker_encoder_model_path = hf_hub_download(repo_id=REPO_ID, filename="model_se.pth")
39
  speaker_encoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="config_se.json")
40
 
41
+ # Inicializar o sintetizador
42
  synthesizer = Synthesizer(
43
  best_model_path,
44
  config_path,
 
51
  False
52
  )
53
 
54
+ # Gerar o áudio
55
+ wavs = synthesizer.tts(text, speaker_idx, "Português") # Idioma fixo: Português
56
 
57
+ # Salvar o áudio em um arquivo temporário
58
  with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
59
  synthesizer.save_wav(wavs, fp)
60
  return fp.name
61
 
62
+ # Criar a interface Gradio
63
+ with gr.Blocks(title=my_title, css=".gradio-container {max-width: 900px; margin: auto;}") as demo:
64
+ gr.Markdown(f"<h1 style='text-align: center;'>{my_title}</h1>")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  gr.Markdown(my_description)
66
+
 
67
  with gr.Row():
68
  with gr.Column(scale=1):
69
  text_input = gr.Textbox(
70
  lines=10,
71
  label="Texto em Português",
72
+ placeholder="Insira o texto aqui... (máximo de 500 tokens)"
 
73
  )
 
74
  voice_selector = gr.Radio(
75
  label="Voz",
76
  choices=TTS_VOICES,
 
78
  )
79
  submit_button = gr.Button("Gerar Áudio", variant="primary")
80
  with gr.Column(scale=1):
81
+ audio_output = gr.Audio(type="filepath", label="Áudio Gerado")
82
+ download_button = gr.File(label="Baixar Áudio")
83
+
84
+ gr.Markdown("<hr>")
85
+ gr.Markdown("""
86
+ <h3>Guia do Usuário:</h3>
87
+ <ul>
88
+ <li>Insira o texto em português no campo de entrada (até 500 tokens).</li>
89
+ <li>Selecione a voz desejada (masculina ou feminina).</li>
90
+ <li>Clique em "Gerar Áudio" para gerar o arquivo de áudio.</li>
91
+ <li>Reproduza ou faça o download do áudio gerado.</li>
92
+ </ul>
93
+ """)
94
+
95
+ # Ação do botão
96
  submit_button.click(
97
  fn=tts,
98
  inputs=[text_input, voice_selector],
99
+ outputs=[audio_output, download_button]
 
100
  )
101
 
102
+ # Iniciar a interface
103
+ demo.launch()