xj commited on
Commit
4c9e450
1 Parent(s): 8f95475

[bug] 加快编译速度

Browse files
Files changed (3) hide show
  1. app.py +2 -4
  2. requirements.txt +6 -6
  3. utils.py +53 -53
app.py CHANGED
@@ -22,8 +22,6 @@ from models import SynthesizerTrn
22
  from text import text_to_sequence
23
  import torch
24
  from torch import no_grad, LongTensor
25
- import webbrowser
26
- import gradio.processing_utils as gr_processing_utils
27
  from gradio_client import utils as client_utils
28
  limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
29
 
@@ -45,10 +43,10 @@ def get_text(text, hps):
45
  def vits(text, language, speaker_id, noise_scale, noise_scale_w, length_scale):
46
  start = time.perf_counter()
47
  if not len(text):
48
- return "输入文本不能为空!", None, None
49
  text = text.replace('\n', ' ').replace('\r', '').replace(" ", "")
50
  if len(text) > 200 and limitation:
51
- return f"输入文字过长!{len(text)}>200", None, None
52
  if language == "中文":
53
  text = f"[ZH]{text}[ZH]"
54
  elif language == "日文":
 
22
  from text import text_to_sequence
23
  import torch
24
  from torch import no_grad, LongTensor
 
 
25
  from gradio_client import utils as client_utils
26
  limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
27
 
 
43
  def vits(text, language, speaker_id, noise_scale, noise_scale_w, length_scale):
44
  start = time.perf_counter()
45
  if not len(text):
46
+ return None
47
  text = text.replace('\n', ' ').replace('\r', '').replace(" ", "")
48
  if len(text) > 200 and limitation:
49
+ return None
50
  if language == "中文":
51
  text = f"[ZH]{text}[ZH]"
52
  elif language == "日文":
requirements.txt CHANGED
@@ -1,12 +1,12 @@
1
- Cython
2
  librosa
3
- matplotlib
4
  numpy
5
- phonemizer
6
- scipy
7
- tensorboard
8
  torch
9
- torchvision
10
  Unidecode
11
  pyopenjtalk
12
  ffmpeg
 
1
+ #Cython
2
  librosa
3
+ #matplotlib
4
  numpy
5
+ #phonemizer
6
+ #scipy
7
+ #tensorboard
8
  torch
9
+ #torchvision
10
  Unidecode
11
  pyopenjtalk
12
  ffmpeg
utils.py CHANGED
@@ -42,59 +42,59 @@ def load_checkpoint(checkpoint_path, model, optimizer=None):
42
  return model, optimizer, learning_rate, iteration
43
 
44
 
45
- def plot_spectrogram_to_numpy(spectrogram):
46
- global MATPLOTLIB_FLAG
47
- if not MATPLOTLIB_FLAG:
48
- import matplotlib
49
- matplotlib.use("Agg")
50
- MATPLOTLIB_FLAG = True
51
- mpl_logger = logging.getLogger('matplotlib')
52
- mpl_logger.setLevel(logging.WARNING)
53
- import matplotlib.pylab as plt
54
- import numpy as np
55
-
56
- fig, ax = plt.subplots(figsize=(10,2))
57
- im = ax.imshow(spectrogram, aspect="auto", origin="lower",
58
- interpolation='none')
59
- plt.colorbar(im, ax=ax)
60
- plt.xlabel("Frames")
61
- plt.ylabel("Channels")
62
- plt.tight_layout()
63
-
64
- fig.canvas.draw()
65
- data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
66
- data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
67
- plt.close()
68
- return data
69
-
70
-
71
- def plot_alignment_to_numpy(alignment, info=None):
72
- global MATPLOTLIB_FLAG
73
- if not MATPLOTLIB_FLAG:
74
- import matplotlib
75
- matplotlib.use("Agg")
76
- MATPLOTLIB_FLAG = True
77
- mpl_logger = logging.getLogger('matplotlib')
78
- mpl_logger.setLevel(logging.WARNING)
79
- import matplotlib.pylab as plt
80
- import numpy as np
81
-
82
- fig, ax = plt.subplots(figsize=(6, 4))
83
- im = ax.imshow(alignment.transpose(), aspect='auto', origin='lower',
84
- interpolation='none')
85
- fig.colorbar(im, ax=ax)
86
- xlabel = 'Decoder timestep'
87
- if info is not None:
88
- xlabel += '\n\n' + info
89
- plt.xlabel(xlabel)
90
- plt.ylabel('Encoder timestep')
91
- plt.tight_layout()
92
-
93
- fig.canvas.draw()
94
- data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
95
- data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
96
- plt.close()
97
- return data
98
 
99
 
100
  def load_audio_to_torch(full_path, target_sampling_rate):
 
42
  return model, optimizer, learning_rate, iteration
43
 
44
 
45
+ # def plot_spectrogram_to_numpy(spectrogram):
46
+ # global MATPLOTLIB_FLAG
47
+ # if not MATPLOTLIB_FLAG:
48
+ # import matplotlib
49
+ # matplotlib.use("Agg")
50
+ # MATPLOTLIB_FLAG = True
51
+ # mpl_logger = logging.getLogger('matplotlib')
52
+ # mpl_logger.setLevel(logging.WARNING)
53
+ # import matplotlib.pylab as plt
54
+ # import numpy as np
55
+
56
+ # fig, ax = plt.subplots(figsize=(10,2))
57
+ # im = ax.imshow(spectrogram, aspect="auto", origin="lower",
58
+ # interpolation='none')
59
+ # plt.colorbar(im, ax=ax)
60
+ # plt.xlabel("Frames")
61
+ # plt.ylabel("Channels")
62
+ # plt.tight_layout()
63
+
64
+ # fig.canvas.draw()
65
+ # data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
66
+ # data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
67
+ # plt.close()
68
+ # return data
69
+
70
+
71
+ # def plot_alignment_to_numpy(alignment, info=None):
72
+ # global MATPLOTLIB_FLAG
73
+ # if not MATPLOTLIB_FLAG:
74
+ # import matplotlib
75
+ # matplotlib.use("Agg")
76
+ # MATPLOTLIB_FLAG = True
77
+ # mpl_logger = logging.getLogger('matplotlib')
78
+ # mpl_logger.setLevel(logging.WARNING)
79
+ # import matplotlib.pylab as plt
80
+ # import numpy as np
81
+
82
+ # fig, ax = plt.subplots(figsize=(6, 4))
83
+ # im = ax.imshow(alignment.transpose(), aspect='auto', origin='lower',
84
+ # interpolation='none')
85
+ # fig.colorbar(im, ax=ax)
86
+ # xlabel = 'Decoder timestep'
87
+ # if info is not None:
88
+ # xlabel += '\n\n' + info
89
+ # plt.xlabel(xlabel)
90
+ # plt.ylabel('Encoder timestep')
91
+ # plt.tight_layout()
92
+
93
+ # fig.canvas.draw()
94
+ # data = np.fromstring(fig.canvas.tostring_rgb(), dtype=np.uint8, sep='')
95
+ # data = data.reshape(fig.canvas.get_width_height()[::-1] + (3,))
96
+ # plt.close()
97
+ # return data
98
 
99
 
100
  def load_audio_to_torch(full_path, target_sampling_rate):