archivartaunik commited on
Commit
af468c1
·
verified ·
1 Parent(s): df2963e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -6,7 +6,7 @@ import torchaudio
6
  import gradio as gr
7
  from tqdm import tqdm
8
  from huggingface_hub import snapshot_download
9
-
10
  import sys
11
 
12
  # Клонуем рэпазіторый, калі ён яшчэ не загружаны
@@ -23,7 +23,21 @@ sys.path.append("./TTS")
23
  from underthesea import sent_tokenize
24
  from TTS.tts.configs.xtts_config import XttsConfig
25
  from TTS.tts.models.xtts import Xtts
26
- # Define repo and model paths
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  repo_id = "archivartaunik/BE_XTTS_V2_60epoch3Dataset"
28
  destination_dir = "checkpoints/XTTS_v2.0_original_model_files/"
29
 
@@ -45,9 +59,6 @@ for root, _, files in os.walk(local_repo_path):
45
 
46
  print(f"Model files are saved in {destination_dir}.")
47
 
48
- # Вызначэнне прылады (выкарыстоўваецца GPU, калі даступна)
49
- device = "cuda:0" if torch.cuda.is_available() else "cpu"
50
-
51
  # Load model
52
  print("Loading the model...")
53
  xtts_checkpoint = os.path.join(destination_dir, "model.pth")
@@ -58,10 +69,10 @@ config = XttsConfig()
58
  config.load_json(xtts_config)
59
  XTTS_MODEL = Xtts.init_from_config(config)
60
  XTTS_MODEL.load_checkpoint(config, checkpoint_path=xtts_checkpoint, vocab_path=xtts_vocab, use_deepspeed=False)
61
- XTTS_MODEL.to(device)
62
  print("Model loaded successfully!")
63
 
64
  # Function for inference
 
65
  def tts_inference(belarusian_text):
66
  lang = "be"
67
  speaker_audio_file = os.path.join(destination_dir, "voice.wav")
@@ -118,4 +129,4 @@ def gradio_app():
118
  # Launch the app
119
  if __name__ == "__main__":
120
  app = gradio_app()
121
- app.launch()
 
6
  import gradio as gr
7
  from tqdm import tqdm
8
  from huggingface_hub import snapshot_download
9
+ import spaces
10
  import sys
11
 
12
  # Клонуем рэпазіторый, калі ён яшчэ не загружаны
 
23
  from underthesea import sent_tokenize
24
  from TTS.tts.configs.xtts_config import XttsConfig
25
  from TTS.tts.models.xtts import Xtts
26
+
27
+
28
+ # Clone the repository if not already present
29
+ if not os.path.exists("XTTSv2-Finetuning-for-New-Languages"):
30
+ os.system("git clone https://github.com/hellcatmon/XTTSv2-Finetuning-for-New-Languages.git")
31
+
32
+ # Move the TTS directory to the current working directory
33
+ if os.path.exists("XTTSv2-Finetuning-for-New-Languages/TTS"):
34
+ os.system("mv XTTSv2-Finetuning-for-New-Languages/TTS ./")
35
+
36
+ # Add the TTS directory to the Python path
37
+ import sys
38
+ sys.path.append("./TTS")
39
+
40
+ # Define repository and model paths
41
  repo_id = "archivartaunik/BE_XTTS_V2_60epoch3Dataset"
42
  destination_dir = "checkpoints/XTTS_v2.0_original_model_files/"
43
 
 
59
 
60
  print(f"Model files are saved in {destination_dir}.")
61
 
 
 
 
62
  # Load model
63
  print("Loading the model...")
64
  xtts_checkpoint = os.path.join(destination_dir, "model.pth")
 
69
  config.load_json(xtts_config)
70
  XTTS_MODEL = Xtts.init_from_config(config)
71
  XTTS_MODEL.load_checkpoint(config, checkpoint_path=xtts_checkpoint, vocab_path=xtts_vocab, use_deepspeed=False)
 
72
  print("Model loaded successfully!")
73
 
74
  # Function for inference
75
+ @spaces.GPU
76
  def tts_inference(belarusian_text):
77
  lang = "be"
78
  speaker_audio_file = os.path.join(destination_dir, "voice.wav")
 
129
  # Launch the app
130
  if __name__ == "__main__":
131
  app = gradio_app()
132
+ app.launch()