archivartaunik commited on
Commit
e2bbfc7
·
verified ·
1 Parent(s): f07b8c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -26
app.py CHANGED
@@ -1,5 +1,14 @@
1
- import os
 
 
 
 
 
 
 
2
  import sys
 
 
3
 
4
  # Клонуем рэпазіторый, калі ён яшчэ не загружаны
5
  if not os.path.exists("XTTSv2-Finetuning-for-New-Languages"):
@@ -12,25 +21,12 @@ if os.path.exists("XTTSv2-Finetuning-for-New-Languages/TTS"):
12
  # Дадаем тэчку TTS у PYTHONPATH
13
  sys.path.append("./TTS")
14
 
15
- # Усталёўваем залежнасці з рэпазіторыя
16
- #os.system("pip install -r XTTSv2-Finetuning-for-New-Languages/requirements.txt")
17
-
18
- # Імпартуем патрэбныя модулі
19
- import gradio as gr
20
- import torch
21
- from tqdm import tqdm
22
- from underthesea import sent_tokenize
23
- from TTS.tts.configs.xtts_config import XttsConfig
24
- from TTS.tts.models.xtts import Xtts
25
- from huggingface_hub import hf_hub_download
26
-
27
-
28
 
29
  # Вызначэнне прылады (выкарыстоўваецца GPU, калі даступна)
30
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
31
 
32
  # Шлях да мадэлі ў Hugging Face
33
- repo_id = "archivartaunik/GPT_XTTS_V2_40EP"
34
  checkpoint_file = hf_hub_download(repo_id, filename="model.pth")
35
  config_file = hf_hub_download(repo_id, filename="config.json")
36
  vocab_file = hf_hub_download(repo_id, filename="vocab.json")
@@ -62,13 +58,10 @@ def text_to_speech(belarusian_story, lang="be", speaker_audio_file=default_voice
62
  )
63
 
64
 
65
- import tempfile
66
- from scipy.io.wavfile import write
67
-
68
- def text_to_speech(belarusian_story, lang="be", speaker_audio_file=default_voice_file):
69
- # Правяраем, ці пададзены файл голасу
70
- if speaker_audio_file is None:
71
- raise ValueError("Speaker audio file is not provided.")
72
 
73
  # Атрыманне латэнтных умоў і эмацый
74
  gpt_cond_latent, speaker_embedding = XTTS_MODEL.get_conditioning_latents(
@@ -107,18 +100,19 @@ def text_to_speech(belarusian_story, lang="be", speaker_audio_file=default_voice
107
  return temp_file.name
108
 
109
 
110
- # Інтэрфейс Gradio
111
  demo = gr.Interface(
112
  fn=text_to_speech,
113
  inputs=[
114
  gr.Textbox(lines=5, label="Тэкст на беларускай мове"),
115
  gr.Textbox(value="be", label="Мова (па змаўчанні BE)", visible=False),
116
- gr.File(label="Файл голасу (па змаўчанні voice.wav)", file_types=[".wav"], interactive=True),
117
  ],
118
  outputs="audio",
119
- title="XTTS Belarusian TTS Demo",
120
- description="Увядзіце тэкст, і мадэль пераўтворыць яго ў аўдыя. Вы можаце выкарыстоўваць голас па змаўчанні або загрузіць уласны.",
121
  )
122
 
 
123
  if __name__ == "__main__":
124
  demo.launch()
 
1
+ # Імпартуем патрэбныя модулі
2
+ import gradio as gr
3
+ import torch
4
+ from tqdm import tqdm
5
+ from underthesea import sent_tokenize
6
+ from TTS.tts.configs.xtts_config import XttsConfig
7
+ from TTS.tts.models.xtts import Xtts
8
+ from huggingface_hub import hf_hub_downloadimport os
9
  import sys
10
+ import tempfile
11
+ from scipy.io.wavfile import write
12
 
13
  # Клонуем рэпазіторый, калі ён яшчэ не загружаны
14
  if not os.path.exists("XTTSv2-Finetuning-for-New-Languages"):
 
21
  # Дадаем тэчку TTS у PYTHONPATH
22
  sys.path.append("./TTS")
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  # Вызначэнне прылады (выкарыстоўваецца GPU, калі даступна)
26
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
27
 
28
  # Шлях да мадэлі ў Hugging Face
29
+ repo_id = "archivartaunik/BE_XTTS_V2_60epoch3Dataset"
30
  checkpoint_file = hf_hub_download(repo_id, filename="model.pth")
31
  config_file = hf_hub_download(repo_id, filename="config.json")
32
  vocab_file = hf_hub_download(repo_id, filename="vocab.json")
 
58
  )
59
 
60
 
61
+ def text_to_speech(belarusian_story, lang="be", speaker_audio_file=None):
62
+ # Калі файл не пададзены, выкарыстоўваем голас па змаўчанні
63
+ if not speaker_audio_file or (not isinstance(speaker_audio_file, str) and speaker_audio_file.name == ""):
64
+ speaker_audio_file = default_voice_file
 
 
 
65
 
66
  # Атрыманне латэнтных умоў і эмацый
67
  gpt_cond_latent, speaker_embedding = XTTS_MODEL.get_conditioning_latents(
 
100
  return temp_file.name
101
 
102
 
103
+
104
  demo = gr.Interface(
105
  fn=text_to_speech,
106
  inputs=[
107
  gr.Textbox(lines=5, label="Тэкст на беларускай мове"),
108
  gr.Textbox(value="be", label="Мова (па змаўчанні BE)", visible=False),
109
+ gr.Audio(source="microphone", type="filepath", label="Запішыце або загрузіце файл голасу (без іншых гукаў)", interactive=True),
110
  ],
111
  outputs="audio",
112
+ title="Belarusian TTS Demo",
113
+ description="Увядзіце тэкст і мадэль пераўтворыць яго ў аўдыя. Вы можаце выкарыстоўваць голас па змаўчанні, загрузіць уласны, або запісаць з мікрафона.",
114
  )
115
 
116
+
117
  if __name__ == "__main__":
118
  demo.launch()