Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Fix a bug with state change that can make index out of range
Browse files
utils.py
CHANGED
|
@@ -175,7 +175,7 @@ def build_df3(noVoice, oneVoice, multiVoice):
|
|
| 175 |
"""Voice category totals DataFrame."""
|
| 176 |
return pd.DataFrame({
|
| 177 |
"values": [su.sumTimes(noVoice), su.sumTimes(oneVoice), su.sumTimes(multiVoice)],
|
| 178 |
-
"names": ["No Voice", "
|
| 179 |
})
|
| 180 |
|
| 181 |
|
|
@@ -234,9 +234,9 @@ def build_df5(oneVoice, multiVoice, sumNoVoice, sumOneVoice, sumMultiVoice, curr
|
|
| 234 |
|
| 235 |
return pd.DataFrame({
|
| 236 |
"ids": ["NV", "OV", "MV"] + [f"OV_{i}" for i in range(n_ov)] + [f"MV_{i}" for i in range(n_mv)],
|
| 237 |
-
"labels": ["No Voice", "
|
| 238 |
"parents": ["", "", ""] + ["OV"] * n_ov + ["MV"] * n_mv,
|
| 239 |
-
"parentNames": ["Total", "Total", "Total"] + ["
|
| 240 |
"values": [sumNoVoice, sumOneVoice, sumMultiVoice] + timeList + multiTimeList,
|
| 241 |
"valueStrings": [
|
| 242 |
su.timeToString(sumNoVoice),
|
|
@@ -295,7 +295,7 @@ def build_fig_pie2(df4, speakerNames, speakerColors, catColors, get_display_name
|
|
| 295 |
df4["names"] = df4["names"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 296 |
fig = go.Figure()
|
| 297 |
fig.update_layout(
|
| 298 |
-
title_text="Percentage of Speakers
|
| 299 |
colorway=catColors + figColors,
|
| 300 |
**TRANSPARENT_BG,
|
| 301 |
)
|
|
@@ -451,20 +451,35 @@ def build_fig_bar(df2, speakerNames, catColors, speakerColors, get_display_name_
|
|
| 451 |
# Multi-file summary DataFrames
|
| 452 |
# ---------------------------------------------------------------------------
|
| 453 |
|
| 454 |
-
def build_multifile_category_df(validNames, results, summaries, categories, categorySelect
|
| 455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
df6_dict = {"files": validNames}
|
| 457 |
allCategories = copy.deepcopy(categories)
|
| 458 |
|
| 459 |
for fn in validNames:
|
| 460 |
currAnnotation, _ = results[fn]
|
| 461 |
-
# categorySelect is now a global token list [[token,...], ...]; extract raw IDs for fn
|
| 462 |
prefix = fn + ": "
|
| 463 |
per_file_selections = [
|
| 464 |
[t[len(prefix):] for t in tokens if t.startswith(prefix)]
|
| 465 |
for tokens in categorySelect
|
| 466 |
]
|
| 467 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 468 |
summaries[fn]["categories"] = (catSummary, extraCats)
|
| 469 |
for extra in extraCats:
|
| 470 |
df6_dict.setdefault(extra, [])
|
|
@@ -490,7 +505,7 @@ def build_multifile_category_df(validNames, results, summaries, categories, cate
|
|
| 490 |
|
| 491 |
def build_multifile_voice_df(validNames, summaries):
|
| 492 |
"""Build df7 (no/one/multi voice percentages per file) for the multi-file expander."""
|
| 493 |
-
voiceNames = ["No Voice", "
|
| 494 |
df7_dict = {"files": validNames}
|
| 495 |
for name in voiceNames:
|
| 496 |
df7_dict[name] = []
|
|
|
|
| 175 |
"""Voice category totals DataFrame."""
|
| 176 |
return pd.DataFrame({
|
| 177 |
"values": [su.sumTimes(noVoice), su.sumTimes(oneVoice), su.sumTimes(multiVoice)],
|
| 178 |
+
"names": ["No Voice", "Single Voice", "Multi Voice"],
|
| 179 |
})
|
| 180 |
|
| 181 |
|
|
|
|
| 234 |
|
| 235 |
return pd.DataFrame({
|
| 236 |
"ids": ["NV", "OV", "MV"] + [f"OV_{i}" for i in range(n_ov)] + [f"MV_{i}" for i in range(n_mv)],
|
| 237 |
+
"labels": ["No Voice", "Single Voice", "Multi Voice"] + speakerList + multiSpeakerList,
|
| 238 |
"parents": ["", "", ""] + ["OV"] * n_ov + ["MV"] * n_mv,
|
| 239 |
+
"parentNames": ["Total", "Total", "Total"] + ["Single Voice"] * n_ov + ["Multi Voice"] * n_mv,
|
| 240 |
"values": [sumNoVoice, sumOneVoice, sumMultiVoice] + timeList + multiTimeList,
|
| 241 |
"valueStrings": [
|
| 242 |
su.timeToString(sumNoVoice),
|
|
|
|
| 295 |
df4["names"] = df4["names"].apply(lambda s: get_display_name_fn(s, currFile))
|
| 296 |
fig = go.Figure()
|
| 297 |
fig.update_layout(
|
| 298 |
+
title_text="Percentage of Speakers per Role",
|
| 299 |
colorway=catColors + figColors,
|
| 300 |
**TRANSPARENT_BG,
|
| 301 |
)
|
|
|
|
| 451 |
# Multi-file summary DataFrames
|
| 452 |
# ---------------------------------------------------------------------------
|
| 453 |
|
| 454 |
+
def build_multifile_category_df(validNames, results, summaries, categories, categorySelect,
|
| 455 |
+
speakerRenames=None):
|
| 456 |
+
"""Build df6 (category breakdown per file) for the multi-file expander.
|
| 457 |
+
|
| 458 |
+
speakerRenames: {filename: {raw_sp: display_name}} — used to apply display
|
| 459 |
+
names to unassigned speaker columns (extraCats).
|
| 460 |
+
"""
|
| 461 |
+
speakerRenames = speakerRenames or {}
|
| 462 |
df6_dict = {"files": validNames}
|
| 463 |
allCategories = copy.deepcopy(categories)
|
| 464 |
|
| 465 |
for fn in validNames:
|
| 466 |
currAnnotation, _ = results[fn]
|
|
|
|
| 467 |
prefix = fn + ": "
|
| 468 |
per_file_selections = [
|
| 469 |
[t[len(prefix):] for t in tokens if t.startswith(prefix)]
|
| 470 |
for tokens in categorySelect
|
| 471 |
]
|
| 472 |
+
try:
|
| 473 |
+
catSummary, extraCats = su.calcCategories(currAnnotation, per_file_selections)
|
| 474 |
+
except (UnboundLocalError, Exception):
|
| 475 |
+
# calcCategories can fail when a role contains a speaker with no
|
| 476 |
+
# segments in this annotation (e.g. assigned in quick succession
|
| 477 |
+
# before the UI has settled). Skip this file for the summary.
|
| 478 |
+
summaries[fn]["categories"] = ([], [])
|
| 479 |
+
continue
|
| 480 |
+
# Apply display names to raw speaker IDs in extraCats
|
| 481 |
+
renames = speakerRenames.get(fn, {})
|
| 482 |
+
extraCats = [renames.get(sp, sp) for sp in extraCats]
|
| 483 |
summaries[fn]["categories"] = (catSummary, extraCats)
|
| 484 |
for extra in extraCats:
|
| 485 |
df6_dict.setdefault(extra, [])
|
|
|
|
| 505 |
|
| 506 |
def build_multifile_voice_df(validNames, summaries):
|
| 507 |
"""Build df7 (no/one/multi voice percentages per file) for the multi-file expander."""
|
| 508 |
+
voiceNames = ["No Voice", "Single Voice", "Multi Voice"]
|
| 509 |
df7_dict = {"files": validNames}
|
| 510 |
for name in voiceNames:
|
| 511 |
df7_dict[name] = []
|