Spaces:
Sleeping
Sleeping
Commit
•
83a3f82
1
Parent(s):
570bdfc
Update app.py
Browse files
app.py
CHANGED
@@ -21,23 +21,33 @@ uploaded_file = st.file_uploader("Upload an Excel file", type=["xlsx"])
|
|
21 |
|
22 |
|
23 |
import base64
|
|
|
24 |
|
25 |
def get_binary_file_downloader_link(file_data, file_name, link_text):
|
26 |
"""
|
27 |
Generates a link to download a file.
|
28 |
-
|
29 |
Parameters:
|
30 |
- file_data: The data you want to make available for download.
|
31 |
- file_name: The name of the file when downloaded.
|
32 |
- link_text: The text to display for the download link.
|
33 |
-
|
34 |
Returns:
|
35 |
- A Streamlit markdown link for downloading the file.
|
36 |
"""
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="{file_name}">{link_text}</a>'
|
|
|
39 |
return href
|
40 |
|
|
|
41 |
def pre_processing(data_frame):
|
42 |
|
43 |
# Lowercase all characters
|
|
|
21 |
|
22 |
|
23 |
import base64
|
24 |
+
from io import BytesIO
|
25 |
|
26 |
def get_binary_file_downloader_link(file_data, file_name, link_text):
|
27 |
"""
|
28 |
Generates a link to download a file.
|
29 |
+
|
30 |
Parameters:
|
31 |
- file_data: The data you want to make available for download.
|
32 |
- file_name: The name of the file when downloaded.
|
33 |
- link_text: The text to display for the download link.
|
34 |
+
|
35 |
Returns:
|
36 |
- A Streamlit markdown link for downloading the file.
|
37 |
"""
|
38 |
+
# Write the DataFrame to an in-memory Excel file
|
39 |
+
excel_buffer = BytesIO()
|
40 |
+
file_data.to_excel(excel_buffer, index=False, engine='xlsxwriter')
|
41 |
+
|
42 |
+
# Create a base64-encoded string of the Excel file's contents
|
43 |
+
b64 = base64.b64encode(excel_buffer.getvalue()).decode()
|
44 |
+
|
45 |
+
# Generate the download link
|
46 |
href = f'<a href="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,{b64}" download="{file_name}">{link_text}</a>'
|
47 |
+
|
48 |
return href
|
49 |
|
50 |
+
|
51 |
def pre_processing(data_frame):
|
52 |
|
53 |
# Lowercase all characters
|