faizhalas commited on
Commit
662b398
1 Parent(s): 721ec1f

download visualization for pyLDA

Browse files
Files changed (1) hide show
  1. pages/2 Topic Modeling.py +22 -0
pages/2 Topic Modeling.py CHANGED
@@ -32,6 +32,8 @@ import sys
32
  import spacy
33
  import en_core_web_sm
34
  import pipeline
 
 
35
 
36
 
37
  #===config===
@@ -180,6 +182,26 @@ if uploaded_file is not None:
180
  st.write('Coherence: ', (coherence_lda))
181
  st.components.v1.html(py_lda_vis_html, width=1700, height=800)
182
  st.markdown('Copyright (c) 2015, Ben Mabey. https://github.com/bmabey/pyLDAvis')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  except NameError:
184
  st.warning('🖱️ Please click Submit')
185
 
 
32
  import spacy
33
  import en_core_web_sm
34
  import pipeline
35
+ import plotly.graph_objects as go
36
+ from html2image import Html2Image
37
 
38
 
39
  #===config===
 
182
  st.write('Coherence: ', (coherence_lda))
183
  st.components.v1.html(py_lda_vis_html, width=1700, height=800)
184
  st.markdown('Copyright (c) 2015, Ben Mabey. https://github.com/bmabey/pyLDAvis')
185
+
186
+ @st.cache_data(ttl=3600, show_spinner=False)
187
+ def img_lda(vis):
188
+ pyLDAvis.save_html(vis, 'output.html')
189
+ hti = Html2Image()
190
+ hti.browser.flags = ['--default-background-color=ffffff', '--hide-scrollbars']
191
+ css = "body {background: white;}"
192
+ hti.screenshot(
193
+ other_file='output.html', css_str=css, size=(1500, 800),
194
+ save_as='ldavis_img.png'
195
+ )
196
+ with open("ldavis_img.png", "rb") as file:
197
+ btn = st.download_button(
198
+ label="Download image",
199
+ data=file,
200
+ file_name="ldavis_img.png",
201
+ mime="image/png"
202
+ )
203
+ img_lda(vis)
204
+
205
  except NameError:
206
  st.warning('🖱️ Please click Submit')
207