TimeoutError: The write operation timed out (using gemini with large audio files)

I am getting this error using google gemini apis (I think that's because of the file size, but I'm not sure, and I don't know how to fix it):

```
Traceback (most recent call last):
File "C:\Users\matte\Desktop\gemini.py", line 37, in <module>
audioFile = genai.upload_file(path = filePath, display_name = "audio_file")
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\google\generativeai\files.py", line 52, in upload_file
response = client.create_file(
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\google\generativeai\client.py", line 74, in create_file
result = request.execute()
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\_helpers.py", line 131, in positional_wrapper
return wrapped(*args, **kwargs)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\http.py", line 922, in execute
resp, content = _retry_request(
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\http.py", line 221, in _retry_request
raise exception
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\googleapiclient\http.py", line 190, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\httplib2\__init__.py", line 1725, in request
(response, content) = self._request(
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\httplib2\__init__.py", line 1441, in _request
(response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\site-packages\httplib2\__init__.py", line 1364, in _conn_request
conn.request(method, request_uri, body, headers)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1276, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1322, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1271, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 1070, in _send_output
self.send(chunk)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\http\client.py", line 992, in send
self.sock.sendall(data)
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1236, in sendall
v = self.send(byte_view[count:])
File "C:\Users\matte\AppData\Local\Programs\Python\Python310\lib\ssl.py", line 1205, in send
return self._sslobj.write(data)
TimeoutError: The write operation timed out
```


Here's my code:
```
import google.generativeai as genai

genai.configure(api_key=MY_API_KEY)
filePath = AUDIO_FILE_PATH

generation_config = {
"temperature": 1,
"top_p": 0.95,
"top_k": 0,
"max_output_tokens": 8192,
}

safety_settings = [
{
"category": "HARM_CATEGORY_HARASSMENT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_HATE_SPEECH",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
"threshold": "BLOCK_NONE"
},
{
"category": "HARM_CATEGORY_DANGEROUS_CONTENT",
"threshold": "BLOCK_NONE"
},
]


audioFile = genai.upload_file(path = filePath, display_name = "audio_file")


model = genai.GenerativeModel(model_name="gemini-1.5-pro-latest",
generation_config=generation_config,
safety_settings=safety_settings)

response = model.generate_content(["summarize this audio", audioFile])
print(response.text)
```

I saw this could be a problem with ssl upload, but couldn't find how to fix it on this specific case.
My network is doing about 5 MiB in upload, and the audio is 50 minutes long, 25 MB in size. With shorter audios I have no problems, but I saw on Geminiโ€™s website it should be able to use up to 9 hours-long audios.

0 0 146
0 REPLIES 0
Top Labels in this Space