Spaces:
Runtime error
Runtime error
Upload vocoder/display.py with huggingface_hub
Browse files- vocoder/display.py +120 -0
vocoder/display.py
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib.pyplot as plt
|
2 |
+
import time
|
3 |
+
import numpy as np
|
4 |
+
import sys
|
5 |
+
|
6 |
+
|
7 |
+
def progbar(i, n, size=16):
|
8 |
+
done = (i * size) // n
|
9 |
+
bar = ''
|
10 |
+
for i in range(size):
|
11 |
+
bar += 'β' if i <= done else 'β'
|
12 |
+
return bar
|
13 |
+
|
14 |
+
|
15 |
+
def stream(message) :
|
16 |
+
try:
|
17 |
+
sys.stdout.write("\r{%s}" % message)
|
18 |
+
except:
|
19 |
+
#Remove non-ASCII characters from message
|
20 |
+
message = ''.join(i for i in message if ord(i)<128)
|
21 |
+
sys.stdout.write("\r{%s}" % message)
|
22 |
+
|
23 |
+
|
24 |
+
def simple_table(item_tuples) :
|
25 |
+
|
26 |
+
border_pattern = '+---------------------------------------'
|
27 |
+
whitespace = ' '
|
28 |
+
|
29 |
+
headings, cells, = [], []
|
30 |
+
|
31 |
+
for item in item_tuples :
|
32 |
+
|
33 |
+
heading, cell = str(item[0]), str(item[1])
|
34 |
+
|
35 |
+
pad_head = True if len(heading) < len(cell) else False
|
36 |
+
|
37 |
+
pad = abs(len(heading) - len(cell))
|
38 |
+
pad = whitespace[:pad]
|
39 |
+
|
40 |
+
pad_left = pad[:len(pad)//2]
|
41 |
+
pad_right = pad[len(pad)//2:]
|
42 |
+
|
43 |
+
if pad_head :
|
44 |
+
heading = pad_left + heading + pad_right
|
45 |
+
else :
|
46 |
+
cell = pad_left + cell + pad_right
|
47 |
+
|
48 |
+
headings += [heading]
|
49 |
+
cells += [cell]
|
50 |
+
|
51 |
+
border, head, body = '', '', ''
|
52 |
+
|
53 |
+
for i in range(len(item_tuples)) :
|
54 |
+
|
55 |
+
temp_head = f'| {headings[i]} '
|
56 |
+
temp_body = f'| {cells[i]} '
|
57 |
+
|
58 |
+
border += border_pattern[:len(temp_head)]
|
59 |
+
head += temp_head
|
60 |
+
body += temp_body
|
61 |
+
|
62 |
+
if i == len(item_tuples) - 1 :
|
63 |
+
head += '|'
|
64 |
+
body += '|'
|
65 |
+
border += '+'
|
66 |
+
|
67 |
+
print(border)
|
68 |
+
print(head)
|
69 |
+
print(border)
|
70 |
+
print(body)
|
71 |
+
print(border)
|
72 |
+
print(' ')
|
73 |
+
|
74 |
+
|
75 |
+
def time_since(started) :
|
76 |
+
elapsed = time.time() - started
|
77 |
+
m = int(elapsed // 60)
|
78 |
+
s = int(elapsed % 60)
|
79 |
+
if m >= 60 :
|
80 |
+
h = int(m // 60)
|
81 |
+
m = m % 60
|
82 |
+
return f'{h}h {m}m {s}s'
|
83 |
+
else :
|
84 |
+
return f'{m}m {s}s'
|
85 |
+
|
86 |
+
|
87 |
+
def save_attention(attn, path) :
|
88 |
+
fig = plt.figure(figsize=(12, 6))
|
89 |
+
plt.imshow(attn.T, interpolation='nearest', aspect='auto')
|
90 |
+
fig.savefig(f'{path}.png', bbox_inches='tight')
|
91 |
+
plt.close(fig)
|
92 |
+
|
93 |
+
|
94 |
+
def save_spectrogram(M, path, length=None) :
|
95 |
+
M = np.flip(M, axis=0)
|
96 |
+
if length : M = M[:, :length]
|
97 |
+
fig = plt.figure(figsize=(12, 6))
|
98 |
+
plt.imshow(M, interpolation='nearest', aspect='auto')
|
99 |
+
fig.savefig(f'{path}.png', bbox_inches='tight')
|
100 |
+
plt.close(fig)
|
101 |
+
|
102 |
+
|
103 |
+
def plot(array) :
|
104 |
+
fig = plt.figure(figsize=(30, 5))
|
105 |
+
ax = fig.add_subplot(111)
|
106 |
+
ax.xaxis.label.set_color('grey')
|
107 |
+
ax.yaxis.label.set_color('grey')
|
108 |
+
ax.xaxis.label.set_fontsize(23)
|
109 |
+
ax.yaxis.label.set_fontsize(23)
|
110 |
+
ax.tick_params(axis='x', colors='grey', labelsize=23)
|
111 |
+
ax.tick_params(axis='y', colors='grey', labelsize=23)
|
112 |
+
plt.plot(array)
|
113 |
+
|
114 |
+
|
115 |
+
def plot_spec(M) :
|
116 |
+
M = np.flip(M, axis=0)
|
117 |
+
plt.figure(figsize=(18,4))
|
118 |
+
plt.imshow(M, interpolation='nearest', aspect='auto')
|
119 |
+
plt.show()
|
120 |
+
|