Greetings. I’m working on a Streamlit app that allows users to pose questions to GPT-3 about a historical text. I’ve recently moved my Python script to Streamlit cloud, and everything works well except rendering the pdf. Below is a screenshot, and here is a link to the app:
The pdf displays correctly when I run it locally, but no luck with Streamlit Cloud. I’ve tried multiple methods (here, here respectively), and here), and tried loading the pdf directly from the web, from Github, and from Google Drive. None seem to work. Here’s my code for displaying the pdf.
st.title("Ask A Source: Thomas More's 'The History of Richard III'")
col1, col2 = st.columns([2,3])
with col1:
#method 1
pdf_url = 'https://github.com/Dr-Hutchinson/prompt_chain_0/blob/main/annotated_full_text.pdf'
pdf_display = F'<iframe src="{pdf_url}" width="700" height="700" type="application/pdf"></iframe>'
st.markdown(pdf_display, unsafe_allow_html=True)
#method 2
st.markdown("""
<embed src="https://thomasmorestudies.org/wp-content/uploads/2020/09/Richard.pdf" width="800" height="800">
""", unsafe_allow_html=True)
#pdf_display = F'<iframe src="https://thomasmorestudies.org/wp-content/uploads/2020/09/Richard.pdf" width="700" height="1000" type="application/pdf"></iframe>'
Thanks very much for the reply. Unfortunately, all I get is an empty frame or or a message indicating Chrome is blocking the file (I’ve tried the same thing for Github and Google Drive, all with the same error)
I clicked your app link and the pdf is showing fine for me. What browser are you using? Can you try private/incognito windows? Can you try other browsers? Maybe you need to clear your browser cache or you have a security setting that is blocking it.
Thank you very much for checking it! For some reason it doesn’t display on my computers hooked up to my college’s network, but also displays fine on my phone(!). This will give me some options to see what’s going on. Thank you!
any updates @Daniel_Hutchinson on how you rendered it on streamlit cloud? I tried Chrome and i got the same thing and for safari it doesn’t even show lol.
This is how I’m rendering it
def show_pdf(folder_name, file_name):
with tempfile.NamedTemporaryFile("wb") as f_src:
logging.info(f"Downloading {file_name}...")
s3.download_file(f"{folder_name}/{file_name}", f_src.name)
with open(f_src.name, "rb") as f:
base64_pdf = base64.b64encode(f.read()).decode("utf-8")
pdf_display = f"""
<iframe
src="data:application/pdf;base64,{base64_pdf}"
width="100%" height="1000"
type="application/pdf"
style="min-width: 400px;"
>
</iframe>
"""
st.markdown(pdf_display, unsafe_allow_html=True)