Update app.py
Browse files
app.py
CHANGED
@@ -102,9 +102,11 @@ def conv_txt(extype):
|
|
102 |
# else:
|
103 |
# st.sidebar.text("Please upload a file first to enable the download button.")
|
104 |
|
|
|
105 |
uploaded_file = st.file_uploader("Choose a file", type=['csv'])
|
106 |
st.sidebar.header("Download Results")
|
107 |
st.sidebar.text("Download the tagged results as a CSV file.")
|
|
|
108 |
if uploaded_file is not None:
|
109 |
df = pd.read_csv(uploaded_file, encoding='latin-1')
|
110 |
st.dataframe(df)
|
@@ -113,11 +115,14 @@ if uploaded_file is not None:
|
|
113 |
df['category'] = df['Abstract'].apply(lambda x: predict_category(x)[0])
|
114 |
st.dataframe(df)
|
115 |
|
116 |
-
|
117 |
-
|
|
|
|
|
118 |
st.sidebar.download_button(
|
119 |
-
label="Download",
|
120 |
-
data=b64,
|
121 |
file_name="results.csv",
|
122 |
-
mime="text/csv"
|
|
|
123 |
)
|
|
|
102 |
# else:
|
103 |
# st.sidebar.text("Please upload a file first to enable the download button.")
|
104 |
|
105 |
+
|
106 |
uploaded_file = st.file_uploader("Choose a file", type=['csv'])
|
107 |
st.sidebar.header("Download Results")
|
108 |
st.sidebar.text("Download the tagged results as a CSV file.")
|
109 |
+
|
110 |
if uploaded_file is not None:
|
111 |
df = pd.read_csv(uploaded_file, encoding='latin-1')
|
112 |
st.dataframe(df)
|
|
|
115 |
df['category'] = df['Abstract'].apply(lambda x: predict_category(x)[0])
|
116 |
st.dataframe(df)
|
117 |
|
118 |
+
# Convert DataFrame to CSV and encode it properly
|
119 |
+
csv = df.to_csv(index=False).encode('utf-8')
|
120 |
+
b64 = base64.b64encode(csv).decode() # Decode the Base64 encoded bytes
|
121 |
+
|
122 |
st.sidebar.download_button(
|
123 |
+
label="Download CSV",
|
124 |
+
data=base64.b64decode(b64), # Decode Base64 to bytes
|
125 |
file_name="results.csv",
|
126 |
+
mime="text/csv",
|
127 |
+
key='download-csv'
|
128 |
)
|