duongthienz commited on
Commit
1a1c3e4
·
verified ·
1 Parent(s): 35bc7ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -151,7 +151,6 @@ def generate_speaker_clips(annotations, waveform, sample_rate, file_index):
151
 
152
  clip_waveform = waveform[:, start_sample:end_sample]
153
 
154
- # soundfile has no FFmpeg/torchcodec dependency
155
  import soundfile as sf
156
  clip_np = clip_waveform.numpy().T # (channels, samples) -> (samples, channels)
157
  buffer = io.BytesIO()
@@ -680,15 +679,18 @@ try:
680
  current_renames = st.session_state.speakerRenames[currFileIndex]
681
  for sp in speakerNames:
682
  widget_key = f"rename_{currFileIndex}_{sp}"
683
- live_name = st.session_state.get(widget_key, "").strip()
684
- display_label = live_name if live_name else current_renames.get(sp, sp)
 
 
 
 
 
685
  st.sidebar.markdown(f"**{display_label}**")
686
  if sp in file_clips:
687
  st.sidebar.audio(file_clips[sp], format="audio/wav")
688
- current_label = current_renames.get(sp, "")
689
  new_name = st.sidebar.text_input(
690
  f"Rename {display_label}",
691
- value=current_label,
692
  placeholder="e.g. John",
693
  key=widget_key
694
  )
 
151
 
152
  clip_waveform = waveform[:, start_sample:end_sample]
153
 
 
154
  import soundfile as sf
155
  clip_np = clip_waveform.numpy().T # (channels, samples) -> (samples, channels)
156
  buffer = io.BytesIO()
 
679
  current_renames = st.session_state.speakerRenames[currFileIndex]
680
  for sp in speakerNames:
681
  widget_key = f"rename_{currFileIndex}_{sp}"
682
+ # Seed the widget state once from speakerRenames (e.g. after a file switch).
683
+ # After that, never pass value= so Streamlit never overwrites what the user typed.
684
+ if widget_key not in st.session_state:
685
+ st.session_state[widget_key] = current_renames.get(sp, "")
686
+ # Use live widget value for the display label so it updates immediately
687
+ live_name = st.session_state[widget_key].strip()
688
+ display_label = live_name if live_name else sp
689
  st.sidebar.markdown(f"**{display_label}**")
690
  if sp in file_clips:
691
  st.sidebar.audio(file_clips[sp], format="audio/wav")
 
692
  new_name = st.sidebar.text_input(
693
  f"Rename {display_label}",
 
694
  placeholder="e.g. John",
695
  key=widget_key
696
  )