Python Error Work with Text and Photo

When I use this:

response = model.generate_content([text, img])

I get an error:

TypeError: Could not create Blob, expected Blob, dict or an Image type(PIL.Image.Image or IPython.display.Image).
Got a: <class ‘NoneType’>
Value: None

text is a string
img is PIL. Image

when I use 1 of them for example just text or just photo its working, but both no!

1 Like

Welcome @rlxrq

What version of the google-generativeai module are you using?

I tested with the following code and it works for me:

import PIL.Image
import google.generativeai as genai

genai.configure(api_key="API_KEY")

img = PIL.Image.open(fp='PATH_TO_IMAGE')
model = genai.GenerativeModel(model_name='gemini-1.5-pro-latest')

response = model.generate_content(contents=["Transcribe text from this image", img], stream=True)
response.resolve()
print(response.candidates[0])
1 Like