Spaces:
Running
Running
Chandima Prabhath
commited on
Commit
·
6dfcfe8
1
Parent(s):
1e6d365
Improve image generation error handling and update message for image count in webhook
Browse files
app.py
CHANGED
@@ -242,8 +242,11 @@ def _fn_generate_images(
|
|
242 |
client.send_media(message_id, chat_id, path, cap, media_type="image")
|
243 |
os.remove(path)
|
244 |
except Exception as e:
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
247 |
|
248 |
def _fn_voice_reply(
|
249 |
message_id: str,
|
@@ -489,16 +492,16 @@ async def whatsapp_webhook(request: Request):
|
|
489 |
if low.startswith("/gen"):
|
490 |
parts = body[4:].split("|")
|
491 |
pr = parts[0].strip()
|
492 |
-
|
493 |
width = int(parts[2]) if len(parts) > 2 and parts[2].isdigit() else None
|
494 |
height = int(parts[3]) if len(parts) > 3 and parts[3].isdigit() else None
|
495 |
-
_fn_send_accept(mid, chat_id, f"✨ Generating {
|
496 |
task_queue.put({
|
497 |
"type": "image",
|
498 |
"message_id": mid,
|
499 |
"chat_id": chat_id,
|
500 |
"prompt": pr,
|
501 |
-
"count":
|
502 |
"width": width,
|
503 |
"height": height
|
504 |
})
|
|
|
242 |
client.send_media(message_id, chat_id, path, cap, media_type="image")
|
243 |
os.remove(path)
|
244 |
except Exception as e:
|
245 |
+
if "Timed out" in str(e):
|
246 |
+
logger.warning("Image generation timed out.")
|
247 |
+
else:
|
248 |
+
logger.warning(f"Img {i}/{count} failed: {e}")
|
249 |
+
_fn_send_text(message_id, chat_id, f"😢 Failed to generate image {i}/{count}.")
|
250 |
|
251 |
def _fn_voice_reply(
|
252 |
message_id: str,
|
|
|
492 |
if low.startswith("/gen"):
|
493 |
parts = body[4:].split("|")
|
494 |
pr = parts[0].strip()
|
495 |
+
count = int(parts[1]) if len(parts) > 1 and parts[1].isdigit() else BotConfig.DEFAULT_IMAGE_COUNT
|
496 |
width = int(parts[2]) if len(parts) > 2 and parts[2].isdigit() else None
|
497 |
height = int(parts[3]) if len(parts) > 3 and parts[3].isdigit() else None
|
498 |
+
_fn_send_accept(mid, chat_id, f"✨ Generating {count if count != 1 else 'a'} image{'s' if count != 1 else ''}...")
|
499 |
task_queue.put({
|
500 |
"type": "image",
|
501 |
"message_id": mid,
|
502 |
"chat_id": chat_id,
|
503 |
"prompt": pr,
|
504 |
+
"count": count,
|
505 |
"width": width,
|
506 |
"height": height
|
507 |
})
|