manika07 commited on
Commit
3c1b261
·
1 Parent(s): 3443c45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -81,13 +81,16 @@ if uploaded_file is not None:
81
  df['category'] = df['Abstract'].apply(predict_category)
82
  st.dataframe(df)
83
 
84
- st.sidebar.header("Download Results")
85
- st.sidebar.text("Download the tagged results as a CSV file.")
86
-
87
- # Create a download button
88
- # Create a download button
89
- if st.sidebar.button("Download"):
90
- csv = df.to_csv(index=False)
91
- b64 = base64.b64encode(csv.encode()).decode()
92
- href = f'<a href="data:file/csv;base64,{b64}" download="results.csv">Download csv file</a>'
93
- st.markdown(href, unsafe_allow_html=True)
 
 
 
 
81
  df['category'] = df['Abstract'].apply(predict_category)
82
  st.dataframe(df)
83
 
84
+ # Create download tab
85
+ with st.sidebar:
86
+ st.header("Download")
87
+ if st.button("Download CSV file"):
88
+ download_csv(df)
89
+
90
+ def download_csv(df):
91
+ """Downloads a CSV file from the given DataFrame."""
92
+ b64_df = base64.b64encode(df.to_csv().encode()).decode()
93
+ headers = {"Content-Disposition": "attachment; filename=data.csv"}
94
+ st.download_file(b64_df, "data.csv", headers=headers)
95
+
96
+