czyoung commited on
Commit
ac958ee
·
verified ·
1 Parent(s): e0cfb45

Major Visual Change

Browse files
Files changed (1) hide show
  1. app.py +89 -31
app.py CHANGED
@@ -26,6 +26,15 @@ import datetime as dt
26
  enableDenoise = False
27
  earlyCleanup = True
28
 
 
 
 
 
 
 
 
 
 
29
  def save_data(
30
  config_dict: Dict[str,str], audio_paths: List[str], userid: str,
31
  ) -> None:
@@ -138,18 +147,21 @@ def analyze(inFileName):
138
  currFileIndex = file_names.index(inFileName)
139
  print(f"Found at index {currFileIndex}")
140
  if len(st.session_state.results) > currFileIndex and len(st.session_state.summaries) > currFileIndex and len(st.session_state.results[currFileIndex]) > 0:
 
 
141
  # Handle
142
  currAnnotation, currTotalTime = st.session_state.results[currFileIndex]
143
  speakerNames = currAnnotation.labels()
144
-
145
  # Update other categories
146
  unusedSpeakers = st.session_state.unusedSpeakers[currFileIndex]
147
  categorySelections = st.session_state["categorySelect"][currFileIndex]
148
-
149
  noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(currAnnotation,currTotalTime)
150
  sumNoVoice = su.sumTimes(noVoice)
151
  sumOneVoice = su.sumTimes(oneVoice)
152
  sumMultiVoice = su.sumTimes(multiVoice)
 
153
 
154
  df3 = pd.DataFrame(
155
  {
@@ -161,6 +173,7 @@ def analyze(inFileName):
161
  )
162
  df3.name = "df3"
163
  st.session_state.summaries[currFileIndex]["df3"] = df3
 
164
 
165
  df4_dict = {}
166
  nameList = st.session_state.categories
@@ -181,13 +194,17 @@ def analyze(inFileName):
181
  else:
182
  extraNames.append(sp)
183
  extraValues.append(su.sumTimes(currAnnotation.subset([sp])))
 
 
184
  df4_dict = {
185
- "values": valueList+extraValues,
186
- "names": nameList+extraNames,
187
  }
188
  df4 = pd.DataFrame(data=df4_dict)
189
  df4.name = "df4"
190
  st.session_state.summaries[currFileIndex]["df4"] = df4
 
 
191
 
192
  speakerList,timeList = su.sumTimesPerSpeaker(oneVoice)
193
  multiSpeakerList, multiTimeList = su.sumMultiTimesPerSpeaker(multiVoice)
@@ -228,6 +245,7 @@ def analyze(inFileName):
228
  )
229
  df5.name = "df5"
230
  st.session_state.summaries[currFileIndex]["df5"] = df5
 
231
 
232
  speakers_dataFrame,speakers_times = su.annotationToDataFrame(currAnnotation)
233
  st.session_state.summaries[currFileIndex]["speakers_dataFrame"] = speakers_dataFrame
@@ -239,6 +257,7 @@ def analyze(inFileName):
239
  }
240
  df2 = pd.DataFrame(df2_dict)
241
  st.session_state.summaries[currFileIndex]["df2"] = df2
 
242
  except ValueError as e:
243
  print(f"Value Error: {e}")
244
  pass
@@ -420,9 +439,9 @@ else:
420
  print(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
421
  st.success(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
422
 
423
- summaryRadio = st.sidebar.empty()
424
  currFile = st.sidebar.selectbox('Current File', file_names,on_change=updateMultiSelect,key="select_currFile")
425
- viewSelection = st.sidebar.selectbox('View', viewChoices)
426
  if currFile is None and len(st.session_state.results) > 0 and len(st.session_state.results[0]) > 0:
427
  st.write("Select a file to view from the sidebar")
428
  try:
@@ -430,9 +449,16 @@ try:
430
  currFileIndex = file_names.index(currFile)
431
  if len(st.session_state.results) > currFileIndex and len(st.session_state.summaries) > currFileIndex and len(st.session_state.results[currFileIndex]) > 0:
432
  st.header(f"Analysis of file {currFile}")
 
 
433
  # Handle
434
  currAnnotation, currTotalTime = st.session_state.results[currFileIndex]
435
  speakerNames = currAnnotation.labels()
 
 
 
 
 
436
  # Update other categories
437
  unusedSpeakers = st.session_state.unusedSpeakers[currFileIndex]
438
  categorySelections = st.session_state["categorySelect"][currFileIndex]
@@ -450,6 +476,11 @@ try:
450
 
451
  newCategory = st.sidebar.text_input('Add category', key='categoryInput',on_change=addCategory)
452
 
 
 
 
 
 
453
  df4_dict = {}
454
  nameList = st.session_state.categories
455
  extraNames = []
@@ -472,25 +503,39 @@ try:
472
  df4.name = "df4"
473
  st.session_state.summaries[currFileIndex]["df4"] = df4
474
 
475
- viewSelection = [viewSelection]
476
-
477
- if viewChoices[0] in viewSelection:
478
  df3 = st.session_state.summaries[currFileIndex]["df3"]
479
  fig1 = go.Figure()
480
  fig1.update_layout(
481
  title_text="Percentage of each Voice Category",
 
 
 
482
  )
483
- fig1.add_trace(go.Pie(values=df3["values"],labels=df3["names"]))
484
  st.plotly_chart(fig1, use_container_width=True)
485
- if viewChoices[1] in viewSelection:
 
486
  df4 = st.session_state.summaries[currFileIndex]["df4"]
 
 
 
 
 
 
487
  fig2 = go.Figure()
488
  fig2.update_layout(
489
  title_text="Percentage of Speakers and Custom Categories",
 
 
 
490
  )
491
- fig2.add_trace(go.Pie(values=df4["values"],labels=df4["names"]))
492
  st.plotly_chart(fig2, use_container_width=True)
493
- if viewChoices[2] in viewSelection:
 
494
  df5 = st.session_state.summaries[currFileIndex]["df5"]
495
  fig3_1 = px.sunburst(df5,
496
  branchvalues = 'total',
@@ -501,6 +546,7 @@ try:
501
  custom_data=['labels','valueStrings','percentiles','parentNames','parentPercentiles'],
502
  color = 'labels',
503
  title="Percentage of each Voice Category with Speakers",
 
504
  )
505
  fig3_1.update_traces(
506
  hovertemplate="<br>".join([
@@ -511,8 +557,13 @@ try:
511
  'Percentage of Parent: %{customdata[4]:.2f}%'
512
  ])
513
  )
 
 
 
 
514
  st.plotly_chart(fig3_1, use_container_width=True)
515
- if viewChoices[3] in viewSelection:
 
516
  df5 = st.session_state.summaries[currFileIndex]["df5"]
517
  fig3 = px.treemap(df5,
518
  branchvalues = "total",
@@ -523,6 +574,7 @@ try:
523
  custom_data=['labels','valueStrings','percentiles','parentNames','parentPercentiles'],
524
  color='labels',
525
  title="Division of Speakers in each Voice Category",
 
526
  )
527
  fig3.update_traces(
528
  hovertemplate="<br>".join([
@@ -532,17 +584,19 @@ try:
532
  'Parent: %{customdata[3]}',
533
  'Percentage of Parent: %{customdata[4]:.2f}%'
534
  ])
 
 
 
 
535
  )
536
  st.plotly_chart(fig3, use_container_width=True)
537
- if viewChoices[4] in viewSelection:
538
- speakers_dataFrame = st.session_state.summaries[currFileIndex]["speakers_dataFrame"]
539
- currDF = speakers_dataFrame
540
- speakers_times = st.session_state.summaries[currFileIndex]["speakers_times"]
541
-
542
- # generate plotting window
543
-
544
-
545
- fig_la = px.timeline(speakers_dataFrame, x_start="Start", x_end="Finish", y="Resource", color="Resource",title="Timeline of Audio with Speakers")
546
  fig_la.update_yaxes(autorange="reversed")
547
 
548
  hMax = int(currTotalTime//3600)
@@ -561,20 +615,26 @@ try:
561
  ),
562
  xaxis_title="Time",
563
  yaxis_title="Speaker",
564
- legend_title=None
 
 
565
  )
566
 
567
  st.plotly_chart(fig_la, use_container_width=True)
568
- if viewChoices[5] in viewSelection:
 
569
  df2 = st.session_state.summaries[currFileIndex]["df2"]
570
  fig2_la = px.bar(df2, x="values", y="names", color="names", orientation='h',
571
- custom_data=["names","values"],title="Time Spoken by each Speaker")
 
572
  fig2_la.update_xaxes(ticksuffix="%")
573
  fig2_la.update_yaxes(autorange="reversed")
574
  fig2_la.update_layout(
575
  xaxis_title="Percentage Time Spoken",
576
  yaxis_title="Speaker",
577
- legend_title=None
 
 
578
 
579
  )
580
  fig2_la.update_traces(
@@ -587,11 +647,9 @@ try:
587
 
588
  except ValueError:
589
  pass
590
-
591
  if len(st.session_state.results) > 0:
592
- st.session_state.showSummary = st.radio('Display Multi-file Summary?',['Yes','No'])
593
-
594
- if st.session_state.showSummary == 'Yes':
595
  st.header("Multi-file Summary Data")
596
  with st.spinner(text='Processing summary results...'):
597
  fileNames = st.session_state.file_names
 
26
  enableDenoise = False
27
  earlyCleanup = True
28
 
29
+ # [None,Low,Medium,High,Debug]
30
+ # [0,1,2,3,4]
31
+ verbosity=4
32
+
33
+ def printV(message,verbosityLevel):
34
+ global verbosity
35
+ if verbosity>=verbosityLevel:
36
+ print(message)
37
+
38
  def save_data(
39
  config_dict: Dict[str,str], audio_paths: List[str], userid: str,
40
  ) -> None:
 
147
  currFileIndex = file_names.index(inFileName)
148
  print(f"Found at index {currFileIndex}")
149
  if len(st.session_state.results) > currFileIndex and len(st.session_state.summaries) > currFileIndex and len(st.session_state.results[currFileIndex]) > 0:
150
+
151
+ printV(f'In if',4)
152
  # Handle
153
  currAnnotation, currTotalTime = st.session_state.results[currFileIndex]
154
  speakerNames = currAnnotation.labels()
155
+ printV(f'Loaded results',4)
156
  # Update other categories
157
  unusedSpeakers = st.session_state.unusedSpeakers[currFileIndex]
158
  categorySelections = st.session_state["categorySelect"][currFileIndex]
159
+ printV(f'Loaded speaker selections',4)
160
  noVoice, oneVoice, multiVoice = su.calcSpeakingTypes(currAnnotation,currTotalTime)
161
  sumNoVoice = su.sumTimes(noVoice)
162
  sumOneVoice = su.sumTimes(oneVoice)
163
  sumMultiVoice = su.sumTimes(multiVoice)
164
+ printV(f'Calculated speaking types',4)
165
 
166
  df3 = pd.DataFrame(
167
  {
 
173
  )
174
  df3.name = "df3"
175
  st.session_state.summaries[currFileIndex]["df3"] = df3
176
+ printV(f'Set df3',4)
177
 
178
  df4_dict = {}
179
  nameList = st.session_state.categories
 
194
  else:
195
  extraNames.append(sp)
196
  extraValues.append(su.sumTimes(currAnnotation.subset([sp])))
197
+ extraPairsSorted = sorted(zip(extraNames, extraValues), key=lambda pair: pair[0])
198
+ extraNames, extraValues = zip(*extraPairsSorted)
199
  df4_dict = {
200
+ "values": valueList+list(extraValues),
201
+ "names": nameList+list(extraNames),
202
  }
203
  df4 = pd.DataFrame(data=df4_dict)
204
  df4.name = "df4"
205
  st.session_state.summaries[currFileIndex]["df4"] = df4
206
+
207
+ printV(f'Set df4',4)
208
 
209
  speakerList,timeList = su.sumTimesPerSpeaker(oneVoice)
210
  multiSpeakerList, multiTimeList = su.sumMultiTimesPerSpeaker(multiVoice)
 
245
  )
246
  df5.name = "df5"
247
  st.session_state.summaries[currFileIndex]["df5"] = df5
248
+ printV(f'Set df5',4)
249
 
250
  speakers_dataFrame,speakers_times = su.annotationToDataFrame(currAnnotation)
251
  st.session_state.summaries[currFileIndex]["speakers_dataFrame"] = speakers_dataFrame
 
257
  }
258
  df2 = pd.DataFrame(df2_dict)
259
  st.session_state.summaries[currFileIndex]["df2"] = df2
260
+ printV(f'Set df2',4)
261
  except ValueError as e:
262
  print(f"Value Error: {e}")
263
  pass
 
439
  print(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
440
  st.success(f"Took {time.time() - start_time} seconds to analyze {totalFiles} files!")
441
 
442
+
443
  currFile = st.sidebar.selectbox('Current File', file_names,on_change=updateMultiSelect,key="select_currFile")
444
+
445
  if currFile is None and len(st.session_state.results) > 0 and len(st.session_state.results[0]) > 0:
446
  st.write("Select a file to view from the sidebar")
447
  try:
 
449
  currFileIndex = file_names.index(currFile)
450
  if len(st.session_state.results) > currFileIndex and len(st.session_state.summaries) > currFileIndex and len(st.session_state.results[currFileIndex]) > 0:
451
  st.header(f"Analysis of file {currFile}")
452
+ graphNames = ["Data","Voice Categories","Speaker Percentage","Speakers with Categories","Treemap","Timeline","Time Spoken"]
453
+ dataTab, pie1, pie2, sunburst1, treemap1, timeline, bar1 = st.tabs(graphNames)
454
  # Handle
455
  currAnnotation, currTotalTime = st.session_state.results[currFileIndex]
456
  speakerNames = currAnnotation.labels()
457
+
458
+ speakers_dataFrame = st.session_state.summaries[currFileIndex]["speakers_dataFrame"]
459
+ currDF = speakers_dataFrame
460
+ speakers_times = st.session_state.summaries[currFileIndex]["speakers_times"]
461
+
462
  # Update other categories
463
  unusedSpeakers = st.session_state.unusedSpeakers[currFileIndex]
464
  categorySelections = st.session_state["categorySelect"][currFileIndex]
 
476
 
477
  newCategory = st.sidebar.text_input('Add category', key='categoryInput',on_change=addCategory)
478
 
479
+ catTypeColors = su.colorsCSS(3)
480
+ allColors = su.colorsCSS(len(speakerNames)+len(st.session_state.categories))
481
+ speakerColors = allColors[:len(speakerNames)]
482
+ catColors = allColors[len(speakerNames):]
483
+
484
  df4_dict = {}
485
  nameList = st.session_state.categories
486
  extraNames = []
 
503
  df4.name = "df4"
504
  st.session_state.summaries[currFileIndex]["df4"] = df4
505
 
506
+ with dataTab:
507
+ st.dataframe(currDF)
508
+ with pie1:
509
  df3 = st.session_state.summaries[currFileIndex]["df3"]
510
  fig1 = go.Figure()
511
  fig1.update_layout(
512
  title_text="Percentage of each Voice Category",
513
+ colorway=catTypeColors,
514
+ plot_bgcolor='rgba(0, 0, 0, 0)',
515
+ paper_bgcolor='rgba(0, 0, 0, 0)',
516
  )
517
+ fig1.add_trace(go.Pie(values=df3["values"],labels=df3["names"],sort=False))
518
  st.plotly_chart(fig1, use_container_width=True)
519
+
520
+ with pie2:
521
  df4 = st.session_state.summaries[currFileIndex]["df4"]
522
+
523
+ # Some speakers may be missing, so fix colors
524
+ figColors = []
525
+ for n in df4["names"]:
526
+ if n in speakerNames:
527
+ figColors.append(speakerColors[speakerNames.index(n)])
528
  fig2 = go.Figure()
529
  fig2.update_layout(
530
  title_text="Percentage of Speakers and Custom Categories",
531
+ colorway=catColors+figColors,
532
+ plot_bgcolor='rgba(0, 0, 0, 0)',
533
+ paper_bgcolor='rgba(0, 0, 0, 0)',
534
  )
535
+ fig2.add_trace(go.Pie(values=df4["values"],labels=df4["names"],sort=False))
536
  st.plotly_chart(fig2, use_container_width=True)
537
+
538
+ with sunburst1:
539
  df5 = st.session_state.summaries[currFileIndex]["df5"]
540
  fig3_1 = px.sunburst(df5,
541
  branchvalues = 'total',
 
546
  custom_data=['labels','valueStrings','percentiles','parentNames','parentPercentiles'],
547
  color = 'labels',
548
  title="Percentage of each Voice Category with Speakers",
549
+ color_discrete_sequence=catTypeColors+speakerColors,
550
  )
551
  fig3_1.update_traces(
552
  hovertemplate="<br>".join([
 
557
  'Percentage of Parent: %{customdata[4]:.2f}%'
558
  ])
559
  )
560
+ fig3_1.update_layout(
561
+ plot_bgcolor='rgba(0, 0, 0, 0)',
562
+ paper_bgcolor='rgba(0, 0, 0, 0)',
563
+ )
564
  st.plotly_chart(fig3_1, use_container_width=True)
565
+
566
+ with treemap1:
567
  df5 = st.session_state.summaries[currFileIndex]["df5"]
568
  fig3 = px.treemap(df5,
569
  branchvalues = "total",
 
574
  custom_data=['labels','valueStrings','percentiles','parentNames','parentPercentiles'],
575
  color='labels',
576
  title="Division of Speakers in each Voice Category",
577
+ color_discrete_sequence=catTypeColors+speakerColors,
578
  )
579
  fig3.update_traces(
580
  hovertemplate="<br>".join([
 
584
  'Parent: %{customdata[3]}',
585
  'Percentage of Parent: %{customdata[4]:.2f}%'
586
  ])
587
+ ))
588
+ fig3.update_layout(
589
+ plot_bgcolor='rgba(0, 0, 0, 0)',
590
+ paper_bgcolor='rgba(0, 0, 0, 0)',
591
  )
592
  st.plotly_chart(fig3, use_container_width=True)
593
+
594
+ # generate plotting window
595
+
596
+
597
+ with timeline:
598
+ fig_la = px.timeline(speakers_dataFrame, x_start="Start", x_end="Finish", y="Resource", color="Resource",title="Timeline of Audio with Speakers",
599
+ color_discrete_sequence=speakerColors)
 
 
600
  fig_la.update_yaxes(autorange="reversed")
601
 
602
  hMax = int(currTotalTime//3600)
 
615
  ),
616
  xaxis_title="Time",
617
  yaxis_title="Speaker",
618
+ legend_title=None,
619
+ plot_bgcolor='rgba(0, 0, 0, 0)',
620
+ paper_bgcolor='rgba(0, 0, 0, 0)',
621
  )
622
 
623
  st.plotly_chart(fig_la, use_container_width=True)
624
+
625
+ with bar1:
626
  df2 = st.session_state.summaries[currFileIndex]["df2"]
627
  fig2_la = px.bar(df2, x="values", y="names", color="names", orientation='h',
628
+ custom_data=["names","values"],title="Time Spoken by each Speaker",
629
+ color_discrete_sequence=catColors+speakerColors)
630
  fig2_la.update_xaxes(ticksuffix="%")
631
  fig2_la.update_yaxes(autorange="reversed")
632
  fig2_la.update_layout(
633
  xaxis_title="Percentage Time Spoken",
634
  yaxis_title="Speaker",
635
+ legend_title=None,
636
+ plot_bgcolor='rgba(0, 0, 0, 0)',
637
+ paper_bgcolor='rgba(0, 0, 0, 0)',
638
 
639
  )
640
  fig2_la.update_traces(
 
647
 
648
  except ValueError:
649
  pass
650
+
651
  if len(st.session_state.results) > 0:
652
+ with st.expander("Multi-file Summary Data"):
 
 
653
  st.header("Multi-file Summary Data")
654
  with st.spinner(text='Processing summary results...'):
655
  fileNames = st.session_state.file_names