fewe32 commited on
Commit
c1bd305
·
verified ·
1 Parent(s): 2fea0af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -89
app.py CHANGED
@@ -87,99 +87,54 @@ with open('dict.txt', 'r', encoding='utf-8') as f:
87
  base_word = remove_combining_chars(line_normalized.replace('+', '').lower())
88
  custom_dict[base_word] = line_normalized
89
 
90
- def synthesise(text, speed, steps, progress=gr.Progress()):
91
- if text.strip() == "":
92
- raise gr.Error("You must enter some text")
93
- if len(text) > 50000:
94
- raise gr.Error("Text must be <50k characters")
95
-
96
- # Pre-process the text
97
  text = normalize_text(text)
98
- text = replace_with_custom_dict(text, custom_dict)
 
99
  text = convert_accented_text(text)
100
- # Uncomment the next line if you want to add pauses
101
- # text = add_pauses(text)
 
102
 
 
 
 
 
 
 
103
  print("*** saying ***")
104
- print(text)
105
  print("*** end ***")
106
-
107
- return 24000, inference(text, progress, speed=speed, alpha=1.0, diffusion_steps=steps, embedding_scale=1.0)[0]
108
 
109
  if __name__ == "__main__":
110
- i = gr.Interface(
111
- fn=synthesise,
112
- description=description,
113
- inputs=[
114
- gr.Text(label='Text:', lines=5, max_lines=10),
115
- gr.Slider(label='Швидкість:', maximum=1.3, minimum=0.7, value=1.0),
116
- gr.Slider(label='Кількість кроків дифузії:', minimum=3, maximum=20, step=1, value=3)
117
- ],
118
- outputs=[
119
- gr.Audio(
120
- label="Audio:",
121
- autoplay=False,
122
- streaming=False,
123
- type="numpy",
124
- ),
125
- ],
126
- allow_flagging='never',
127
- cache_examples=False,
128
- title='StyleTTS2 Ukrainian Demo',
129
- examples=[
130
- [
131
- '''Мені+ трина+дцятий мина+ло;:::
132
- Я пас ягня+та за село+м. ... ...
133
- Чи то так со+нечко сія+ло,:::
134
- Чи так мені+ чого+ було+ –:::
135
- Мені+ так лю+бо,::: лю+бо ста+ло,:::
136
- Нена+че в Бо+га. ... ... . ... ... . ... ...
137
- Уже+ прокли+кали до па+ю,:::
138
- А я собі+ у бур’яні+
139
- Молю+ся Бо+гу,::: і не зна+ю,:::
140
- Чого+ мале+нькому мені+
141
- Тоді+ так при+язно моли+лось,:::
142
- Чого+ так ве+село було+. ... ...
143
- Госпо+днє не+бо і село+,:::
144
- Ягня+,::: здає+ться,::: весели+лось,:::
145
- І со+нце грі+ло –::: не пекло+. ... ...
146
- Та не до+вго со+нце грі+ло,:::
147
- Не до+вго моли+лось;:::
148
- Запекло+,::: почервоні+ло
149
- І рай запали+ло. ... ...
150
- Мов проки+нувся,::: –::: дивлю+ся:::
151
- Село+ почорні+ло,:::
152
- Бо+же не+бо голубеє –:::
153
- І те помарні+ло. ... ...
154
- Погля+нув я на ягня+та –:::
155
- Не мої+ ягня+та;:::
156
- Оберну+вся я на ха+ти –:::
157
- Нема+ в мене+ ха+ти. ... ...
158
- Не дав мені+ Бог нічо+го! ... ...
159
- І хли+нули сльо+зи. ... ... . ... ... . ... ...
160
- Тяжкі+ сльо+зи. ... ... . ... ... . ... ... А ді+вчи+на,:::
161
- При самі+й доро+зі,:::
162
- Недале+ко ко+ло мене+
163
- Пло+скінь вибира+ла,:::
164
- Та й почу+ла,::: що я пла+чу:::
165
- Прийшла+,::: привіта+ла,:::
166
- Утира+ла мої+ сльо+зи,:::
167
- І поцілува+ла. ... ... . ... ... . ... ...
168
- Нена+че со+нце засія+ло,:::
169
- Нена+че все на сві+ті ста+ло
170
- Моє+::: лани+,::: гаї+,::: сади+. ... ... . ... ... . ... ...
171
- І ми,::: жарту+ючи,::: погна+ли
172
- Чужі+ ягня+та до води+. ... ...
173
- Бридня+! ... .... ... ... . ... ... А й до+сі,::: як згада+ю,:::
174
- То се+рце пла+че та боли+ть,:::
175
- Чому+ Госпо+дь не дав дожить
176
- Мало+го ві+ку у ті+м ра+ю. ... ...
177
- Уме+р би,::: орючи+ на ни+ві,:::
178
- Нічо+го б на сві+ті не знав. ... ...
179
- Не був би в сві+ті юроди+вим. ... ...
180
- Люде+й і [Бо+га] не прокля+в! ... ...''', 1.0, 6
181
- ]
182
- ],
183
- )
184
- i.queue(max_size=20, default_concurrency_limit=4)
185
- i.launch(share=False, server_name="0.0.0.0")
 
87
  base_word = remove_combining_chars(line_normalized.replace('+', '').lower())
88
  custom_dict[base_word] = line_normalized
89
 
90
+ def transform_text(text, apply_custom_dict, add_pauses):
 
 
 
 
 
 
91
  text = normalize_text(text)
92
+ if apply_custom_dict:
93
+ text = replace_with_custom_dict(text, custom_dict)
94
  text = convert_accented_text(text)
95
+ if add_pauses:
96
+ text = add_pauses(text)
97
+ return text
98
 
99
+ def synthesise(transformed_text, speed, steps, progress=gr.Progress()):
100
+ if transformed_text.strip() == "":
101
+ raise gr.Error("Ви повинні ввести текст")
102
+ if len(transformed_text) > 50000:
103
+ raise gr.Error("Текст повинен бути менше 50 000 символів")
104
+
105
  print("*** saying ***")
106
+ print(transformed_text)
107
  print("*** end ***")
108
+
109
+ return 24000, inference(transformed_text, progress, speed=speed, alpha=1.0, diffusion_steps=steps, embedding_scale=1.0)[0]
110
 
111
  if __name__ == "__main__":
112
+ with gr.Blocks() as demo:
113
+ gr.Markdown(description)
114
+ with gr.Row():
115
+ text_input = gr.Textbox(label='Text:', lines=5, max_lines=10)
116
+ transformed_text_output = gr.Textbox(label='Transformed Text:', lines=5, max_lines=10, interactive=False)
117
+ with gr.Row():
118
+ apply_custom_dict_checkbox = gr.Checkbox(label='Замінити слова за словником', value=True)
119
+ add_pauses_checkbox = gr.Checkbox(label='Додати паузи', value=False)
120
+ with gr.Row():
121
+ speed_slider = gr.Slider(label='Швидкість:', maximum=1.3, minimum=0.7, value=1.0)
122
+ steps_slider = gr.Slider(label='Кількість кроків дифузії:', minimum=3, maximum=20, step=1, value=3)
123
+ generate_button = gr.Button('Згенерувати аудіо')
124
+ audio_output = gr.Audio(label="Audio:", autoplay=False, streaming=False, type="numpy")
125
+
126
+ def update_transformed_text(text, apply_custom_dict, add_pauses):
127
+ transformed_text = transform_text(text, apply_custom_dict, add_pauses)
128
+ return transformed_text
129
+
130
+ # Set up live update of transformed text
131
+ text_input.change(fn=update_transformed_text, inputs=[text_input, apply_custom_dict_checkbox, add_pauses_checkbox], outputs=transformed_text_output)
132
+ apply_custom_dict_checkbox.change(fn=update_transformed_text, inputs=[text_input, apply_custom_dict_checkbox, add_pauses_checkbox], outputs=transformed_text_output)
133
+ add_pauses_checkbox.change(fn=update_transformed_text, inputs=[text_input, apply_custom_dict_checkbox, add_pauses_checkbox], outputs=transformed_text_output)
134
+
135
+ def generate_audio(transformed_text, speed, steps):
136
+ return synthesise(transformed_text, speed, steps)
137
+
138
+ generate_button.click(fn=generate_audio, inputs=[transformed_text_output, speed_slider, steps_slider], outputs=audio_output)
139
+
140
+ demo.launch(share=False, server_name="0.0.0.0")