czyoung commited on
Commit
2b3fa70
·
verified ·
1 Parent(s): f262643

Add in RTTM TXT viewer functionality

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -290,7 +290,7 @@ if 'results' not in st.session_state:
290
  if 'summaries' not in st.session_state:
291
  st.session_state.summaries = []
292
  if 'categories' not in st.session_state:
293
- st.session_state.categories = ["Lecturer","Audience"]
294
  st.session_state.categorySelect = []
295
  # Single Use
296
  if 'removeCategory' not in st.session_state:
@@ -314,7 +314,7 @@ if not isGPU:
314
 
315
  uploaded_file_paths = st.file_uploader("Upload an audio of classroom activity to analyze", accept_multiple_files=True)
316
 
317
- supported_file_types = ('.wav','.mp3','.mp4','.txt')
318
 
319
  valid_files = []
320
  file_paths = []
@@ -328,7 +328,7 @@ if uploaded_file_paths is not None:
328
  file_names = []
329
  # Reset valid_files?
330
  for uploaded_file in uploaded_file_paths:
331
- if not uploaded_file.name.endswith(supported_file_types):
332
  st.error('File must be of type: {}'.format(supported_file_types))
333
  uploaded_file = None
334
  else:
@@ -353,12 +353,7 @@ if uploaded_file_paths is not None:
353
  st.session_state.categorySelect.append(tempCategories)
354
  while (len(st.session_state.summaries) < len(valid_files)):
355
  st.session_state.summaries.append([])
356
- maybeRemove = '''
357
- # Clear replaced files
358
- for i in range(len(valid_files)):
359
- if len(st.session_state.results[i]) > 0 and st.session_state.results[i][0] != file_names[i]:
360
- st.session_state.results[i] = []
361
- st.session_state.summaries[i] = []'''
362
  st.session_state.file_names = file_names
363
 
364
  file_names = st.session_state.file_names
@@ -377,11 +372,25 @@ else:
377
  if len(st.session_state.results) > i and len(st.session_state.results[i]) > 0:
378
  continue
379
  # Text files use sample data
380
- if file_paths[i].endswith('.txt'):
381
  with st.spinner(text=f'Loading Demo File {i+1} of {totalFiles}'):
382
- time.sleep(1)
383
  # RTTM load as filler
384
- speakerList, annotations = su.loadAudioRTTM(sample_data[i])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  # Approximate total seconds
386
  totalSeconds = 0
387
  for segment in annotations.itersegments():
@@ -392,7 +401,6 @@ else:
392
  speakerNames = annotations.labels()
393
  st.session_state.unusedSpeakers[i] = speakerNames
394
  else:
395
- #st.info(file_paths[i])
396
  with st.spinner(text=f'Processing File {i+1} of {totalFiles}'):
397
  annotations, totalSeconds = processFile(file_paths[i])
398
  print(f"Finished processing {file_paths[i]}")
@@ -406,6 +414,7 @@ else:
406
  with st.spinner(text=f'Analyzing File {i+1} of {totalFiles}'):
407
  analyze(file_names[i])
408
  print(f"Finished analyzing {file_paths[i]}")
 
409
  st.success(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
410
 
411
  currFile = st.sidebar.selectbox('Current File', file_names,on_change=updateMultiSelect,key="select_currFile")
 
290
  if 'summaries' not in st.session_state:
291
  st.session_state.summaries = []
292
  if 'categories' not in st.session_state:
293
+ st.session_state.categories = ["Instructor","Audience"]
294
  st.session_state.categorySelect = []
295
  # Single Use
296
  if 'removeCategory' not in st.session_state:
 
314
 
315
  uploaded_file_paths = st.file_uploader("Upload an audio of classroom activity to analyze", accept_multiple_files=True)
316
 
317
+ supported_file_types = ('.wav','.mp3','.mp4','.txt','.rttm')
318
 
319
  valid_files = []
320
  file_paths = []
 
328
  file_names = []
329
  # Reset valid_files?
330
  for uploaded_file in uploaded_file_paths:
331
+ if not uploaded_file.name.lower().endswith(supported_file_types):
332
  st.error('File must be of type: {}'.format(supported_file_types))
333
  uploaded_file = None
334
  else:
 
353
  st.session_state.categorySelect.append(tempCategories)
354
  while (len(st.session_state.summaries) < len(valid_files)):
355
  st.session_state.summaries.append([])
356
+
 
 
 
 
 
357
  st.session_state.file_names = file_names
358
 
359
  file_names = st.session_state.file_names
 
372
  if len(st.session_state.results) > i and len(st.session_state.results[i]) > 0:
373
  continue
374
  # Text files use sample data
375
+ if file_paths[i].lower().endswith('.txt'):
376
  with st.spinner(text=f'Loading Demo File {i+1} of {totalFiles}'):
 
377
  # RTTM load as filler
378
+ speakerList, annotations = su.loadAudioTXT(file_paths[i])
379
+ print(annotations)
380
+ # Approximate total seconds
381
+ totalSeconds = 0
382
+ for segment in annotations.itersegments():
383
+ if segment.end > totalSeconds:
384
+ totalSeconds = segment.end
385
+ st.session_state.results[i] = (annotations, totalSeconds)
386
+ st.session_state.summaries[i] = {}
387
+ speakerNames = annotations.labels()
388
+ st.session_state.unusedSpeakers[i] = speakerNames
389
+ elif file_paths[i].lower().endswith('.rttm'):
390
+ with st.spinner(text=f'Loading File {i+1} of {totalFiles}'):
391
+ # RTTM load as filler
392
+ speakerList, annotations = su.loadAudioRTTM(file_paths[i])
393
+ print(annotations)
394
  # Approximate total seconds
395
  totalSeconds = 0
396
  for segment in annotations.itersegments():
 
401
  speakerNames = annotations.labels()
402
  st.session_state.unusedSpeakers[i] = speakerNames
403
  else:
 
404
  with st.spinner(text=f'Processing File {i+1} of {totalFiles}'):
405
  annotations, totalSeconds = processFile(file_paths[i])
406
  print(f"Finished processing {file_paths[i]}")
 
414
  with st.spinner(text=f'Analyzing File {i+1} of {totalFiles}'):
415
  analyze(file_names[i])
416
  print(f"Finished analyzing {file_paths[i]}")
417
+ print(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
418
  st.success(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
419
 
420
  currFile = st.sidebar.selectbox('Current File', file_names,on_change=updateMultiSelect,key="select_currFile")