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)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.