Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module 'google.generativeai' has no attribute 'ImageGenerationModel' for Image Generating #597

Open
mimonirbd opened this issue Oct 13, 2024 · 7 comments
Assignees
Labels
component:python sdk Issue/PR related to Python SDK type:help Support-related issues

Comments

@mimonirbd
Copy link

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

@Hamza-nabil
Copy link
Contributor

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.

@mimonirbd
Copy link
Author

That means currently it isn't possible to generate image by gemini api without vertext ai api?

@Gunand3043 Gunand3043 added status:triaged Issue/PR triaged to the corresponding sub-team component:python sdk Issue/PR related to Python SDK type:help Support-related issues labels Oct 14, 2024
@Gunand3043 Gunand3043 self-assigned this Oct 14, 2024
@Gunand3043
Copy link

@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 Gunand3043 added status:awaiting user response Awaiting a response from the author and removed status:triaged Issue/PR triaged to the corresponding sub-team labels Oct 14, 2024
@mimonirbd
Copy link
Author

@Gunand3043 Got it, Thanks.

@MarianoMolina
Copy link

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.

@Gunand3043 Gunand3043 removed the status:awaiting user response Awaiting a response from the author label Oct 15, 2024
@Gunand3043
Copy link

Hi @MarianoMolina, Imagen 3 in the Gemini API is not publicly available yet. Stay tuned for announcements regarding the status of this feature.

https://ai.google.dev/gemini-api/docs/imagen

@MarkDaoust
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:python sdk Issue/PR related to Python SDK type:help Support-related issues
Projects
None yet
Development

No branches or pull requests

5 participants