sbapan41 commited on
Commit
e149bb5
·
verified ·
1 Parent(s): e4b5795

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -29
app.py CHANGED
@@ -4,35 +4,10 @@ import gradio as gr
4
  import os
5
  import random
6
  import torch
7
- #
8
  import logging
9
 
10
  logging.basicConfig(level=logging.INFO)
11
 
12
- def generate_first(text, voice='af_heart', speed=1, use_gpu=CUDA_AVAILABLE):
13
- logging.info(f"Received request: text={text}, voice={voice}, speed={speed}, use_gpu={use_gpu}")
14
- text = text if CHAR_LIMIT is None else text.strip()[:CHAR_LIMIT]
15
- pipeline = pipelines[voice[0]]
16
- pack = pipeline.load_voice(voice)
17
- use_gpu = use_gpu and CUDA_AVAILABLE
18
- for _, ps, _ in pipeline(text, voice, speed):
19
- ref_s = pack[len(ps)-1]
20
- try:
21
- if use_gpu:
22
- audio = forward_gpu(ps, ref_s, speed)
23
- else:
24
- audio = models[False](ps, ref_s, speed)
25
- except gr.exceptions.Error as e:
26
- if use_gpu:
27
- gr.Warning(str(e))
28
- gr.Info('Retrying with CPU. To avoid this error, change Hardware to CPU.')
29
- audio = models[False](ps, ref_s, speed)
30
- else:
31
- raise gr.Error(e)
32
- return (24000, audio.numpy()), ps
33
- return None, ''
34
- #
35
-
36
  IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('Quantamhash/')
37
  CUDA_AVAILABLE = torch.cuda.is_available()
38
  if not IS_DUPLICATE:
@@ -51,6 +26,7 @@ def forward_gpu(ps, ref_s, speed):
51
  return models[True](ps, ref_s, speed)
52
 
53
  def generate_first(text, voice='af_heart', speed=1, use_gpu=CUDA_AVAILABLE):
 
54
  text = text if CHAR_LIMIT is None else text.strip()[:CHAR_LIMIT]
55
  pipeline = pipelines[voice[0]]
56
  pack = pipeline.load_voice(voice)
@@ -156,11 +132,8 @@ for v in CHOICES.values():
156
 
157
  TOKEN_NOTE = '''
158
  💡 Customize pronunciation with Markdown link syntax and /slashes/ like `[Qhash-TTS]`
159
-
160
  💬 To adjust intonation, try punctuation `;:,.!?—…"()“”` or stress `ˈ` and `ˌ`
161
-
162
  ⬇️ Lower stress `[1 level](-1)` or `[2 levels](-2)`
163
-
164
  ⬆️ Raise stress 1 level `[or](+2)` 2 levels (only works on less stressed, usually short words)
165
  '''
166
 
@@ -190,7 +163,6 @@ with gr.Blocks() as stream_tab:
190
 
191
  BANNER_TEXT = '''
192
  [***Qhash-TTS*** **is an open-weight TTS model with 82 million parameters.**](https://huggingface.co/sbapan41/Qhash-TTS)
193
-
194
  This demo only showcases English, but you can directly use the model to access other languages.
195
  '''
196
  API_OPEN = True # Ensure API is open
 
4
  import os
5
  import random
6
  import torch
 
7
  import logging
8
 
9
  logging.basicConfig(level=logging.INFO)
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  IS_DUPLICATE = not os.getenv('SPACE_ID', '').startswith('Quantamhash/')
12
  CUDA_AVAILABLE = torch.cuda.is_available()
13
  if not IS_DUPLICATE:
 
26
  return models[True](ps, ref_s, speed)
27
 
28
  def generate_first(text, voice='af_heart', speed=1, use_gpu=CUDA_AVAILABLE):
29
+ logging.info(f"Received request: text={text}, voice={voice}, speed={speed}, use_gpu={use_gpu}")
30
  text = text if CHAR_LIMIT is None else text.strip()[:CHAR_LIMIT]
31
  pipeline = pipelines[voice[0]]
32
  pack = pipeline.load_voice(voice)
 
132
 
133
  TOKEN_NOTE = '''
134
  💡 Customize pronunciation with Markdown link syntax and /slashes/ like `[Qhash-TTS]`
 
135
  💬 To adjust intonation, try punctuation `;:,.!?—…"()“”` or stress `ˈ` and `ˌ`
 
136
  ⬇️ Lower stress `[1 level](-1)` or `[2 levels](-2)`
 
137
  ⬆️ Raise stress 1 level `[or](+2)` 2 levels (only works on less stressed, usually short words)
138
  '''
139
 
 
163
 
164
  BANNER_TEXT = '''
165
  [***Qhash-TTS*** **is an open-weight TTS model with 82 million parameters.**](https://huggingface.co/sbapan41/Qhash-TTS)
 
166
  This demo only showcases English, but you can directly use the model to access other languages.
167
  '''
168
  API_OPEN = True # Ensure API is open