I am building an API in FastAPI that receives a streaming video in the request. I need to send the video content to the Google Gemini API. I know that it is possible to generate content by the Gemini in a streaming mode, but I am not sure if it is possible to stream the input into the API.
I currently have a code similar to the following:
async for chunk in request.stream():
model = GenerativeModel("gemini-1.5-pro-preview-0409")
generation_config = {
"max_output_tokens": 8192,
"temperature": 1,
"top_p": 0.95,
}
video = Part.from_data(
mime_type="video/mp4",
data=base64.b64encode(chunk).decode("utf-8"),
)
responses = model.generate_content(
[prompt, video],
generation_config=generation_config,
stream=True,
)
for response in responses:
print(response.text)
However, it throws an error with the following content:
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.
Does anybody know if there is a way to stream a video content into the Gemini API? If it is not possible, could you provide any alternative solutions if possible?