[st.file_uploader()] AttributeError: 'bytes' object has no attribute 'read'

Hi,

I have used Streamlit’s sample documentation code on st.file_uploader() I am unable to read the uploaded file using .read().

Error I am getting:
AttributeError: ‘bytes’ object has no attribute ‘read’

My code:
pdf_label = st.sidebar.file_uploader(“Upload PDF label document. Only 1 document is allowed for upload.”, type=“pdf”, accept_multiple_files=False)
pdf_compliance = st.sidebar.file_uploader(“Upload PDF compliance documents. You may upload more than 1 document!”, type=“pdf”, accept_multiple_files=True)

if pdf_label:
for pdf in pdf_label:
data = pdf.read()
st.write(data)

if pdf_compliance:
for pdf in pdf_compliance:
data = pdf.read()
st.write(data)

Appreciate if anyone knows a work around for this. Thanks!

Also, I am trying to pass the contents of the uploaded pdf documents into llamaparse to convert into markdown, however, llamaparse gives an error that the file type is not supported (llamaparse supports anything with a .pdf format). How do i go about implementing this workflow of: uploading pdf documents (st.file_uploader()) to streamlit > passing these documents to llamaparse to convert to markdown?

my code:
def llamaparse_markdown(pdf_docs):
“”"
Converts user input’s pdf documents into markdown text using llamaparse for LLM processing.

Args:
    pdf_docs (inputted pdf documents).

Returns:
    markdown text of the pdf documents.
"""
text = ""

if pdf_docs:
    for pdf in pdf_docs:
        # data = pdf.read()
        document = LlamaParse(result_type="markdown",
                    parsing_instruction="""
                    """
                    ).load_data(pdf)

        text += document[0].text

return text

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.