The process of uploading videos using the File API has suddenly become very slow. Previously, a 30-second video would upload successfully within a few seconds, but now it can take up to several tens of minutes. This issue has persisted for a few days. I have tried changing the API key, checked the network, and even had other people run it on different hosts, but the problem remains unresolved.
The code I am using is as follows:
video_file = self.gemini_client.files.upload(file=video_segment)
while video_file.state.name == "PROCESSING":
time.sleep(1)
print(".", end="")
video_file = self.gemini_client.files.get(name=video_file.name)
contents = [
types.Content(
role="user",
parts=[
types.Part.from_uri(
file_uri=video_file.uri,
mime_type=video_file.mime_type,
),
types.Part.from_text(text=input_prompt),
],
),
]
for attempt in range(3):
try:
response = self.gemini_client.models.generate_content(
model=self.gemini_model_version,
contents=contents,
config={
'response_mime_type': 'application/json',
'response_schema': Output,
},
)
break
except errors.ServerError as e:
print(e.code)
print(e.message)
wait_time = 2 ** attempt
print(f"Attempt {attempt+1}/3: 503 error. Retrying in {wait_time}s...")
time.sleep(wait_time)
except Exception as e:
print(f"Fatal error: {str(e)}")
raise
After checking the output, a large number of “.” appears after each video upload.