czyoung commited on
Commit
ebf5b7d
·
verified ·
1 Parent(s): ff71e94

Add download buttons

Browse files
Files changed (1) hide show
  1. app.py +127 -11
app.py CHANGED
@@ -447,6 +447,7 @@ if currFile is None and len(st.session_state.results) > 0 and len(st.session_sta
447
  try:
448
  st.session_state.resetResult = False
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"]
@@ -503,7 +504,25 @@ try:
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"]
@@ -515,6 +534,24 @@ try:
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:
@@ -533,6 +570,24 @@ try:
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:
@@ -561,6 +616,24 @@ try:
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:
@@ -589,6 +662,24 @@ try:
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
@@ -619,7 +710,24 @@ try:
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:
@@ -643,6 +751,24 @@ try:
643
  'Percentage of Time: %{customdata[1]:.2f}%'
644
  ])
645
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
646
  st.plotly_chart(fig2_la, use_container_width=True)
647
 
648
  except ValueError:
@@ -729,13 +855,3 @@ def convert_df(df):
729
  return df.to_csv(index=False).encode('utf-8')
730
 
731
 
732
- if currDF is not None:
733
- csv = convert_df(currDF)
734
-
735
- st.download_button(
736
- "Press to Download analysis data",
737
- csv,
738
- "file.csv",
739
- "text/csv",
740
- key='download-csv'
741
- )
 
447
  try:
448
  st.session_state.resetResult = False
449
  currFileIndex = file_names.index(currFile)
450
+ currPlainName = currFile.split('.')[0]
451
  if len(st.session_state.results) > currFileIndex and len(st.session_state.summaries) > currFileIndex and len(st.session_state.results[currFileIndex]) > 0:
452
  st.header(f"Analysis of file {currFile}")
453
  graphNames = ["Data","Voice Categories","Speaker Percentage","Speakers with Categories","Treemap","Timeline","Time Spoken"]
 
504
  df4.name = "df4"
505
  st.session_state.summaries[currFileIndex]["df4"] = df4
506
 
507
+ # Save files for potential download
508
+
509
+ fig1.write_image("ascn_pie1.pdf")
510
+ fig2.write_image("ascn_pie2.pdf")
511
+ fig3_1.write_image("ascn_sunburst.pdf")
512
+ fig3.write_image("ascn_treemap.pdf")
513
+ fig_la.write_image("ascn_timeline.pdf")
514
+ fig2_la.write_image("ascn_bar.pdf")
515
+
516
  with dataTab:
517
+ csv = convert_df(currDF)
518
+
519
+ st.download_button(
520
+ "Press to Download analysis data",
521
+ csv,
522
+ "sonogram-analysis.csv",
523
+ "text/csv",
524
+ key='download-csv'
525
+ )
526
  st.dataframe(currDF)
527
  with pie1:
528
  df3 = st.session_state.summaries[currFileIndex]["df3"]
 
534
  paper_bgcolor='rgba(0, 0, 0, 0)',
535
  )
536
  fig1.add_trace(go.Pie(values=df3["values"],labels=df3["names"],sort=False))
537
+
538
+ col1, col2 = st.columns(2)
539
+ fig1.write_image("ascn_pie1.pdf")
540
+ fig1.write_image("ascn_pie1.svg")
541
+ with open('ascn_pie1.pdf') as f:
542
+ col1.dowload_botton(
543
+ "Save As PDF",
544
+ f,
545
+ 'sonogram-voice-category-'+currPlainName+'.pdf',
546
+ key='download-pdf1'
547
+ )
548
+ with open('ascn_pie1.svg') as f:
549
+ col2.dowload_botton(
550
+ "Save As SVG",
551
+ f,
552
+ 'sonogram-voice-category-'+currPlainName+'.svg',
553
+ key='download-svg1'
554
+ )
555
  st.plotly_chart(fig1, use_container_width=True)
556
 
557
  with pie2:
 
570
  paper_bgcolor='rgba(0, 0, 0, 0)',
571
  )
572
  fig2.add_trace(go.Pie(values=df4["values"],labels=df4["names"],sort=False))
573
+
574
+ col1, col2 = st.columns(2)
575
+ fig2.write_image("ascn_pie2.pdf")
576
+ fig2.write_image("ascn_pie2.svg")
577
+ with open('ascn_pie2.pdf') as f:
578
+ col1.dowload_botton(
579
+ "Save As PDF",
580
+ f,
581
+ 'sonogram-speaker-percent-'+currPlainName+'.pdf',
582
+ key='download-pdf2'
583
+ )
584
+ with open('ascn_pie2.svg') as f:
585
+ col2.dowload_botton(
586
+ "Save As SVG",
587
+ f,
588
+ 'sonogram-speaker-percent-'+currPlainName+'.svg',
589
+ key='download-svg2'
590
+ )
591
  st.plotly_chart(fig2, use_container_width=True)
592
 
593
  with sunburst1:
 
616
  plot_bgcolor='rgba(0, 0, 0, 0)',
617
  paper_bgcolor='rgba(0, 0, 0, 0)',
618
  )
619
+
620
+ col1, col2 = st.columns(2)
621
+ fig3_1.write_image("ascn_sunburst.pdf")
622
+ fig3_1.write_image("ascn_sunburst.svg")
623
+ with open('ascn_sunburst.pdf') as f:
624
+ col1.dowload_botton(
625
+ "Save As PDF",
626
+ f,
627
+ 'sonogram-speaker-categories-'+currPlainName+'.pdf',
628
+ key='download-pdf3'
629
+ )
630
+ with open('ascn_sunburst.svg') as f:
631
+ col2.dowload_botton(
632
+ "Save As SVG",
633
+ f,
634
+ 'sonogram-speaker-categories-'+currPlainName+'.svg',
635
+ key='download-svg3'
636
+ )
637
  st.plotly_chart(fig3_1, use_container_width=True)
638
 
639
  with treemap1:
 
662
  plot_bgcolor='rgba(0, 0, 0, 0)',
663
  paper_bgcolor='rgba(0, 0, 0, 0)',
664
  )
665
+
666
+ col1, col2 = st.columns(2)
667
+ fig3.write_image("ascn_treemap.pdf")
668
+ fig3.write_image("ascn_treemap.svg")
669
+ with open('ascn_treemap.pdf') as f:
670
+ col1.dowload_botton(
671
+ "Save As PDF",
672
+ f,
673
+ 'sonogram-treemap-'+currPlainName+'.pdf',
674
+ key='download-pdf4'
675
+ )
676
+ with open('ascn_treemap.svg') as f:
677
+ col2.dowload_botton(
678
+ "Save As SVG",
679
+ f,
680
+ 'sonogram-treemap-'+currPlainName+'.svg',
681
+ key='download-svg4'
682
+ )
683
  st.plotly_chart(fig3, use_container_width=True)
684
 
685
  # generate plotting window
 
710
  plot_bgcolor='rgba(0, 0, 0, 0)',
711
  paper_bgcolor='rgba(0, 0, 0, 0)',
712
  )
713
+
714
+ col1, col2 = st.columns(2)
715
+ fig_la.write_image("ascn_timeline.pdf")
716
+ fig_la.write_image("ascn_timeline.svg")
717
+ with open('ascn_timeline.pdf') as f:
718
+ col1.dowload_botton(
719
+ "Save As PDF",
720
+ f,
721
+ 'sonogram-timeline-'+currPlainName+'.pdf',
722
+ key='download-pdf5'
723
+ )
724
+ with open('ascn_timeline.svg') as f:
725
+ col2.dowload_botton(
726
+ "Save As SVG",
727
+ f,
728
+ 'sonogram-timeline-'+currPlainName+'.svg',
729
+ key='download-svg5'
730
+ )
731
  st.plotly_chart(fig_la, use_container_width=True)
732
 
733
  with bar1:
 
751
  'Percentage of Time: %{customdata[1]:.2f}%'
752
  ])
753
  )
754
+
755
+ col1, col2 = st.columns(2)
756
+ fig_la.write_image("ascn_bar.pdf")
757
+ fig_la.write_image("ascn_bar.svg")
758
+ with open('ascn_bar.pdf') as f:
759
+ col1.dowload_botton(
760
+ "Save As PDF",
761
+ f,
762
+ 'sonogram-speaker-time-'+currPlainName+'.pdf',
763
+ key='download-pdf6'
764
+ )
765
+ with open('ascn_bar.svg') as f:
766
+ col2.dowload_botton(
767
+ "Save As SVG",
768
+ f,
769
+ 'sonogram-speaker-time-'+currPlainName+'.svg',
770
+ key='download-svg6'
771
+ )
772
  st.plotly_chart(fig2_la, use_container_width=True)
773
 
774
  except ValueError:
 
855
  return df.to_csv(index=False).encode('utf-8')
856
 
857