Spaces:
Running
Running
Martijn Bartelds
commited on
Commit
·
8b8c6ec
1
Parent(s):
b587f3a
Update log errors
Browse files- neural_acoustic_distance.py +10 -8
neural_acoustic_distance.py
CHANGED
@@ -12,6 +12,8 @@ from scipy import signal
|
|
12 |
from transformers import AutoConfig
|
13 |
from transformers.models.wav2vec2 import Wav2Vec2Model
|
14 |
|
|
|
|
|
15 |
|
16 |
def play_audio(filename):
|
17 |
audio_file = open(filename, "rb")
|
@@ -89,15 +91,15 @@ def run(model_id, layer, filename_x, filename_y):
|
|
89 |
with st.spinner("Measuring distance..."):
|
90 |
feats_x = featurizer(filename_x)
|
91 |
feats_y = featurizer(filename_y)
|
92 |
-
print('3. Features computed') # test
|
93 |
gcm = aligner(feats_x, feats_y)
|
94 |
-
print('4. Alignments computed') # test
|
95 |
|
96 |
d = gcm.normalizedDistance
|
97 |
print("Distance:", d)
|
98 |
|
99 |
c, n = compute_costs(gcm)
|
100 |
-
print('5. Costs computed') # test
|
101 |
return d, c, n
|
102 |
|
103 |
|
@@ -132,7 +134,7 @@ except OSError:
|
|
132 |
)
|
133 |
layer = None
|
134 |
|
135 |
-
print('1. Model selected') # test
|
136 |
|
137 |
st.subheader("Audio file selection:")
|
138 |
|
@@ -161,7 +163,7 @@ if filename_x == "custom upload":
|
|
161 |
if filename_y == "custom upload":
|
162 |
filename_y = st.file_uploader("Choose a file (y-axis)", key="f_y")
|
163 |
|
164 |
-
print('2. Files selected') # test
|
165 |
|
166 |
if filename_x is not None and filename_y is not None and layer is not None:
|
167 |
print(f"\nX: {filename_x}\nY: {filename_y}")
|
@@ -171,7 +173,7 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
171 |
|
172 |
fig, axes = plt.subplots(figsize=(4, 2.5))
|
173 |
|
174 |
-
print('6. Plot init') # test
|
175 |
|
176 |
window_size = 9
|
177 |
rate = 20
|
@@ -199,7 +201,7 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
199 |
plt.savefig("./output/plot.pdf")
|
200 |
st.pyplot(fig)
|
201 |
|
202 |
-
print('7. Plot filled') # test
|
203 |
|
204 |
if os.path.isfile("./output/plot.pdf"):
|
205 |
st.caption(" Visualization of neural acoustic distances\
|
@@ -215,4 +217,4 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
215 |
with open("./output/plot.pdf", "rb") as file:
|
216 |
btn = st.download_button(label="Download plot", data=file, file_name="plot.pdf", mime="image/pdf")
|
217 |
|
218 |
-
print('8. End') # test
|
|
|
12 |
from transformers import AutoConfig
|
13 |
from transformers.models.wav2vec2 import Wav2Vec2Model
|
14 |
|
15 |
+
from datetime import datetime # test
|
16 |
+
|
17 |
|
18 |
def play_audio(filename):
|
19 |
audio_file = open(filename, "rb")
|
|
|
91 |
with st.spinner("Measuring distance..."):
|
92 |
feats_x = featurizer(filename_x)
|
93 |
feats_y = featurizer(filename_y)
|
94 |
+
print('3. Features computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
95 |
gcm = aligner(feats_x, feats_y)
|
96 |
+
print('4. Alignments computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
97 |
|
98 |
d = gcm.normalizedDistance
|
99 |
print("Distance:", d)
|
100 |
|
101 |
c, n = compute_costs(gcm)
|
102 |
+
print('5. Costs computed', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
103 |
return d, c, n
|
104 |
|
105 |
|
|
|
134 |
)
|
135 |
layer = None
|
136 |
|
137 |
+
print('1. Model selected', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
138 |
|
139 |
st.subheader("Audio file selection:")
|
140 |
|
|
|
163 |
if filename_y == "custom upload":
|
164 |
filename_y = st.file_uploader("Choose a file (y-axis)", key="f_y")
|
165 |
|
166 |
+
print('2. Files selected', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
167 |
|
168 |
if filename_x is not None and filename_y is not None and layer is not None:
|
169 |
print(f"\nX: {filename_x}\nY: {filename_y}")
|
|
|
173 |
|
174 |
fig, axes = plt.subplots(figsize=(4, 2.5))
|
175 |
|
176 |
+
print('6. Plot init', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
177 |
|
178 |
window_size = 9
|
179 |
rate = 20
|
|
|
201 |
plt.savefig("./output/plot.pdf")
|
202 |
st.pyplot(fig)
|
203 |
|
204 |
+
print('7. Plot filled', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|
205 |
|
206 |
if os.path.isfile("./output/plot.pdf"):
|
207 |
st.caption(" Visualization of neural acoustic distances\
|
|
|
217 |
with open("./output/plot.pdf", "rb") as file:
|
218 |
btn = st.download_button(label="Download plot", data=file, file_name="plot.pdf", mime="image/pdf")
|
219 |
|
220 |
+
print('8. End', datetime.now().strftime('%d-%m-%Y %H:%M:%S')) # test
|