chinmayc3 commited on
Commit
ba6f8aa
Β·
1 Parent(s): 6bb602d

UI improvements

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -224,6 +224,7 @@ def reset_state():
224
  st.session_state.option_2 = ""
225
  st.session_state.option_1_model_name_state = ""
226
  st.session_state.option_2_model_name_state = ""
 
227
 
228
  def on_option_1_click():
229
  if st.session_state.transcribed and not st.session_state.option_selected:
@@ -300,7 +301,7 @@ def on_option_none_click():
300
 
301
  def on_click_transcribe():
302
  if st.session_state.has_audio:
303
- with st.spinner("πŸ’Ύ Saving and loading results... please wait"):
304
  option_1_text, option_2_text = transcribe_audio(
305
  )
306
  st.session_state.option_1 = option_1_text
@@ -312,7 +313,7 @@ def on_click_transcribe():
312
 
313
  def on_random_click():
314
  reset_state()
315
- with st.spinner("πŸ’Ύ Saving and loading results... please wait"):
316
  fetch_audio_payload = {"task": "fetch_audio"}
317
  array, sampling_rate, filepath = send_task(fetch_audio_payload)
318
  st.session_state.audio = {"data":array,"sample_rate":sampling_rate,"format":"audio/wav"}
@@ -321,6 +322,9 @@ def on_random_click():
321
  st.session_state.audio_path = filepath
322
  st.session_state.option_selected = None
323
 
 
 
 
324
  writer_thread = threading.Thread(target=result_writer_thread)
325
  writer_thread.start()
326
 
@@ -350,6 +354,8 @@ def main():
350
  st.session_state.option_2_model_name_state = ""
351
  if "user_email" not in st.session_state:
352
  st.session_state.user_email = ""
 
 
353
 
354
  col1, col2 = st.columns([1, 1])
355
 
@@ -357,7 +363,7 @@ def main():
357
  st.markdown("### Record Audio")
358
  with st.container():
359
  audio_bytes = audio_recorder(
360
- text="πŸŽ™οΈ Click to Record",
361
  pause_threshold=3,
362
  icon_size="2x",
363
  key="audio_recorder",
@@ -375,18 +381,20 @@ def main():
375
  st.session_state.audio_path = tmp_file.name
376
  st.session_state.option_selected = None
377
  st.toast("Audio recorded successfully",icon="🎀")
 
378
 
379
  with col2:
380
  st.markdown("### Random Audio Example")
381
  with st.container():
382
- st.button("🎲 Random Audio",on_click=on_random_click,key="random_btn")
 
383
 
384
  if st.session_state.has_audio:
385
  st.audio(**st.session_state.audio)
386
 
387
 
388
  with st.container():
389
- st.button("πŸ“ Transcribe Audio",on_click=on_click_transcribe,use_container_width=True,key="transcribe_btn")
390
 
391
  text_containers = st.columns([1, 1])
392
  name_containers = st.columns([1, 1])
@@ -419,6 +427,9 @@ def main():
419
  with c4:
420
  st.button("Prefer None",on_click=on_option_none_click,key="none_btn")
421
 
 
 
 
422
  INSTR = """
423
  ## Instructions:
424
  * Record audio to recognise speech (or press 🎲 for random Audio).
 
224
  st.session_state.option_2 = ""
225
  st.session_state.option_1_model_name_state = ""
226
  st.session_state.option_2_model_name_state = ""
227
+ st.session_state.has_audio = False
228
 
229
  def on_option_1_click():
230
  if st.session_state.transcribed and not st.session_state.option_selected:
 
301
 
302
  def on_click_transcribe():
303
  if st.session_state.has_audio:
304
+ with st.spinner("Transcribing audio... this may take up to 30 seconds"):
305
  option_1_text, option_2_text = transcribe_audio(
306
  )
307
  st.session_state.option_1 = option_1_text
 
313
 
314
  def on_random_click():
315
  reset_state()
316
+ with st.spinner("Fetching random audio... please wait"):
317
  fetch_audio_payload = {"task": "fetch_audio"}
318
  array, sampling_rate, filepath = send_task(fetch_audio_payload)
319
  st.session_state.audio = {"data":array,"sample_rate":sampling_rate,"format":"audio/wav"}
 
322
  st.session_state.audio_path = filepath
323
  st.session_state.option_selected = None
324
 
325
+ def on_reset_click():
326
+ reset_state()
327
+
328
  writer_thread = threading.Thread(target=result_writer_thread)
329
  writer_thread.start()
330
 
 
354
  st.session_state.option_2_model_name_state = ""
355
  if "user_email" not in st.session_state:
356
  st.session_state.user_email = ""
357
+ if "recording" not in st.session_state:
358
+ st.session_state.recording = True
359
 
360
  col1, col2 = st.columns([1, 1])
361
 
 
363
  st.markdown("### Record Audio")
364
  with st.container():
365
  audio_bytes = audio_recorder(
366
+ text="Click microphone to start/stop recording",
367
  pause_threshold=3,
368
  icon_size="2x",
369
  key="audio_recorder",
 
381
  st.session_state.audio_path = tmp_file.name
382
  st.session_state.option_selected = None
383
  st.toast("Audio recorded successfully",icon="🎀")
384
+ st.session_state.recording = False
385
 
386
  with col2:
387
  st.markdown("### Random Audio Example")
388
  with st.container():
389
+ st.button("🎲 Select Random Audio",on_click=on_random_click,key="random_btn")
390
+ st.session_state.recording = False
391
 
392
  if st.session_state.has_audio:
393
  st.audio(**st.session_state.audio)
394
 
395
 
396
  with st.container():
397
+ st.button("πŸ“ Transcribe Audio",on_click=on_click_transcribe,use_container_width=True,key="transcribe_btn",disabled=st.session_state.recording)
398
 
399
  text_containers = st.columns([1, 1])
400
  name_containers = st.columns([1, 1])
 
427
  with c4:
428
  st.button("Prefer None",on_click=on_option_none_click,key="none_btn")
429
 
430
+ with st.container():
431
+ st.button("New Match",on_click=on_reset_click,key="reset_btn",use_container_width=True)
432
+
433
  INSTR = """
434
  ## Instructions:
435
  * Record audio to recognise speech (or press 🎲 for random Audio).