1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Google GenerativeAI unable to load video files

Discussão em 'Python' iniciado por Stack, Setembro 28, 2024 às 06:52.

  1. Stack

    Stack Membro Participativo

    I was building a small Flask app with HTML templates where a user could upload a video and I would use an LLM to describe the video.

    I receive the file URL through an HTML form, which I then save to a local folder.

    file_url = request.form[f'media-url-{i}']
    extension = file_url.split('?')[0].split('.')[-1]
    filename = str(uuid.uuid4()) + '.' + extension
    file_path = os.path.join(os.environ['TMP_DIR'], filename)


    The file works successfully with the image/video being saved.

    I then try to use the LLM as such:

    genai.configure(api_key=os.environ["GEMINI_API_KEY"])
    model = genai.GenerativeModel('gemini-1.5-flash')

    gen_file = genai.upload_file(path=file_path)
    response = model.generate_content([llm_prompt, gen_file).text


    This seems to work pretty well with image files.

    When I upload videos, this doesn't work on my Flask app (although the mechanism works when I test on a Jupyter notebook).

    This is the error I get:

    line 91, in generate_posts
    response = model.generate_content([llm_prompt, gen_file).text
    File "C:\miniconda3\lib\site-packages\google\generativeai\generative_models.py", line 331, in generate_content
    response = self._client.generate_content(
    File "C:\miniconda3\lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 830, in generate_content
    response = rpc(
    File "C:\miniconda3\lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in __call__
    return wrapped_func(*args, **kwargs)
    File "C:\miniconda3\lib\site-packages\google\api_core\retry\retry_unary.py", line 293, in retry_wrapped_func
    return retry_target(
    File "C:\miniconda3\lib\site-packages\google\api_core\retry\retry_unary.py", line 153, in retry_target
    _retry_error_helper(
    File "C:\miniconda3\lib\site-packages\google\api_core\retry\retry_base.py", line 212, in _retry_error_helper
    raise final_exc from source_exc
    File "C:\miniconda3\lib\site-packages\google\api_core\retry\retry_unary.py", line 144, in retry_target
    result = target()
    File "C:\miniconda3\lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
    return func(*args, **kwargs)
    File "C:\miniconda3\lib\site-packages\google\api_core\grpc_helpers.py", line 78, in error_remapped_callable
    raise exceptions.from_grpc_error(exc) from exc
    google.api_core.exceptions.FailedPrecondition: 400 The File shtw63tpykp2 is not in an ACTIVE state and usage is not allowed.


    Would you guys have any idea?

    Thanks!

    Continue reading...

Compartilhe esta Página