Spaces:
Sleeping
Sleeping
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 |