manika07 commited on
Commit
bf85a00
·
1 Parent(s): 00de706

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -73,20 +73,21 @@ def conv_txt(extype):
73
 
74
  #===Read data===
75
  uploaded_file = st.file_uploader("Choose a file", type=['csv'])
76
-
 
77
  if uploaded_file is not None:
78
  df = pd.read_csv(uploaded_file, encoding='latin-1')
79
  st.dataframe(df)
 
80
  # Tag the "Abstract" column with the corresponding categories
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
- if st.sidebar.button("Download"):
89
- csv = df.to_csv(index=False)
90
- b64 = base64.b64encode(csv.encode()).decode()
91
- href = f'<a href="data:file/csv;base64,{b64}" download="results.csv">Download csv file</a>'
92
- st.markdown(href, unsafe_allow_html=True)
 
73
 
74
  #===Read data===
75
  uploaded_file = st.file_uploader("Choose a file", type=['csv'])
76
+ st.sidebar.header("Download Results")
77
+ st.sidebar.text("Download the tagged results as a CSV file.")
78
  if uploaded_file is not None:
79
  df = pd.read_csv(uploaded_file, encoding='latin-1')
80
  st.dataframe(df)
81
+
82
  # Tag the "Abstract" column with the corresponding categories
83
+ df['category'] = df['Abstract'].apply(lambda x: predict_category(x)[0])
84
  st.dataframe(df)
85
+
86
+ csv = df.to_csv(index=False, encoding='utf-8-sig') # Using utf-8-sig to handle possible BOM issues
87
+ b64 = base64.b64encode(csv.encode('utf-8-sig'))
88
+ st.sidebar.download_button(
89
+ label="Download",
90
+ data=b64,
91
+ file_name="results.csv",
92
+ mime="text/csv"
93
+ )