Creating Download Button

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

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,

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


def get_binary_file_downloader_html(bin_file, file_label='File'):
    with open(bin_file, 'rb') as f:
        data =
    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