[Python] Why is Q2 of my assignment not completing?

Discussão em 'Python' iniciado por Stack, Julho 8, 2025.

  1. Stack

    Stack Membro Participativo

    I don't understand where I am going wrong, why the Q2 of the assignment is not completing. Part 1 is completing.

    Here is my assignment:


    Task 2: Develop a second Python function called analyze_bouquet_image(image_path). This function will take the image path as input along with a text prompt to generate birthday wishes based on the image passed and send it to the gemini-2.0-flash-001 model. To ensure responses can be obtained as and when they are generated, enable streaming on the prompt requests.
    ​

    My final code (private info masked):

    import mimetypes
    import google.generativeai as genai

    # Initialize the SDK with your API key
    genai.configure(api_key="API_KEY")

    def analyze_bouquet_image(image_path, prompt):
    # Load image and detect MIME type
    mime_type, _ = mimetypes.guess_type(image_path)
    with open(image_path, "rb") as image_file:
    image_data = image_file.read()

    # Load the model
    model = genai.GenerativeModel("gemini-2.0-flash-001")

    # Stream the response
    responses = model.generate_content(
    contents=[
    {"text": prompt},
    {
    "inline_data": {
    "mime_type": mime_type or "image/jpeg",
    "data": image_data,
    }
    },
    ]
    )

    for chunk in responses:
    if chunk.text:
    print(chunk.text, end="", flush=True)

    # Usage
    local_image_path = "/home/student/image.jpeg"
    prompt = "Generate birthday wishes based on the image"
    analyze_bouquet_image(local_image_path, prompt)


    Every time I press verify, I see the same error message:


    Please use the generated image to read the content of the image and wait till the log gets created.
    ​

    What can I try next?

    Continue reading...

Compartilhe esta Página