Last active
January 21, 2023 21:12
-
-
Save CharlyWargnier/d3bdf62a301263e8874905a63f2d999d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from zipfile import ZipFile | |
from io import BytesIO | |
zipObj = ZipFile("sample.zip", "w") | |
# Add multiple files to the zip | |
zipObj.write("checkpoint") | |
zipObj.write("model_hyperparameters.json") | |
# close the Zip File | |
zipObj.close() | |
ZipfileDotZip = "sample.zip" | |
with open(ZipfileDotZip, "rb") as f: | |
bytes = f.read() | |
b64 = base64.b64encode(bytes).decode() | |
href = f"<a href=\"data:file/zip;base64,{b64}\" download='{ZipfileDotZip}.zip'>\ | |
Click last model weights\ | |
</a>" | |
st.sidebar.markdown(href, unsafe_allow_html=True) |
hi, do you know, why the zipped file can not be opened..?
Thank you for this! In my program, the user filtrate a data framework using streamlit input, and then downloads one pdf per resulting data frame line. So, I'm trying to create a zip with "on the fly" content, depending on the current filtering. Could you help with that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for this! FYI you forgot to add import base64 :)