module 'google.generativeai' has no attribute 'ImageGenerationModel' for Image Generating
Opened this issue · 9 comments
Description of the bug:
I am using this script for gemini api to generate image:
import os
import google.generativeai as genai
genai.configure(api_key=os.environ['GEMINI_API_KEY'])
model = genai.ImageGenerationModel("imagen-3.0-generate-001")
result = model.generate_images(
prompt="Fuzzy bunnies in my kitchen",
number_of_images=2,
safety_filter_level="block_only_high",
person_generation="allow_adult",
aspect_ratio="3:4",
negative_prompt="Outside",
)
for image in result.images:
print(image)
# The output should look similar to this:
# <vertexai.preview.vision_models.GeneratedImage object at 0x78f3396ef370>
# <vertexai.preview.vision_models.GeneratedImage object at 0x78f3396ef700>
# <vertexai.preview.vision_models.GeneratedImage object at 0x78f33953c2b0>
# <vertexai.preview.vision_models.GeneratedImage object at 0x78f33953c280>
for image in result.images:
# Open and display the image using your local operating system.
image._pil_image.show()
Actual vs expected behavior:
I am using python 3.10 but when I run the code then showig this error:
PS C:\Users\M i Monir\Documents\python project\gemini content writer> & "C:/Users/M i Monir/AppData/Local/Programs/Python/Python310/python.exe" "c:/Users/M i Monir/Documents/python project/gemini content writer/gemini image generator.py"
Traceback (most recent call last):
File "c:\Users\M i Monir\Documents\python project\gemini content writer\gemini image generator.py", line 7, in <module>
model = genai.ImageGenerationModel("imagen-3.0-generate-001")
AttributeError: module 'google.generativeai' has no attribute 'ImageGenerationModel'
PS C:\Users\M i Monir\Documents\python project\gemini content writer>
How to fix it
Any other information you'd like to share?
No response
The code is from Generate images using Imagen 3 , but I think it not accurate as the current api SDK does not support image generation.
I found similar example in this notebook that use ImageGenerationModel
from vertexai.preview.vision_models
. it does make sense as the output is vertexai.preview.vision_models.GeneratedImage
object.
That means currently it isn't possible to generate image by gemini api without vertext ai api?
@mimonirbd , The model is still in early access and not generally available yet.
Preview: Imagen 3 in the Gemini API is available as an early access release in private preview. It's not yet generally available.
@Gunand3043 Got it, Thanks.
Its kinda silly that the docs are nonsense. The code example throws an exception, and the API Docs make the claim that img models are usable, yet it seems they are not.
I tried:
from google.generativeai.vision_models import ImageGenerationModel
Got this error too:
File "/usr/local/lib/python3.10/site-packages/google/generativeai/vision_models/_vision_models.py", line 695, in
class GenerateVideoOperation(operations.BaseOperation):
AttributeError: module 'google.generativeai.operations' has no attribute 'BaseOperation'. Did you mean: 'get_operation'?
The docs have been like this for weeks btw, so not sure what was the plan with this.
Hi @MarianoMolina, Imagen 3 in the Gemini API is not publicly available yet. Stay tuned for announcements regarding the status of this feature.
Hi everyone, @Gunand3043 is correct, Imagen is currently in an EAP.
The code supporting it is in the imagen
branch, but if you're not part of the EAP you won;'t be able to access it.
In the future we'll be more careful about exposing docs before things are generally available.
Any update as to when this will be available to the public?
Bump