[Python] Issues Getting Ghibli-Style Image Output with Gemini API - What Am I Missing?

Discussão em 'Python' iniciado por Stack, Maio 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm starting a venture in AI-powered image applications, and as a learning project, I'm developing a small app that transforms input images into Ghibli-style animation art.

    To experiment with different APIs, I tried the following models under the Gemini ecosystem:

    1. gemini-2.0-flash-exp-image-generation – Poor results.
    2. Uploading an image directly to Gemini Advanced 2.5 Pro (via chat interface) – Also produces unsatisfactory output.
    3. imagen-3.0-generate-002 – Seems like this model doesn't support image input?

    [​IMG]

    In contrast, when I upload the same image to ChatGPT (via the image upload feature) and use the simple prompt:


    Turn this image into Ghibli-style animation art
    ​

    …the output is significantly better and aligns more closely with the style I’m aiming for.

    [​IMG]

    Question:


    Am I missing something when using the Gemini API for this kind of task?

    Here’s the code I used to test gemini-2.0-flash-exp-image-generation:

    from PIL import Image
    from io import BytesIO
    import google.generativeai as genai
    from google.generativeai.types import GenerateContentConfig

    client = genai.Client(api_key=API_KEY)

    image = Image.open("a.jpg")

    prompt = "Turn this image into Ghibli-style animation art"

    response = client.models.generate_content(
    model='gemini-2.0-flash-exp-image-generation',
    contents=[prompt, image],
    config=GenerateContentConfig(
    response_modalities=['Text', 'Image']
    )
    )

    for part in response.candidates[0].content.parts:
    if part.text:
    print(part.text)
    elif part.inline_data:
    result_image = Image.open(BytesIO(part.inline_data.data))
    result_image.save('output.jpg')
    result_image.show()


    Any tips, corrections, or best practices would be appreciated!

    Thanks in advance.

    Continue reading...

Compartilhe esta Página