2pift commited on
Commit
22a76e8
·
1 Parent(s): daa813b

Application desing

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +11 -11
src/streamlit_app.py CHANGED
@@ -131,7 +131,7 @@ def handle_upload(label: str, key: str) -> np.ndarray | None:
131
  return None
132
 
133
  def delta(x):
134
- """Computes first-order difference along time axis."""
135
  return x[:, 1:] - x[:, :-1]
136
 
137
  def array_to_spectrogram(audio_np: np.ndarray,
@@ -175,9 +175,9 @@ def verify_speakers(model, audio_left, audio_right, margin):
175
  cosine_similarity = float(cosine_similarity.numpy().squeeze())
176
 
177
  if cosine_similarity >= margin:
178
- st.success("Both voice recordings belong to the same person.")
179
  else:
180
- st.warning("The voice recordings belong to different people.")
181
  st.caption(f"Cosine similarity: {cosine_similarity:.4f}, margin: {margin:.4f}")
182
 
183
  # ========= Load model =========
@@ -188,7 +188,7 @@ if st.session_state.load_model_button:
188
  filename="best_model.keras",
189
  revision="v1.0.0",
190
  )
191
- st.success("Model loaded. You can now upload/record audio files.")
192
  st.download_button(
193
  "(Option) Download the model file",
194
  data=model_bytes,
@@ -201,8 +201,8 @@ if st.session_state.load_model_button:
201
  left_column, right_column = st.columns(2)
202
 
203
  with left_column:
204
- st.subheader("Left input")
205
- record_left = st.checkbox("Record left input")
206
  if record_left:
207
  audio_left = handle_record("Record (left)")
208
  else:
@@ -210,12 +210,12 @@ if st.session_state.load_model_button:
210
  if audio_left is not None:
211
  st.session_state.audio_left = audio_left
212
  fig = plot_waveform(audio_left, FS, "Left audio waveform")
213
- st.pyplot(fig, use_container_width=True)
214
  st.caption(f"Samples: {audio_left.size} • Duration: {audio_left.size/FS:.2f}s")
215
 
216
  with right_column:
217
- st.subheader("Right input")
218
- record_right = st.checkbox("Record right input")
219
  if record_right:
220
  audio_right = handle_record("Record (right)")
221
  else:
@@ -223,12 +223,12 @@ if st.session_state.load_model_button:
223
  if audio_right is not None:
224
  st.session_state.audio_right = audio_right
225
  fig = plot_waveform(audio_right, FS, "Right audio waveform")
226
- st.pyplot(fig, use_container_width=True)
227
  st.caption(f"Samples: {audio_right.size} • Duration: {audio_right.size/FS:.2f}s")
228
 
229
  if audio_left is not None and audio_right is not None:
230
  margin = st.slider('Selected margin:', -1.0, 1.0, 0.26, 0.01)
231
- verify_button = st.button("Verify speaker!")
232
  if verify_button:
233
  try:
234
  verify_speakers(model, audio_left, audio_right, margin)
 
131
  return None
132
 
133
  def delta(x):
134
+ """Computes first-order derivative along time axis."""
135
  return x[:, 1:] - x[:, :-1]
136
 
137
  def array_to_spectrogram(audio_np: np.ndarray,
 
175
  cosine_similarity = float(cosine_similarity.numpy().squeeze())
176
 
177
  if cosine_similarity >= margin:
178
+ st.success("Both utterances belong to the same speaker.")
179
  else:
180
+ st.warning("The utterances are from different speakers.")
181
  st.caption(f"Cosine similarity: {cosine_similarity:.4f}, margin: {margin:.4f}")
182
 
183
  # ========= Load model =========
 
188
  filename="best_model.keras",
189
  revision="v1.0.0",
190
  )
191
+ st.success("Model loaded you can upload audio files or record utterances.")
192
  st.download_button(
193
  "(Option) Download the model file",
194
  data=model_bytes,
 
201
  left_column, right_column = st.columns(2)
202
 
203
  with left_column:
204
+ st.subheader("Voice Sample 1")
205
+ record_left = st.checkbox("Record first voice sample", key="chk_record_left")
206
  if record_left:
207
  audio_left = handle_record("Record (left)")
208
  else:
 
210
  if audio_left is not None:
211
  st.session_state.audio_left = audio_left
212
  fig = plot_waveform(audio_left, FS, "Left audio waveform")
213
+ st.pyplot(fig, width="stretch")
214
  st.caption(f"Samples: {audio_left.size} • Duration: {audio_left.size/FS:.2f}s")
215
 
216
  with right_column:
217
+ st.subheader("Voice Sample 2")
218
+ record_right = st.checkbox("Record second voice sample", key="chk_record_right")
219
  if record_right:
220
  audio_right = handle_record("Record (right)")
221
  else:
 
223
  if audio_right is not None:
224
  st.session_state.audio_right = audio_right
225
  fig = plot_waveform(audio_right, FS, "Right audio waveform")
226
+ st.pyplot(fig, width="stretch")
227
  st.caption(f"Samples: {audio_right.size} • Duration: {audio_right.size/FS:.2f}s")
228
 
229
  if audio_left is not None and audio_right is not None:
230
  margin = st.slider('Selected margin:', -1.0, 1.0, 0.26, 0.01)
231
+ verify_button = st.button("Verify Speaker")
232
  if verify_button:
233
  try:
234
  verify_speakers(model, audio_left, audio_right, margin)