Spaces:
Running
Running
Martijn Bartelds
commited on
Commit
·
b587f3a
1
Parent(s):
1eec854
Log errors
Browse files- neural_acoustic_distance.py +13 -0
neural_acoustic_distance.py
CHANGED
|
@@ -89,12 +89,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 |
gcm = aligner(feats_x, feats_y)
|
|
|
|
| 93 |
|
| 94 |
d = gcm.normalizedDistance
|
| 95 |
print("Distance:", d)
|
| 96 |
|
| 97 |
c, n = compute_costs(gcm)
|
|
|
|
| 98 |
return d, c, n
|
| 99 |
|
| 100 |
|
|
@@ -129,6 +132,8 @@ except OSError:
|
|
| 129 |
)
|
| 130 |
layer = None
|
| 131 |
|
|
|
|
|
|
|
| 132 |
st.subheader("Audio file selection:")
|
| 133 |
|
| 134 |
filename_x = st.selectbox("Filename (x-axis):",
|
|
@@ -156,6 +161,8 @@ if filename_x == "custom upload":
|
|
| 156 |
if filename_y == "custom upload":
|
| 157 |
filename_y = st.file_uploader("Choose a file (y-axis)", key="f_y")
|
| 158 |
|
|
|
|
|
|
|
| 159 |
if filename_x is not None and filename_y is not None and layer is not None:
|
| 160 |
print(f"\nX: {filename_x}\nY: {filename_y}")
|
| 161 |
|
|
@@ -164,6 +171,8 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
| 164 |
|
| 165 |
fig, axes = plt.subplots(figsize=(4, 2.5))
|
| 166 |
|
|
|
|
|
|
|
| 167 |
window_size = 9
|
| 168 |
rate = 20
|
| 169 |
x = np.arange(0, len(c) * rate, rate)
|
|
@@ -190,6 +199,8 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
| 190 |
plt.savefig("./output/plot.pdf")
|
| 191 |
st.pyplot(fig)
|
| 192 |
|
|
|
|
|
|
|
| 193 |
if os.path.isfile("./output/plot.pdf"):
|
| 194 |
st.caption(" Visualization of neural acoustic distances\
|
| 195 |
per frame (based on wav2vec 2.0) with the pronunciation of\
|
|
@@ -203,3 +214,5 @@ if filename_x is not None and filename_y is not None and layer is not None:
|
|
| 203 |
|
| 204 |
with open("./output/plot.pdf", "rb") as file:
|
| 205 |
btn = st.download_button(label="Download plot", data=file, file_name="plot.pdf", mime="image/pdf")
|
|
|
|
|
|
|
|
|
| 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 |
)
|
| 133 |
layer = None
|
| 134 |
|
| 135 |
+
print('1. Model selected') # test
|
| 136 |
+
|
| 137 |
st.subheader("Audio file selection:")
|
| 138 |
|
| 139 |
filename_x = st.selectbox("Filename (x-axis):",
|
|
|
|
| 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}")
|
| 168 |
|
|
|
|
| 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
|
| 178 |
x = np.arange(0, len(c) * rate, rate)
|
|
|
|
| 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\
|
| 206 |
per frame (based on wav2vec 2.0) with the pronunciation of\
|
|
|
|
| 214 |
|
| 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
|