Den4ikAI commited on
Commit
af5fbc8
·
verified ·
1 Parent(s): 80d1f1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -16
app.py CHANGED
@@ -163,6 +163,17 @@ def process_text_with_accent(text, accentizer):
163
  # Прогоняем через RUAccent
164
  return accentizer.process_all(text)
165
 
 
 
 
 
 
 
 
 
 
 
 
166
  # ----------------- Основная функция синтеза (GPU-aware) -----------------
167
  # Декорируем synthesize, чтобы при вызове Space выделял GPU (если доступно).
168
  # duration — сколько секунд просим GPU (адаптируйте под ваш инференс).
@@ -320,9 +331,9 @@ def synthesize(
320
  # ----------------- Gradio UI (как у вас) -----------------
321
  with gr.Blocks(title="ESpeech-TTS") as app:
322
  gr.Markdown("# ESpeech-TTS")
323
- gr.Markdown("See more on https://huggingface.co/ESpeech")
324
- gr.Markdown("💡 **Tip:** Add '+' symbol in text to mark custom stress (e.g., 'прив+ет'). Text with '+' won't be processed by RUAccent.")
325
-
326
  # Описание моделей на русском языке
327
  gr.Markdown("""
328
  ## 📋 Описание моделей:
@@ -349,11 +360,6 @@ with gr.Blocks(title="ESpeech-TTS") as app:
349
  lines=2,
350
  placeholder="leave empty → ASR will transcribe"
351
  )
352
- ref_text_output = gr.Textbox(
353
- label="Processed Reference Text (with accents)",
354
- lines=2,
355
- interactive=False
356
- )
357
  with gr.Column():
358
  gen_text_input = gr.Textbox(
359
  label="Text to Generate",
@@ -361,12 +367,9 @@ with gr.Blocks(title="ESpeech-TTS") as app:
361
  max_lines=20,
362
  placeholder="Enter text to synthesize..."
363
  )
364
- gen_text_output = gr.Textbox(
365
- label="Processed Text to Generate (with accents)",
366
- lines=5,
367
- max_lines=20,
368
- interactive=False
369
- )
370
 
371
  with gr.Row():
372
  with gr.Column():
@@ -408,12 +411,20 @@ with gr.Blocks(title="ESpeech-TTS") as app:
408
  nfe_slider,
409
  speed_slider,
410
  ],
411
- outputs=[audio_output, spectrogram_output, ref_text_output, gen_text_output],
412
  fn=lambda *args: synthesize(model_choice.value, *args),
413
  cache_examples=True,
414
  run_on_click=True,
415
  )
416
 
 
 
 
 
 
 
 
 
417
  generate_btn.click(
418
  synthesize,
419
  inputs=[
@@ -427,7 +438,7 @@ with gr.Blocks(title="ESpeech-TTS") as app:
427
  nfe_slider,
428
  speed_slider,
429
  ],
430
- outputs=[audio_output, spectrogram_output, ref_text_output, gen_text_output]
431
  )
432
 
433
  if __name__ == "__main__":
 
163
  # Прогоняем через RUAccent
164
  return accentizer.process_all(text)
165
 
166
+ # ----------------- Функция для обработки текста без синтеза -----------------
167
+ def process_texts_only(ref_text, gen_text):
168
+ """
169
+ Обрабатывает только тексты через RUAccent, не делая синтез.
170
+ Возвращает обработанные тексты для обновления полей ввода.
171
+ """
172
+ processed_ref_text = process_text_with_accent(ref_text, accentizer)
173
+ processed_gen_text = process_text_with_accent(gen_text, accentizer)
174
+
175
+ return processed_ref_text, processed_gen_text
176
+
177
  # ----------------- Основная функция синтеза (GPU-aware) -----------------
178
  # Декорируем synthesize, чтобы при вызове Space выделял GPU (если доступно).
179
  # duration — сколько секунд просим GPU (адаптируйте под ваш инференс).
 
331
  # ----------------- Gradio UI (как у вас) -----------------
332
  with gr.Blocks(title="ESpeech-TTS") as app:
333
  gr.Markdown("# ESpeech-TTS")
334
+ gr.Markdown("Подробнее см. на https://huggingface.co/ESpeech")
335
+ gr.Markdown("💡 **Совет:** Добавьте символ '+' в тексте, чтобы указать пользовательское ударение (например, 'прив+ет'). Текст с '+' не будет обрабатываться RUAccent.")
336
+
337
  # Описание моделей на русском языке
338
  gr.Markdown("""
339
  ## 📋 Описание моделей:
 
360
  lines=2,
361
  placeholder="leave empty → ASR will transcribe"
362
  )
 
 
 
 
 
363
  with gr.Column():
364
  gen_text_input = gr.Textbox(
365
  label="Text to Generate",
 
367
  max_lines=20,
368
  placeholder="Enter text to synthesize..."
369
  )
370
+
371
+ # Кнопка для обработки текста без синтеза
372
+ process_text_btn = gr.Button("✏️ Process Text (Add Accents)", variant="secondary")
 
 
 
373
 
374
  with gr.Row():
375
  with gr.Column():
 
411
  nfe_slider,
412
  speed_slider,
413
  ],
414
+ outputs=[audio_output, spectrogram_output, ref_text_input, gen_text_input],
415
  fn=lambda *args: synthesize(model_choice.value, *args),
416
  cache_examples=True,
417
  run_on_click=True,
418
  )
419
 
420
+ # Обработка текста без синтеза
421
+ process_text_btn.click(
422
+ process_texts_only,
423
+ inputs=[ref_text_input, gen_text_input],
424
+ outputs=[ref_text_input, gen_text_input]
425
+ )
426
+
427
+ # Основная генерация
428
  generate_btn.click(
429
  synthesize,
430
  inputs=[
 
438
  nfe_slider,
439
  speed_slider,
440
  ],
441
+ outputs=[audio_output, spectrogram_output, ref_text_input, gen_text_input]
442
  )
443
 
444
  if __name__ == "__main__":