Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
| 74 |
-
|
| 75 |
-
|
| 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 |
|