multimodalart HF Staff commited on
Commit
2d645a3
·
verified ·
1 Parent(s): 8fc2468

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -8,6 +8,7 @@ from huggingface_hub import whoami
8
  from PIL import Image
9
  from io import BytesIO
10
  import tempfile
 
11
 
12
  # --- Google Gemini API Configuration ---
13
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
@@ -70,10 +71,17 @@ def unified_image_generator(
70
  # Always add the prompt to the contents
71
  contents.append(prompt)
72
 
73
- response = client.models.generate_content(
74
- model=GEMINI_MODEL_NAME,
75
- contents=contents,
76
- )
 
 
 
 
 
 
 
77
 
78
  image_data = _extract_image_data_from_response(response)
79
 
 
8
  from PIL import Image
9
  from io import BytesIO
10
  import tempfile
11
+ import time
12
 
13
  # --- Google Gemini API Configuration ---
14
  GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY", "")
 
71
  # Always add the prompt to the contents
72
  contents.append(prompt)
73
 
74
+ for attempt in range(1, 3 + 1):
75
+ try:
76
+ response = client.models.generate_content(
77
+ model=GEMINI_MODEL_NAME,
78
+ contents=contents,
79
+ )
80
+ break
81
+ except Exception as e:
82
+ if attempt == MAX_RETRIES:
83
+ raise gr.Error(f"The Gemini API returned an error: {e}")
84
+ time.sleep(1)
85
 
86
  image_data = _extract_image_data_from_response(response)
87