Creating Download Button

Is there any possible way to create a download button in streamlit? I want to generate a txt file

@arwa
Welcome to the community!
This tutorial might help you. You can skim thru the video cz it is long.

Link: Building a Document Redactor NLP App with Streamlit and SpaCy ( Plus File Download)

Best Wishes,
Amaan

1 Like

Hi, @arwa there is a hack you can use to download a file from streamlit

import os
import base64
import streamlit as st

st.title('Downloader')

def get_binary_file_downloader_html(bin_file, file_label='File'):
    with open(bin_file, 'rb') as f:
        data = f.read()
    bin_str = base64.b64encode(data).decode()
    href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(bin_file)}">Download {file_label}</a>'
    return href

st.markdown(get_binary_file_downloader_html('info.txt', 'Text Download'), unsafe_allow_html=True)

Hope this is helpful.

1 Like

didnt’ worked!