I am using Gemini 1.5 Flash on a Google Cloud (located in the US), and am not able to load a file (but I can do it locally). Locally, as said, it works and returns me the correct output. On GC, I get the message that the file has been uploaded, but then Gemini answers as it doesn’t have it. One hypotesis is that this problem occurs because I have my Gemini account based in Italy, and the GC functions run in the US. Another could be that the file may be corrupt.
Here is the uploaded file’s specifics that I printed in the GC terminal:
Audio file uploaded: genai.File({
'name': 'files/fxjmrf7j67we',
'display_name': 'audio_file',
'mime_type': 'audio/mpeg',
'sha256_hash': 'OTMyZjllZmU2NjJiMzNlNTUxYjEyZDI3Nzc2Y2NjYzk2OGI5N2EzN2JhYTYzZjQ5NTM5ZWY1YWI5MWY4MzM1NQ==',
'size_bytes': '13293',
'state': 'ACTIVE',
'uri': 'https://generativelanguage.googleapis.com/v1beta/files/fxjmrf7j67we',
'create_time': '2024-12-20T20:24:07.131807Z',
'expiration_time': '2024-12-22T20:24:07.124177437Z',
'update_time': '2024-12-20T20:24:07.131807Z'})
If I try to open the uri of the file, I get this (but I think that’s normal):
{
"error": {
"code": 403,
"message": "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API.",
"status": "PERMISSION_DENIED"
}
}
And here’s the function:
def summary(audio_path):
genai.configure(api_key=GEMINI_API_KEY)
try:
audioFile = genai.upload_file(audio_path, display_name="audio_file")
print(f"Audio file uploaded: {audioFile}")
except Exception as e:
print(f"Error uploading audio file: {e}")
generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 40,
"max_output_tokens": 8192,
"response_mime_type": "text/plain",
}
model = genai.GenerativeModel(model_name='gemini-1.5-flash', generation_config=generation_config)
prompt = """Summarise this audio file."""
try:
response = model.generate_content([prompt, audioFile])
response_text = response.text
print(f"Model response: {response_text}")
except Exception as e:
print(f"Error generating content: {e}")
return None
return response_text