hexgrad commited on
Commit
1abc286
·
verified ·
1 Parent(s): 22b8f4b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -233,7 +233,7 @@ def clamp_speed(speed):
233
  return speed
234
 
235
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
236
- def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto'):
237
  voices = resolve_voices(voice, warn=ps)
238
  ps = ps or phonemize(text, voice)
239
  speed = clamp_speed(speed)
@@ -246,9 +246,7 @@ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto'):
246
  tokens = tokens[:510]
247
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
248
  use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
249
- is_space = os.environ.get('SPACE_ID') is not None
250
- is_api_call = os.environ.get('GRADIO_ENDPOINT') is not None
251
- print('🔥', datetime.now(), text, voices, ps, use_gpu, is_space, is_api_call)
252
  try:
253
  if use_gpu:
254
  out = forward_gpu(tokens, voices, speed)
@@ -325,6 +323,8 @@ with gr.Blocks() as basic_tts:
325
  voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
326
  text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
327
  generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
 
 
328
 
329
  @torch.no_grad()
330
  def lf_forward(token_lists, voices, speed, device='cpu'):
 
233
  return speed
234
 
235
  # Must be backwards compatible with https://huggingface.co/spaces/Pendrokar/TTS-Spaces-Arena
236
+ def generate(text, voice='af', ps=None, speed=1, trim=3000, use_gpu='auto', sh=None):
237
  voices = resolve_voices(voice, warn=ps)
238
  ps = ps or phonemize(text, voice)
239
  speed = clamp_speed(speed)
 
246
  tokens = tokens[:510]
247
  ps = ''.join(next(k for k, v in VOCAB.items() if i == v) for i in tokens)
248
  use_gpu = len(ps) > 99 if use_gpu == 'auto' else use_gpu
249
+ print('🔥', datetime.now(), text, voices, ps, use_gpu, is_space, sh)
 
 
250
  try:
251
  if use_gpu:
252
  out = forward_gpu(tokens, voices, speed)
 
323
  voice.change(lambda v, b: gr.Button(b, variant='primary' if v.startswith(b[:2]) else 'secondary'), inputs=[voice, btn], outputs=[btn])
324
  text.submit(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
325
  generate_btn.click(generate, inputs=[text, voice, in_ps, speed, trim, use_gpu], outputs=[audio, out_ps])
326
+ sh = gr.State()
327
+ basic_tts.load(lambda r: r.session_hash, None, sh)
328
 
329
  @torch.no_grad()
330
  def lf_forward(token_lists, voices, speed, device='cpu'):