I’m using gradio to upload a pdf file, convert it to images and start a chat through Gemini. Everything indicates that the following code block
"def input_pdf_setup(uploaded_file):
if uploaded_file is not None:
## Convert the PDF to image
images=pdf2image.convert_from_bytes(uploaded_file.read())
first_page=images[0]
# Convert to bytes
img_byte_arr = io.BytesIO()
first_page.save(img_byte_arr, format='JPEG')
img_byte_arr = img_byte_arr.getvalue()
pdf_parts = [
{
"mime_type": "image/jpeg",
"data": base64.b64encode(img_byte_arr).decode() # encode to base64
}
]
return pdf_parts
else:
raise FileNotFoundError("No file found.")",
is responsible for the error message:
“File “”, line 30, in input_pdf_setup
images=pdf2image.convert_from_bytes(uploaded_file.read())
AttributeError: ‘NamedString’ object has no attribute ‘read’”.
Can anyone help?