Spaces:
Sleeping
Sleeping
Add Population tab and convert .csv to .xml (May need more adjust)
Browse files
app.py
CHANGED
|
@@ -27,6 +27,8 @@ from state import (
|
|
| 27 |
updateMultiSelect, store_speaker_clips, register_file, analyze,
|
| 28 |
load_demo_single, load_demo_single_sample, load_demo_multi, run_analysis_loop,
|
| 29 |
build_all_csv_zip,
|
|
|
|
|
|
|
| 30 |
)
|
| 31 |
|
| 32 |
# ---------------------------------------------------------------------------
|
|
@@ -259,8 +261,8 @@ try:
|
|
| 259 |
|
| 260 |
st.header(f"Analysis of file {currFile}")
|
| 261 |
TAB_NAMES = ["Speakers & Roles", "Pie Chart", "Sunburst",
|
| 262 |
-
"Treemap", "Time Spoken", "Timeline", "Download"]
|
| 263 |
-
renameTab, pie2, sunburst1, treemap1, bar1, timeline, dataTab = st.tabs(TAB_NAMES)
|
| 264 |
|
| 265 |
currAnnotation, currTotalTime = st.session_state.results[currFile]
|
| 266 |
speakerNames = currAnnotation.labels()
|
|
@@ -340,6 +342,55 @@ try:
|
|
| 340 |
# Tab: Data
|
| 341 |
# -----------------------------------------------------------------------
|
| 342 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
with dataTab:
|
| 344 |
# Build raw-speaker -> role lookup against the RAW currDF (before renames
|
| 345 |
# are applied) so the map keys match the original SPEAKER_## labels.
|
|
@@ -356,19 +407,20 @@ try:
|
|
| 356 |
displayDF = displayDF.rename(columns={"Resource": "Speaker"})
|
| 357 |
if "Start" in displayDF.columns:
|
| 358 |
displayDF = displayDF.sort_values("Start").reset_index(drop=True)
|
| 359 |
-
|
|
|
|
| 360 |
st.download_button(
|
| 361 |
-
f"Download {currPlainName}.
|
| 362 |
-
f"sonogram-analysis-{currPlainName}.
|
| 363 |
-
key="download-
|
| 364 |
)
|
| 365 |
|
| 366 |
analyzed_count = sum(
|
| 367 |
1 for r in st.session_state.results.values() if len(r) == 2
|
| 368 |
)
|
| 369 |
-
zip_bytes =
|
| 370 |
st.download_button(
|
| 371 |
-
"Download all analyzed datas.
|
| 372 |
"sonogram-analysis-all.zip", "application/zip",
|
| 373 |
key="download-all-zip", on_click="ignore",
|
| 374 |
disabled=(analyzed_count <= 1),
|
|
|
|
| 27 |
updateMultiSelect, store_speaker_clips, register_file, analyze,
|
| 28 |
load_demo_single, load_demo_single_sample, load_demo_multi, run_analysis_loop,
|
| 29 |
build_all_csv_zip,
|
| 30 |
+
build_xml_download,
|
| 31 |
+
build_all_xml_zip,
|
| 32 |
)
|
| 33 |
|
| 34 |
# ---------------------------------------------------------------------------
|
|
|
|
| 261 |
|
| 262 |
st.header(f"Analysis of file {currFile}")
|
| 263 |
TAB_NAMES = ["Speakers & Roles", "Pie Chart", "Sunburst",
|
| 264 |
+
"Treemap", "Time Spoken", "Timeline", "Population", "Download"]
|
| 265 |
+
renameTab, pie2, sunburst1, treemap1, bar1, timeline, populationTab, dataTab = st.tabs(TAB_NAMES)
|
| 266 |
|
| 267 |
currAnnotation, currTotalTime = st.session_state.results[currFile]
|
| 268 |
speakerNames = currAnnotation.labels()
|
|
|
|
| 342 |
# Tab: Data
|
| 343 |
# -----------------------------------------------------------------------
|
| 344 |
|
| 345 |
+
# -----------------------------------------------------------------------
|
| 346 |
+
# Tab: Population
|
| 347 |
+
# -----------------------------------------------------------------------
|
| 348 |
+
|
| 349 |
+
with populationTab:
|
| 350 |
+
st.markdown("Enter the number of students present in each recording.")
|
| 351 |
+
pop_header_cols = st.columns([4, 2, 1])
|
| 352 |
+
pop_header_cols[0].markdown("**File Name**")
|
| 353 |
+
pop_header_cols[1].markdown("**Number of Students**")
|
| 354 |
+
st.markdown("<hr style='margin-top:2px; margin-bottom:4px;'>",
|
| 355 |
+
unsafe_allow_html=True)
|
| 356 |
+
for fn in st.session_state.file_names:
|
| 357 |
+
if not (fn in st.session_state.results
|
| 358 |
+
and len(st.session_state.results[fn]) == 2):
|
| 359 |
+
continue
|
| 360 |
+
plain = fn.rsplit(".", 1)[0]
|
| 361 |
+
edit_key = f"pop_editing_{fn}"
|
| 362 |
+
input_key = f"pop_input_{fn}"
|
| 363 |
+
current_pop = st.session_state.studentPopulations.get(fn)
|
| 364 |
+
|
| 365 |
+
row_cols = st.columns([4, 2, 1])
|
| 366 |
+
row_cols[0].write(plain)
|
| 367 |
+
|
| 368 |
+
if st.session_state.get(edit_key, False):
|
| 369 |
+
with st.form(key=f"pop_form_{fn}", border=False):
|
| 370 |
+
new_val = st.number_input(
|
| 371 |
+
"Students", min_value=0, step=1,
|
| 372 |
+
value=int(current_pop) if current_pop is not None else 0,
|
| 373 |
+
key=input_key, label_visibility="collapsed",
|
| 374 |
+
)
|
| 375 |
+
c1, c2 = st.columns(2)
|
| 376 |
+
if c1.form_submit_button("✓"):
|
| 377 |
+
st.session_state.studentPopulations[fn] = int(new_val)
|
| 378 |
+
st.session_state[edit_key] = False
|
| 379 |
+
st.rerun()
|
| 380 |
+
if c2.form_submit_button("✕"):
|
| 381 |
+
st.session_state[edit_key] = False
|
| 382 |
+
st.rerun()
|
| 383 |
+
else:
|
| 384 |
+
row_cols[1].write(str(current_pop) if current_pop is not None else "—")
|
| 385 |
+
if row_cols[2].button("✎", key=f"pop_edit_btn_{fn}",
|
| 386 |
+
help="Edit student count"):
|
| 387 |
+
st.session_state[edit_key] = True
|
| 388 |
+
st.rerun()
|
| 389 |
+
|
| 390 |
+
# -----------------------------------------------------------------------
|
| 391 |
+
# Tab: Download
|
| 392 |
+
# -----------------------------------------------------------------------
|
| 393 |
+
|
| 394 |
with dataTab:
|
| 395 |
# Build raw-speaker -> role lookup against the RAW currDF (before renames
|
| 396 |
# are applied) so the map keys match the original SPEAKER_## labels.
|
|
|
|
| 407 |
displayDF = displayDF.rename(columns={"Resource": "Speaker"})
|
| 408 |
if "Start" in displayDF.columns:
|
| 409 |
displayDF = displayDF.sort_values("Start").reset_index(drop=True)
|
| 410 |
+
|
| 411 |
+
xml_bytes = build_xml_download(currFile)
|
| 412 |
st.download_button(
|
| 413 |
+
f"Download {currPlainName}.xml", xml_bytes,
|
| 414 |
+
f"sonogram-analysis-{currPlainName}.xml", "application/xml",
|
| 415 |
+
key="download-xml", on_click="ignore",
|
| 416 |
)
|
| 417 |
|
| 418 |
analyzed_count = sum(
|
| 419 |
1 for r in st.session_state.results.values() if len(r) == 2
|
| 420 |
)
|
| 421 |
+
zip_bytes = build_all_xml_zip() if analyzed_count > 1 else b""
|
| 422 |
st.download_button(
|
| 423 |
+
"Download all analyzed datas.xml in .zip archive", zip_bytes,
|
| 424 |
"sonogram-analysis-all.zip", "application/zip",
|
| 425 |
key="download-all-zip", on_click="ignore",
|
| 426 |
disabled=(analyzed_count <= 1),
|