Fabrice-TIERCELIN commited on
Commit
dd59b92
·
verified ·
1 Parent(s): 1d9aa0b

randomize_seed

Browse files
Files changed (1) hide show
  1. app.py +23 -4
app.py CHANGED
@@ -4,6 +4,7 @@ import re
4
  import time
5
  import math
6
  import torch
 
7
  import spaces
8
  # By using XTTS you agree to CPML license https://coqui.ai/cpml
9
  os.environ["COQUI_TOS_AGREED"] = "1"
@@ -11,6 +12,8 @@ os.environ["COQUI_TOS_AGREED"] = "1"
11
  import gradio as gr
12
  from TTS.api import TTS
13
  from TTS.utils.manage import ModelManager
 
 
14
  model_names = TTS().list_models()
15
  print(model_names.__dict__)
16
  print(model_names.__dir__())
@@ -32,8 +35,12 @@ else:
32
  tts = TTS(model_name, gpu=torch.cuda.is_available())
33
  tts.to(device_type)
34
 
35
- def predict(prompt, language, gender, audio_file_pth, mic_file_path, use_mic):
36
  start = time.time()
 
 
 
 
37
  if len(prompt) < 2:
38
  gr.Warning("Please give a longer prompt text")
39
  return (
@@ -76,7 +83,7 @@ def predict(prompt, language, gender, audio_file_pth, mic_file_path, use_mic):
76
  language = "fr-fr"
77
  if m.find("/fr/") != -1:
78
  language = None
79
- predict_on_gpu(prompt, speaker_wav, language, output_filename)
80
  except RuntimeError as e :
81
  if "device-assert" in str(e):
82
  # cannot do anything on cuda device side error, need to restart
@@ -102,7 +109,10 @@ def predict(prompt, language, gender, audio_file_pth, mic_file_path, use_mic):
102
  )
103
 
104
  @spaces.GPU(duration=60)
105
- def predict_on_gpu(prompt, speaker_wav, language, output_filename):
 
 
 
106
  tts.tts_to_file(
107
  text = prompt,
108
  file_path = output_filename,
@@ -174,6 +184,8 @@ Leave a star on the Github <a href="https://github.com/coqui-ai/TTS">TTS</a>, wh
174
  info="Notice: Microphone input may not work properly under traffic",)
175
  with gr.Accordion("Advanced options", open = False):
176
  debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
 
 
177
 
178
  submit = gr.Button("🚀 Speak", variant = "primary")
179
 
@@ -182,7 +194,14 @@ Leave a star on the Github <a href="https://github.com/coqui-ai/TTS">TTS</a>, wh
182
  information = gr.HTML()
183
 
184
  submit.click(predict, inputs = [
185
- prompt, language, gender, audio_file_pth, mic_file_path, use_mic
 
 
 
 
 
 
 
186
  ], outputs = [
187
  waveform_visual,
188
  synthesised_audio,
 
4
  import time
5
  import math
6
  import torch
7
+ import random
8
  import spaces
9
  # By using XTTS you agree to CPML license https://coqui.ai/cpml
10
  os.environ["COQUI_TOS_AGREED"] = "1"
 
12
  import gradio as gr
13
  from TTS.api import TTS
14
  from TTS.utils.manage import ModelManager
15
+
16
+ max_64_bit_int = 2**63 - 1
17
  model_names = TTS().list_models()
18
  print(model_names.__dict__)
19
  print(model_names.__dir__())
 
35
  tts = TTS(model_name, gpu=torch.cuda.is_available())
36
  tts.to(device_type)
37
 
38
+ def predict(prompt, language, gender, audio_file_pth, mic_file_path, use_mic, randomize_seed, seed):
39
  start = time.time()
40
+
41
+ if randomize_seed:
42
+ seed = random.randint(0, max_64_bit_int)
43
+
44
  if len(prompt) < 2:
45
  gr.Warning("Please give a longer prompt text")
46
  return (
 
83
  language = "fr-fr"
84
  if m.find("/fr/") != -1:
85
  language = None
86
+ predict_on_gpu(prompt, speaker_wav, language, output_filename, seed)
87
  except RuntimeError as e :
88
  if "device-assert" in str(e):
89
  # cannot do anything on cuda device side error, need to restart
 
109
  )
110
 
111
  @spaces.GPU(duration=60)
112
+ def predict_on_gpu(prompt, speaker_wav, language, output_filename, seed):
113
+ random.seed(seed)
114
+ torch.manual_seed(seed)
115
+
116
  tts.tts_to_file(
117
  text = prompt,
118
  file_path = output_filename,
 
184
  info="Notice: Microphone input may not work properly under traffic",)
185
  with gr.Accordion("Advanced options", open = False):
186
  debug_mode = gr.Checkbox(label = "Debug mode", value = False, info = "Show intermediate results")
187
+ randomize_seed = gr.Checkbox(label = "\U0001F3B2 Randomize seed", value = True, info = "If checked, result is always different")
188
+ seed = gr.Slider(minimum = 0, maximum = max_64_bit_int, step = 1, randomize = True, label = "Seed")
189
 
190
  submit = gr.Button("🚀 Speak", variant = "primary")
191
 
 
194
  information = gr.HTML()
195
 
196
  submit.click(predict, inputs = [
197
+ prompt,
198
+ language,
199
+ gender,
200
+ audio_file_pth,
201
+ mic_file_path,
202
+ use_mic,
203
+ randomize_seed,
204
+ seed
205
  ], outputs = [
206
  waveform_visual,
207
  synthesised_audio,