Showing PDF file on StreamlitSharing that's in github directory

Hi, i am building an app that does timeseries forecasting and would like to show a pdf instruction file on my about section. The problem is, it isnt showing in streamlit sharing but it is showing when i run it in browser locally. Here is examples and the code i used.

Locally:

Sharing:


image

Code:

    if st.checkbox("Show Instructions"):
        def show_pdf(file_path):
            with open(file_path,"rb") as f:
                  base64_pdf = base64.b64encode(f.read()).decode('utf-8')
            pdf_display = f'<embed src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf">'
            st.markdown(pdf_display, unsafe_allow_html=True)
        st.write(show_pdf("DFCU_Instructions_on_GUI.pdf"))

Possible anyone can tell me why it is showing None? and How i can fix this or have any other method to showcase an instruction pdf file in streamlit sharing, or maybe a download link where they can download the file that is on my public github?

My guess would be that Streamlit starts in a different directory on sharing than you are locally. Meaning, you relative file reference in show_pdf doesn’t exist, so Python shows None

Perhaps you could try using pathlib to programmatically determine where you file actually is?

Best,
Randy

1 Like

I got the solution for this, this is returning none just because we are using st.write. After displays pdf it becomes none. Now the solution is to remove that st.write, and just do a function call like this.

    pdf_file = st.file_uploader("Choose your Resume", type=["pdf"])
    if pdf_file is not None:
        save_image_path = './Uploaded_Resumes/'+pdf_file.name
        with open(save_image_path, "wb") as f:
            f.write(pdf_file.getbuffer())
        show_pdf(save_image_path)
2 Likes