duongthienz commited on
Commit
7f1a5da
·
verified ·
1 Parent(s): 61b4d5b

Add Single File Demo (Sample)

Browse files
Files changed (1) hide show
  1. app.py +31 -10
app.py CHANGED
@@ -28,7 +28,7 @@ from state import (
28
  init_session_state,
29
  get_display_name, apply_speaker_renames_to_df, convert_df,
30
  updateMultiSelect, store_speaker_clips, register_file, analyze,
31
- load_demo_single, load_demo_multi, run_analysis_loop,
32
  build_all_csv_zip,
33
  )
34
 
@@ -50,6 +50,7 @@ PARQUET_DATASET_DIR = Path("parquet_dataset")
50
  PARQUET_DATASET_DIR.mkdir(parents=True, exist_ok=True)
51
 
52
  DEMO_PATH = "sample.rttm"
 
53
  MULTI_DEMO_PATHS = [
54
  "audioSamples/media-afc-cal-afc1986022_sr01a05.rttm",
55
  "audioSamples/media-afc-cal-afc1986022_sr34a01.rttm",
@@ -124,7 +125,8 @@ if not isGPU:
124
 
125
  st.write(
126
  'If you would like to see a sample result or multiple sample results generated from '
127
- 'real classroom audio, select "Single File Demo" or "Multiple Files Demo" on the left sidebar.'
 
128
  )
129
  st.markdown(
130
  "<p style='margin-bottom:4px;'>Keep in mind that this is a very early draft of the tool. "
@@ -177,7 +179,11 @@ file_paths_dict = st.session_state.file_paths
177
 
178
  isDemo = False
179
 
180
- if st.sidebar.button("Single File Demo"):
 
 
 
 
181
  load_demo_single(DEMO_PATH)
182
  isDemo = True
183
 
@@ -185,6 +191,12 @@ if st.sidebar.button("Multiple Files Demo"):
185
  load_demo_multi(MULTI_DEMO_PATHS)
186
  isDemo = True
187
 
 
 
 
 
 
 
188
  # ---------------------------------------------------------------------------
189
  # Analyze All / Reset buttons
190
  # ---------------------------------------------------------------------------
@@ -240,7 +252,7 @@ try:
240
  raise ValueError("No file selected")
241
 
242
  st.session_state.resetResult = False
243
- currPlainName = currFile.split(".")[0]
244
 
245
  if not (
246
  currFile in st.session_state.results
@@ -300,23 +312,32 @@ try:
300
  for sp in st.session_state.results[fn][0].labels()
301
  ]
302
  # Map display label -> raw token so ui.py can translate back after selection.
303
- # Build carefully to avoid key collisions: if two speakers in the same file
304
- # share a display name, append the raw ID to disambiguate both entries.
 
 
 
 
 
 
 
 
305
  token_display_map = {}
306
  for fn in st.session_state.file_names:
307
  if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
308
  continue
 
309
  # First pass: collect display labels per file to detect duplicates
310
- sp_labels = {sp: f"{fn}: {get_display_name(sp, fn)}"
311
  for sp in st.session_state.results[fn][0].labels()}
312
  label_counts = {}
313
  for disp in sp_labels.values():
314
  label_counts[disp] = label_counts.get(disp, 0) + 1
315
  # Second pass: build map, disambiguating where needed
316
  for sp, disp in sp_labels.items():
317
- raw = f"{fn}: {sp}"
318
  if label_counts[disp] > 1:
319
- token_display_map[f"{fn}: {get_display_name(sp, fn)} ({sp})"] = raw
320
  else:
321
  token_display_map[disp] = raw
322
  display_speaker_tokens = list(token_display_map.keys())
@@ -439,7 +460,7 @@ with st.expander("(Potentially) FAQ"):
439
  st.write("**3. I still don't have a file to select in the dropdown! Why?**")
440
  st.write("Your file may be too large. We currently support approximately 1.5 hours of audio.")
441
  st.write("**4. I want to view my previously analyzed data. How?**")
442
- st.write("Download a CSV copy from the Data tab and re-upload it later.")
443
  st.write("**5. The app is extremely slow. What is wrong?**")
444
  st.write("We are securing funding for permanent GPU access. Until then, CPU analysis may take a very long time.")
445
 
 
28
  init_session_state,
29
  get_display_name, apply_speaker_renames_to_df, convert_df,
30
  updateMultiSelect, store_speaker_clips, register_file, analyze,
31
+ load_demo_single, load_demo_single_sample, load_demo_multi, run_analysis_loop,
32
  build_all_csv_zip,
33
  )
34
 
 
50
  PARQUET_DATASET_DIR.mkdir(parents=True, exist_ok=True)
51
 
52
  DEMO_PATH = "sample.rttm"
53
+ DEMO_SAMPLE_PATH = "sample_short.rttm"
54
  MULTI_DEMO_PATHS = [
55
  "audioSamples/media-afc-cal-afc1986022_sr01a05.rttm",
56
  "audioSamples/media-afc-cal-afc1986022_sr34a01.rttm",
 
125
 
126
  st.write(
127
  'If you would like to see a sample result or multiple sample results generated from '
128
+ 'real classroom audio, select "Single File Demo (Sample)", "Single File Demo (Full)", '
129
+ 'or "Multiple Files Demo" on the left sidebar.'
130
  )
131
  st.markdown(
132
  "<p style='margin-bottom:4px;'>Keep in mind that this is a very early draft of the tool. "
 
179
 
180
  isDemo = False
181
 
182
+ if st.sidebar.button("Single File Demo (Sample)"):
183
+ load_demo_single_sample(DEMO_SAMPLE_PATH)
184
+ isDemo = True
185
+
186
+ if st.sidebar.button("Single File Demo (Full)"):
187
  load_demo_single(DEMO_PATH)
188
  isDemo = True
189
 
 
191
  load_demo_multi(MULTI_DEMO_PATHS)
192
  isDemo = True
193
 
194
+ st.sidebar.caption(
195
+ "Single File Demo (Sample) analyzes a 10-minute sample, while "
196
+ "Single File Demo (Full) analyzes the entire file. "
197
+ "The latter can take a while to finish."
198
+ )
199
+
200
  # ---------------------------------------------------------------------------
201
  # Analyze All / Reset buttons
202
  # ---------------------------------------------------------------------------
 
252
  raise ValueError("No file selected")
253
 
254
  st.session_state.resetResult = False
255
+ currPlainName = currFile.rsplit(".", 1)[0]
256
 
257
  if not (
258
  currFile in st.session_state.results
 
312
  for sp in st.session_state.results[fn][0].labels()
313
  ]
314
  # Map display label -> raw token so ui.py can translate back after selection.
315
+ # Display label uses a truncated filename (first 5 chars + "...") to keep
316
+ # the dropdown readable when filenames are long. The raw token always uses
317
+ # the full filename so the data model is never affected by this truncation.
318
+ # If two speakers in the same file share a display name, the raw speaker ID
319
+ # is appended to disambiguate both entries.
320
+ def _short_fn(fname):
321
+ """Return first 5 chars of filename stem + '...' if longer than 5."""
322
+ stem = fname.rsplit(".", 1)[0] # strip extension
323
+ return (stem[:5] + "...") if len(stem) > 5 else stem
324
+
325
  token_display_map = {}
326
  for fn in st.session_state.file_names:
327
  if not (fn in st.session_state.results and len(st.session_state.results[fn]) == 2):
328
  continue
329
+ short = _short_fn(fn)
330
  # First pass: collect display labels per file to detect duplicates
331
+ sp_labels = {sp: f"{short}: {get_display_name(sp, fn)}"
332
  for sp in st.session_state.results[fn][0].labels()}
333
  label_counts = {}
334
  for disp in sp_labels.values():
335
  label_counts[disp] = label_counts.get(disp, 0) + 1
336
  # Second pass: build map, disambiguating where needed
337
  for sp, disp in sp_labels.items():
338
+ raw = f"{fn}: {sp}" # raw token always uses full filename
339
  if label_counts[disp] > 1:
340
+ token_display_map[f"{short}: {get_display_name(sp, fn)} ({sp})"] = raw
341
  else:
342
  token_display_map[disp] = raw
343
  display_speaker_tokens = list(token_display_map.keys())
 
460
  st.write("**3. I still don't have a file to select in the dropdown! Why?**")
461
  st.write("Your file may be too large. We currently support approximately 1.5 hours of audio.")
462
  st.write("**4. I want to view my previously analyzed data. How?**")
463
+ st.write("Download a CSV copy from the Download tab and re-upload it later.")
464
  st.write("**5. The app is extremely slow. What is wrong?**")
465
  st.write("We are securing funding for permanent GPU access. Until then, CPU analysis may take a very long time.")
466