Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -450,7 +450,6 @@ if uploaded_file_paths is not None and len(uploaded_file_paths) > 0:
|
|
| 450 |
valid_files = []
|
| 451 |
file_paths = []
|
| 452 |
file_names = []
|
| 453 |
-
# Reset valid_files?
|
| 454 |
for uploaded_file in uploaded_file_paths:
|
| 455 |
if not uploaded_file.name.lower().endswith(supported_file_types):
|
| 456 |
st.error('File must be of type: {}'.format(supported_file_types))
|
|
@@ -466,22 +465,29 @@ if uploaded_file_paths is not None and len(uploaded_file_paths) > 0:
|
|
| 466 |
# Save valid file names
|
| 467 |
if len(valid_files) > 0:
|
| 468 |
file_names = [f.name for f in valid_files]
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 485 |
st.session_state.file_names = file_names
|
| 486 |
st.session_state.valid_files = valid_files
|
| 487 |
st.session_state.file_paths = file_paths
|
|
@@ -689,13 +695,10 @@ try:
|
|
| 689 |
st.sidebar.markdown(f"**{display_label}**")
|
| 690 |
if sp in file_clips:
|
| 691 |
st.sidebar.audio(file_clips[sp], format="audio/wav")
|
| 692 |
-
# IMPORTANT: label must stay fixed (use sp, not display_label) so Streamlit
|
| 693 |
-
# does not treat it as a new widget and reset its state on every rerun.
|
| 694 |
new_name = st.sidebar.text_input(
|
| 695 |
-
|
| 696 |
placeholder="e.g. John",
|
| 697 |
-
key=widget_key
|
| 698 |
-
label_visibility="collapsed"
|
| 699 |
)
|
| 700 |
if new_name.strip():
|
| 701 |
st.session_state.speakerRenames[currFileIndex][sp] = new_name.strip()
|
|
|
|
| 450 |
valid_files = []
|
| 451 |
file_paths = []
|
| 452 |
file_names = []
|
|
|
|
| 453 |
for uploaded_file in uploaded_file_paths:
|
| 454 |
if not uploaded_file.name.lower().endswith(supported_file_types):
|
| 455 |
st.error('File must be of type: {}'.format(supported_file_types))
|
|
|
|
| 465 |
# Save valid file names
|
| 466 |
if len(valid_files) > 0:
|
| 467 |
file_names = [f.name for f in valid_files]
|
| 468 |
+
|
| 469 |
+
# --- Reconcile per-file state lists against the new file set ---
|
| 470 |
+
# For each new file, carry over existing state if the filename matches a
|
| 471 |
+
# previously analyzed file, otherwise insert a fresh empty slot.
|
| 472 |
+
prev_names = st.session_state.file_names
|
| 473 |
+
def _carry(old_list, empty_val_fn):
|
| 474 |
+
new_list = []
|
| 475 |
+
for name in file_names:
|
| 476 |
+
if name in prev_names:
|
| 477 |
+
idx = prev_names.index(name)
|
| 478 |
+
new_list.append(old_list[idx] if idx < len(old_list) else empty_val_fn())
|
| 479 |
+
else:
|
| 480 |
+
new_list.append(empty_val_fn())
|
| 481 |
+
return new_list
|
| 482 |
+
|
| 483 |
+
st.session_state.results = _carry(st.session_state.results, lambda: [])
|
| 484 |
+
st.session_state.summaries = _carry(st.session_state.summaries, lambda: [])
|
| 485 |
+
st.session_state.unusedSpeakers= _carry(st.session_state.unusedSpeakers, lambda: [])
|
| 486 |
+
st.session_state.categorySelect= _carry(st.session_state.categorySelect,
|
| 487 |
+
lambda: [[] for _ in st.session_state.categories])
|
| 488 |
+
st.session_state.speakerRenames= _carry(st.session_state.speakerRenames, lambda: {})
|
| 489 |
+
st.session_state.speakerClips = _carry(st.session_state.speakerClips, lambda: {})
|
| 490 |
+
|
| 491 |
st.session_state.file_names = file_names
|
| 492 |
st.session_state.valid_files = valid_files
|
| 493 |
st.session_state.file_paths = file_paths
|
|
|
|
| 695 |
st.sidebar.markdown(f"**{display_label}**")
|
| 696 |
if sp in file_clips:
|
| 697 |
st.sidebar.audio(file_clips[sp], format="audio/wav")
|
|
|
|
|
|
|
| 698 |
new_name = st.sidebar.text_input(
|
| 699 |
+
f"Rename {display_label}",
|
| 700 |
placeholder="e.g. John",
|
| 701 |
+
key=widget_key
|
|
|
|
| 702 |
)
|
| 703 |
if new_name.strip():
|
| 704 |
st.session_state.speakerRenames[currFileIndex][sp] = new_name.strip()
|