Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -164,24 +164,31 @@ if st.session_state.authenticated:
|
|
164 |
df = pd.DataFrame(emails)
|
165 |
|
166 |
st.write("### Download Options:")
|
167 |
-
col1, col2, col3, col4 = st.columns(4)
|
168 |
|
169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
csv = df.to_csv(index=False).encode('utf-8')
|
171 |
-
st.download_button("Download
|
172 |
|
173 |
-
|
174 |
excel_buffer = io.BytesIO()
|
175 |
with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
|
176 |
df.to_excel(writer, index=False)
|
177 |
excel_buffer.seek(0)
|
178 |
-
st.download_button("Download
|
179 |
|
180 |
-
|
181 |
pdf_buffer = export_to_pdf(df)
|
182 |
-
st.download_button("Download
|
183 |
|
184 |
-
|
185 |
conn = sqlite3.connect(':memory:')
|
186 |
df.to_sql('emails', conn, index=False, if_exists='replace')
|
187 |
sql_buffer = io.BytesIO()
|
@@ -189,6 +196,6 @@ if st.session_state.authenticated:
|
|
189 |
for line in conn.iterdump():
|
190 |
f.write(f'{line}\n'.encode('utf-8'))
|
191 |
sql_buffer.seek(0)
|
192 |
-
st.download_button("Download
|
193 |
else:
|
194 |
st.warning("You are not authenticated yet.")
|
|
|
164 |
df = pd.DataFrame(emails)
|
165 |
|
166 |
st.write("### Download Options:")
|
|
|
167 |
|
168 |
+
# Create a dropdown for file format selection
|
169 |
+
file_format = st.selectbox(
|
170 |
+
"Select Download Format",
|
171 |
+
["CSV", "Excel", "PDF", "SQL"],
|
172 |
+
index=0 # CSV is default
|
173 |
+
)
|
174 |
+
|
175 |
+
# Download button logic based on the selected format
|
176 |
+
if file_format == "CSV":
|
177 |
csv = df.to_csv(index=False).encode('utf-8')
|
178 |
+
st.download_button("Download", csv, f"{label}_emails.csv", "text/csv")
|
179 |
|
180 |
+
elif file_format == "Excel":
|
181 |
excel_buffer = io.BytesIO()
|
182 |
with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
|
183 |
df.to_excel(writer, index=False)
|
184 |
excel_buffer.seek(0)
|
185 |
+
st.download_button("Download", excel_buffer, f"{label}_emails.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
|
186 |
|
187 |
+
elif file_format == "PDF":
|
188 |
pdf_buffer = export_to_pdf(df)
|
189 |
+
st.download_button("Download", pdf_buffer, f"{label}_emails.pdf", "application/pdf")
|
190 |
|
191 |
+
elif file_format == "SQL":
|
192 |
conn = sqlite3.connect(':memory:')
|
193 |
df.to_sql('emails', conn, index=False, if_exists='replace')
|
194 |
sql_buffer = io.BytesIO()
|
|
|
196 |
for line in conn.iterdump():
|
197 |
f.write(f'{line}\n'.encode('utf-8'))
|
198 |
sql_buffer.seek(0)
|
199 |
+
st.download_button("Download", sql_buffer, "emails.db", "application/octet-stream")
|
200 |
else:
|
201 |
st.warning("You are not authenticated yet.")
|