darthPanda commited on
Commit
c0d7f9d
1 Parent(s): e62e803

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -18,6 +18,8 @@ import plotly.graph_objs as go
18
  import pandas as pd
19
  import plotly.offline as pyo
20
 
 
 
21
  #@st.cache_resource()
22
  @st.cache()
23
  def get_nl():
@@ -278,17 +280,29 @@ if len(uploaded_file)>0:
278
 
279
  fig.update_layout(height=700, showlegend=False, title={'text': f"<b>{wrapped_title} - Sentiment Analysis Report</b>", 'x': 0.5, 'xanchor': 'center','font': {'size': 32}})
280
 
281
- pyo.plot(fig, filename='report.html')
 
 
 
 
 
 
 
 
 
 
 
 
282
 
283
- import base64
284
 
285
- # Convert the figure to HTML format
286
- fig_html = pio.to_html(fig, full_html=False)
287
- b64 = base64.b64encode(fig_html.encode()).decode()
288
 
289
- # Generate a download link
290
- filename = "figure.html"
291
- href = f'<a href="data:file/html;base64,{b64}" download="{filename}">Download Report</a>'
292
 
293
- # Display the link
294
- st.markdown(href, unsafe_allow_html=True)
 
18
  import pandas as pd
19
  import plotly.offline as pyo
20
 
21
+ from io import StringIO
22
+
23
  #@st.cache_resource()
24
  @st.cache()
25
  def get_nl():
 
280
 
281
  fig.update_layout(height=700, showlegend=False, title={'text': f"<b>{wrapped_title} - Sentiment Analysis Report</b>", 'x': 0.5, 'xanchor': 'center','font': {'size': 32}})
282
 
283
+ #pyo.plot(fig, filename='report.html')
284
+
285
+ buffer = io.StringIO()
286
+ fig.write_html(buffer, include_plotlyjs='cdn')
287
+ html_bytes = buffer.getvalue().encode()
288
+
289
+ st.download_button(
290
+ label='Download HTML',
291
+ data=html_bytes,
292
+ file_name='report.html',
293
+ mime='text/html'
294
+ )
295
+
296
 
297
+ # import base64
298
 
299
+ # # Convert the figure to HTML format
300
+ # fig_html = pio.to_html(fig, full_html=False)
301
+ # b64 = base64.b64encode(fig_html.encode()).decode()
302
 
303
+ # # Generate a download link
304
+ # filename = "figure.html"
305
+ # href = f'<a href="data:file/html;base64,{b64}" download="{filename}">Download Report</a>'
306
 
307
+ # # Display the link
308
+ # st.markdown(href, unsafe_allow_html=True)