Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Reformat tableDF
Browse filesMake it looks nicer
app.py
CHANGED
|
@@ -436,15 +436,36 @@ try:
|
|
| 436 |
key="download-csv", on_click="ignore",
|
| 437 |
)
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
file_clips = st.session_state.speakerClips.get(currFile, {})
|
| 440 |
has_clips = bool(file_clips)
|
| 441 |
has_waveform = currFile in st.session_state.speakerWaveforms
|
| 442 |
|
| 443 |
-
#
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
other_cols = [c for c in displayDF.columns if c != "Resource"]
|
| 447 |
-
has_extras = has_clips
|
| 448 |
|
| 449 |
if has_extras:
|
| 450 |
col_widths = [2] + [1] * len(other_cols) + [2, 1]
|
|
@@ -453,7 +474,7 @@ try:
|
|
| 453 |
|
| 454 |
# Header row
|
| 455 |
header_cols = st.columns(col_widths)
|
| 456 |
-
header_cols[0].markdown("**
|
| 457 |
for i, col_name in enumerate(other_cols):
|
| 458 |
header_cols[i + 1].markdown(f"**{col_name}**")
|
| 459 |
if has_extras:
|
|
@@ -466,18 +487,17 @@ try:
|
|
| 466 |
# so we only show it once (on the first row for that speaker).
|
| 467 |
rendered_clip_for: set = set()
|
| 468 |
|
| 469 |
-
for _, row in
|
| 470 |
-
row_cols
|
| 471 |
-
|
| 472 |
|
| 473 |
-
#
|
| 474 |
-
# (speakerClips is keyed by original SPEAKER_## labels)
|
| 475 |
raw_key = next(
|
| 476 |
-
(sp for sp in speakerNames if raw_to_display.get(sp, sp) ==
|
| 477 |
-
|
| 478 |
)
|
| 479 |
|
| 480 |
-
row_cols[0].write(
|
| 481 |
for i, col_name in enumerate(other_cols):
|
| 482 |
row_cols[i + 1].write(row[col_name])
|
| 483 |
|
|
|
|
| 436 |
key="download-csv", on_click="ignore",
|
| 437 |
)
|
| 438 |
|
| 439 |
+
# Build the display version of the table:
|
| 440 |
+
# - Rename "Resource" -> "Speaker"
|
| 441 |
+
# - Drop "Task" if present
|
| 442 |
+
# - Format Start / Finish as HH:MM:SS strings
|
| 443 |
+
def _fmt_seconds(val):
|
| 444 |
+
try:
|
| 445 |
+
secs = float(val)
|
| 446 |
+
except (TypeError, ValueError):
|
| 447 |
+
return str(val)
|
| 448 |
+
h = int(secs // 3600)
|
| 449 |
+
m = int(secs % 3600 // 60)
|
| 450 |
+
s = int(secs % 60)
|
| 451 |
+
return f"{h:02d}:{m:02d}:{s:02d}"
|
| 452 |
+
|
| 453 |
+
tableDF = displayDF.copy()
|
| 454 |
+
if "Task" in tableDF.columns:
|
| 455 |
+
tableDF = tableDF.drop(columns=["Task"])
|
| 456 |
+
if "Start" in tableDF.columns:
|
| 457 |
+
tableDF["Start"] = tableDF["Start"].apply(_fmt_seconds)
|
| 458 |
+
if "Finish" in tableDF.columns:
|
| 459 |
+
tableDF["Finish"] = tableDF["Finish"].apply(_fmt_seconds)
|
| 460 |
+
tableDF = tableDF.rename(columns={"Resource": "Speaker"})
|
| 461 |
+
|
| 462 |
file_clips = st.session_state.speakerClips.get(currFile, {})
|
| 463 |
has_clips = bool(file_clips)
|
| 464 |
has_waveform = currFile in st.session_state.speakerWaveforms
|
| 465 |
|
| 466 |
+
# Column layout: Speaker | remaining cols | [Clip | 🔀] if clips exist
|
| 467 |
+
other_cols = [c for c in tableDF.columns if c != "Speaker"]
|
| 468 |
+
has_extras = has_clips
|
|
|
|
|
|
|
| 469 |
|
| 470 |
if has_extras:
|
| 471 |
col_widths = [2] + [1] * len(other_cols) + [2, 1]
|
|
|
|
| 474 |
|
| 475 |
# Header row
|
| 476 |
header_cols = st.columns(col_widths)
|
| 477 |
+
header_cols[0].markdown("**Speaker**")
|
| 478 |
for i, col_name in enumerate(other_cols):
|
| 479 |
header_cols[i + 1].markdown(f"**{col_name}**")
|
| 480 |
if has_extras:
|
|
|
|
| 487 |
# so we only show it once (on the first row for that speaker).
|
| 488 |
rendered_clip_for: set = set()
|
| 489 |
|
| 490 |
+
for _, row in tableDF.iterrows():
|
| 491 |
+
row_cols = st.columns(col_widths)
|
| 492 |
+
display_sp = row["Speaker"]
|
| 493 |
|
| 494 |
+
# Map display name back to original SPEAKER_## for clip lookup
|
|
|
|
| 495 |
raw_key = next(
|
| 496 |
+
(sp for sp in speakerNames if raw_to_display.get(sp, sp) == display_sp),
|
| 497 |
+
display_sp,
|
| 498 |
)
|
| 499 |
|
| 500 |
+
row_cols[0].write(display_sp)
|
| 501 |
for i, col_name in enumerate(other_cols):
|
| 502 |
row_cols[i + 1].write(row[col_name])
|
| 503 |
|