Spaces:
Sleeping
Sleeping
File size: 1,302 Bytes
20d4a20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import base64
from io import BytesIO
import streamlit as st
def save_workbook_to_bytes(wb):
# Save the workbook into a BytesIO object (in memory, not on disk)
byte_io = BytesIO()
wb.save(byte_io)
byte_io.seek(0) # Go to the beginning of the BytesIO buffer
return byte_io.getvalue()
# Function to serve the file for download
def serve_excel_for_download(file_path):
# Open the Excel file in binary mode
with open(file_path, "rb") as f:
file_data = f.read()
# Provide the download button for the user
st.download_button(
label="Download Example Excel File",
data=file_data,
file_name="example.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
# Function to convert image to base64 so that it can be displayed
def image_to_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
# Function to allow downloading the example images
def download_image(image_path, image_name):
with open(image_path, "rb") as file:
btn = st.download_button(
label=f"Download {image_name}",
data=file,
file_name=image_name,
mime="image/png"
)
return btn |