Spaces:
Sleeping
Sleeping
import streamlit as st | |
import os | |
import zipfile | |
import base64 | |
# Function to generate a downloadable link | |
def create_download_link(file_path): | |
with open(file_path, "rb") as file: | |
bytes = file.read() | |
b64 = base64.b64encode(bytes).decode() | |
href = f'<a href="data:file/octet-stream;base64,{b64}" download={os.path.basename(file_path)}>Download {os.path.basename(file_path)}</a>' | |
return href | |
# Streamlit app | |
def app(): | |
uploaded_file = st.file_uploader("Choose a zip file", type="zip") | |
if uploaded_file is not None: | |
with zipfile.ZipFile(uploaded_file, 'r') as zip_ref: | |
zip_ref.extractall("/path/to/extract/to") # replace with the path where you want to extract the files | |
st.success("Files extracted!") | |
for filename in zip_ref.namelist(): | |
file_path = os.path.join("/path/to/extract/to", filename) # replace with the path where you extracted the files | |
st.markdown(create_download_link(file_path), unsafe_allow_html=True) | |
# Run the app | |
if __name__ == "__main__": | |
app() | |