Paula Leonova commited on
Commit
5db15b3
1 Parent(s): bf19bee

Add a button to download csv results

Browse files
Files changed (1) hide show
  1. app.py +18 -6
app.py CHANGED
@@ -109,20 +109,32 @@ if submit_button:
109
 
110
  if len(glabels) > 0:
111
  gdata = pd.DataFrame({'label': glabels})
112
- gdata['is_true_label'] = 1
113
 
114
  data2 = pd.merge(data2, gdata, how = 'left', on = ['label'])
115
  data2['is_true_label'].fillna(0, inplace = True)
116
 
117
  st.markdown("### Data Table")
118
  with st.spinner('Generating a table of results and a download link...'):
119
- coded_data = base64.b64encode(data2.to_csv(index = False). encode ()).decode()
120
- st.markdown(
121
- f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Click here to download the data</a>',
122
- unsafe_allow_html = True
123
- )
124
  st.dataframe(data2)
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  if len(glabels) > 0:
127
  st.markdown("### Evaluation Metrics")
128
  with st.spinner('Evaluating output against ground truth...'):
 
109
 
110
  if len(glabels) > 0:
111
  gdata = pd.DataFrame({'label': glabels})
112
+ gdata['is_true_label'] = int(1)
113
 
114
  data2 = pd.merge(data2, gdata, how = 'left', on = ['label'])
115
  data2['is_true_label'].fillna(0, inplace = True)
116
 
117
  st.markdown("### Data Table")
118
  with st.spinner('Generating a table of results and a download link...'):
 
 
 
 
 
119
  st.dataframe(data2)
120
 
121
+ @st.cache
122
+ def convert_df(df):
123
+ # IMPORTANT: Cache the conversion to prevent computation on every rerun
124
+ return df.to_csv().encode('utf-8')
125
+ csv = convert_df(data2)
126
+ st.download_button(
127
+ label="Download data as CSV",
128
+ data=csv,
129
+ file_name='text_labels.csv',
130
+ mime='text/csv',
131
+ )
132
+ # coded_data = base64.b64encode(data2.to_csv(index = False). encode ()).decode()
133
+ # st.markdown(
134
+ # f'<a href="data:file/csv;base64, {coded_data}" download = "data.csv">Click here to download the data</a>',
135
+ # unsafe_allow_html = True
136
+ # )
137
+
138
  if len(glabels) > 0:
139
  st.markdown("### Evaluation Metrics")
140
  with st.spinner('Evaluating output against ground truth...'):