-
Notifications
You must be signed in to change notification settings - Fork 465
Closed
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKtype:feature requestNew feature request/enhancementNew feature request/enhancement
Description
Description of the bug:
Currently P mode images cannot be uploaded to Gemini. https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes
Actual vs expected behavior:
import requests
from PIL import Image
import google.generativeai as genai
genai.configure(api_key)
media_url = "https://cdn.betterttv.net/emote/5f5a87416084af6c1719f9b4/3x"
image = Image.open(requests.get(media_url, stream=True).raw)
response = genai.GenerativeModel("gemini-1.5-flash").generate_content(["Describe this image.", image])
description = response.text.replace('\n', ' ')
print(description)
Actual:
Running this code gives the errors:
KeyError: 'P'
OSError: cannot write mode P as JPEG
Expected:
If we add the following line before generating the response
image = image.convert("RGB")
The code runs with no errors.
Any other information you'd like to share?
This is similar to this issue solved previously: #160
Metadata
Metadata
Assignees
Labels
component:python sdkIssue/PR related to Python SDKIssue/PR related to Python SDKtype:feature requestNew feature request/enhancementNew feature request/enhancement