1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to send parallel request to Google Gemini?

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have 107 images and I want to extract text from them, and I am using Gemini API, and this is my code till now:

    # Gemini Model
    model = genai.GenerativeModel('gemini-pro-vision', safety_settings=safety_settings)

    # Code
    images_to_process = [os.path.join(image_dir, image_name) for image_name in os.listdir(image_dir)] # list of 107 images

    prompt = """Carefully scan this images: if it has text, extract all the text and return the text from it. If the image does not have text return '<000>'."""

    for image_path in tqdm(images_to_process):
    img = Image.open(image_path)
    output = model.generate_content([prompt, img])
    text = output.text
    print(text)


    In this code, I am just taking one image at a time and extracting text from it using Gemini.

    Problem - I have 107 images and this code is taking ~10 minutes to run. I know that Gemini API can handle 60 requests per minute. How to send 60 images at the same time? How to do it in batch?

    Continue reading...

Compartilhe esta Página