Update app.py
Browse files
app.py
CHANGED
@@ -17,9 +17,6 @@ O vento começou a soprar com toda a força, mas quanto mais soprava, mais o via
|
|
17 |
Então, o Sol começou a brilhar suavemente, e o viajante, sentindo o calor, logo tirou a capa.
|
18 |
Assim, o Sol provou que o calor e a gentileza são mais eficazes do que a força bruta.
|
19 |
Esta história nos ensina que, muitas vezes, a delicadeza e a paciência são mais poderosas do que a agressividade.
|
20 |
-
Em nossa vida diária, podemos aplicar essa lição ao lidar com os outros, buscando sempre a compreensão e o diálogo.
|
21 |
-
A natureza nos oferece muitos exemplos de como a suavidade pode superar a força, e essa é uma lição valiosa para todos nós.
|
22 |
-
Que possamos sempre lembrar dessa história e agir com sabedoria em nossas interações com os outros.
|
23 |
"""
|
24 |
|
25 |
# Vozes disponíveis para português
|
@@ -30,8 +27,8 @@ TTS_VOICES = [
|
|
30 |
|
31 |
# Exemplo de uso
|
32 |
my_examples = [
|
33 |
-
[max_tokens_text, "Ed"],
|
34 |
-
[max_tokens_text, "Linda"]
|
35 |
]
|
36 |
|
37 |
# Artigo com informações adicionais
|
@@ -39,13 +36,12 @@ my_article = """
|
|
39 |
<h3>Guia do Usuário</h3>
|
40 |
<p>1. Insira o texto em português no campo de entrada (até 500 tokens).</p>
|
41 |
<p>2. Selecione a voz desejada (masculina ou feminina).</p>
|
42 |
-
<p>3. Clique em "
|
43 |
-
<p>4.
|
44 |
"""
|
45 |
|
46 |
# Função para sintetizar a fala
|
47 |
def tts(text: str, speaker_idx: str):
|
48 |
-
# Baixar os arquivos do modelo
|
49 |
best_model_path = hf_hub_download(repo_id=REPO_ID, filename="best_model.pth")
|
50 |
config_path = hf_hub_download(repo_id=REPO_ID, filename="config.json")
|
51 |
speakers_path = hf_hub_download(repo_id=REPO_ID, filename="speakers.pth")
|
@@ -53,7 +49,6 @@ def tts(text: str, speaker_idx: str):
|
|
53 |
speaker_encoder_model_path = hf_hub_download(repo_id=REPO_ID, filename="model_se.pth")
|
54 |
speaker_encoder_config_path = hf_hub_download(repo_id=REPO_ID, filename="config_se.json")
|
55 |
|
56 |
-
# Inicializar o sintetizador
|
57 |
synthesizer = Synthesizer(
|
58 |
best_model_path,
|
59 |
config_path,
|
@@ -66,33 +61,74 @@ def tts(text: str, speaker_idx: str):
|
|
66 |
False
|
67 |
)
|
68 |
|
69 |
-
|
70 |
-
wavs = synthesizer.tts(text, speaker_idx, "Português") # Idioma fixo: Português
|
71 |
|
72 |
-
# Salvar o áudio em um arquivo temporário
|
73 |
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
|
74 |
synthesizer.save_wav(wavs, fp)
|
75 |
return fp.name
|
76 |
|
77 |
-
# Criar a interface Gradio
|
78 |
-
with gr.Blocks(title=my_title, css="
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
gr.Markdown(my_description)
|
81 |
-
|
|
|
82 |
with gr.Row():
|
83 |
-
with gr.Column():
|
84 |
-
text_input = gr.Textbox(
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
submit_button = gr.Button("Gerar Áudio", variant="primary")
|
87 |
-
with gr.Column():
|
88 |
-
audio_output = gr.Audio(type="filepath", label="Áudio Gerado")
|
|
|
89 |
gr.Markdown(my_article)
|
90 |
-
|
91 |
-
#
|
92 |
-
gr.Examples(
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
Então, o Sol começou a brilhar suavemente, e o viajante, sentindo o calor, logo tirou a capa.
|
18 |
Assim, o Sol provou que o calor e a gentileza são mais eficazes do que a força bruta.
|
19 |
Esta história nos ensina que, muitas vezes, a delicadeza e a paciência são mais poderosas do que a agressividade.
|
|
|
|
|
|
|
20 |
"""
|
21 |
|
22 |
# Vozes disponíveis para português
|
|
|
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
|
|
|
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 |
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 |
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,
|
106 |
+
value="Ed"
|
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)
|