Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,12 +151,8 @@ def generate_speaker_clips(annotations, waveform, sample_rate, file_index):
|
|
| 151 |
|
| 152 |
clip_waveform = waveform[:, start_sample:end_sample]
|
| 153 |
|
| 154 |
-
# Use soundfile (pure C, no FFmpeg/torchcodec) to encode WAV bytes
|
| 155 |
-
# soundfile expects (samples, channels) numpy array; waveform is (channels, samples) tensor
|
| 156 |
-
clip_np = clip_waveform.numpy().T
|
| 157 |
buffer = io.BytesIO()
|
| 158 |
-
|
| 159 |
-
sf.write(buffer, clip_np, sample_rate, format="WAV", subtype="PCM_16")
|
| 160 |
buffer.seek(0)
|
| 161 |
clips[speaker] = buffer.read()
|
| 162 |
|
|
@@ -680,16 +676,19 @@ try:
|
|
| 680 |
|
| 681 |
current_renames = st.session_state.speakerRenames[currFileIndex]
|
| 682 |
for sp in speakerNames:
|
| 683 |
-
|
|
|
|
|
|
|
|
|
|
| 684 |
st.sidebar.markdown(f"**{display_label}**")
|
| 685 |
if sp in file_clips:
|
| 686 |
st.sidebar.audio(file_clips[sp], format="audio/wav")
|
| 687 |
current_label = current_renames.get(sp, "")
|
| 688 |
new_name = st.sidebar.text_input(
|
| 689 |
-
f"Rename {
|
| 690 |
value=current_label,
|
| 691 |
-
placeholder=
|
| 692 |
-
key=
|
| 693 |
)
|
| 694 |
if new_name.strip():
|
| 695 |
st.session_state.speakerRenames[currFileIndex][sp] = new_name.strip()
|
|
|
|
| 151 |
|
| 152 |
clip_waveform = waveform[:, start_sample:end_sample]
|
| 153 |
|
|
|
|
|
|
|
|
|
|
| 154 |
buffer = io.BytesIO()
|
| 155 |
+
torchaudio.save(buffer, clip_waveform, sample_rate, format="wav")
|
|
|
|
| 156 |
buffer.seek(0)
|
| 157 |
clips[speaker] = buffer.read()
|
| 158 |
|
|
|
|
| 676 |
|
| 677 |
current_renames = st.session_state.speakerRenames[currFileIndex]
|
| 678 |
for sp in speakerNames:
|
| 679 |
+
# Read the live widget value so label updates immediately on rename
|
| 680 |
+
widget_key = f"rename_{currFileIndex}_{sp}"
|
| 681 |
+
live_name = st.session_state.get(widget_key, "").strip()
|
| 682 |
+
display_label = live_name if live_name else current_renames.get(sp, sp)
|
| 683 |
st.sidebar.markdown(f"**{display_label}**")
|
| 684 |
if sp in file_clips:
|
| 685 |
st.sidebar.audio(file_clips[sp], format="audio/wav")
|
| 686 |
current_label = current_renames.get(sp, "")
|
| 687 |
new_name = st.sidebar.text_input(
|
| 688 |
+
f"Rename {display_label}",
|
| 689 |
value=current_label,
|
| 690 |
+
placeholder="e.g. John",
|
| 691 |
+
key=widget_key
|
| 692 |
)
|
| 693 |
if new_name.strip():
|
| 694 |
st.session_state.speakerRenames[currFileIndex][sp] = new_name.strip()
|