Uploading files to GenAI Python module

Hello,

I am using the google-genai module in my flask python code. I would like to upload 2 files to genai and I want it to generate a response based on the files, text content that I set and variable text content. I have tried many different methods including the client.files.upload method. When using the client.files.upload method in regular python code without flask, the AI seems to generate a response based on one file.

However, when I use the same code in my flask project, there are many errors. When I use the genai module with the variables but without the files, the code works. Are there any ways to upload pdf files to the google.genai module (not the google.generativeai module).

Can you please help me with suggestions on how to resolve this?

Hi @Jacob_John , Welcome to the forum.

Are you uploading two files at a time using upload method??

Could you share sample code??

Thanks.

Hello @GUNAND_MAYANGLAMBAM,

Here is a link to my sample code. Thank you for replying :grinning_face:

Hey, can you try changing the way the prompt is structured when sending multiple PDFs?

Instead of including all the text instructions and files together in one big chunk, you can refer to the code below for reference:

pdf_path_1 = client.files.upload(file="/sample1.pdf")
pdf_path_2 = client.files.upload(file="/sample2.pdf")

contents300 = [
    types.UserContent(
    parts=[
        types.Part.from_text(text=("first pdf")),
        pdf_path_1, 
        types.Part.from_text(text=("second pdf")),
        pdf_path_2, 
        types.Part.from_text(text=("summarize the given pdfs")),
        types.Part.from_text(text=("generate some questions for each pdf")), 
    ]
)
]