add time estimation for image gen
Build and Push Container / build-and-push (push) Successful in 1m11s
Build and Push Container / build-and-push (push) Successful in 1m11s
This commit is contained in:
@@ -5,6 +5,7 @@ from __future__ import annotations
|
||||
import base64
|
||||
import logging
|
||||
import re
|
||||
import time
|
||||
from io import BytesIO
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
@@ -819,8 +820,13 @@ async def doodlebob(ctx: CommandsContext[Bot], *, message: str) -> None:
|
||||
return
|
||||
|
||||
# Alert the user we're generating the image
|
||||
db = get_database()
|
||||
estimated_seconds = db.get_image_generation_time_estimate()
|
||||
await ctx.send(f"**Doodlebob calling drone strike on {image_prompt[:100]}...**")
|
||||
if estimated_seconds is not None:
|
||||
await ctx.send(f"**Drone ETA: ~{estimated_seconds:.0f} seconds**")
|
||||
|
||||
start_time = time.monotonic()
|
||||
image_b64 = llama_wrapper.image_generation(
|
||||
prompt=image_prompt,
|
||||
openai_url=IMAGE_GEN_ENDPOINT,
|
||||
@@ -828,16 +834,22 @@ async def doodlebob(ctx: CommandsContext[Bot], *, message: str) -> None:
|
||||
model=IMAGE_GEN_MODEL,
|
||||
size=LAYOUT_SIZES[layout],
|
||||
)
|
||||
elapsed_seconds = time.monotonic() - start_time
|
||||
|
||||
if not image_b64:
|
||||
logger.warning("Image generation returned empty response.")
|
||||
await ctx.send("Failed to generate image. The server may be busy.")
|
||||
return
|
||||
|
||||
db.record_image_generation_time(elapsed_seconds)
|
||||
|
||||
try:
|
||||
edited_image_data = BytesIO(base64.b64decode(image_b64))
|
||||
send_img = discord.File(edited_image_data, filename="image.png")
|
||||
await ctx.send(file=send_img)
|
||||
await ctx.send(
|
||||
f"**Strike complete. Image generated in {elapsed_seconds:.1f} seconds.**",
|
||||
)
|
||||
except Exception:
|
||||
logger.exception("Failed to decode image data")
|
||||
await ctx.send("Failed to process the generated image.")
|
||||
|
||||
Reference in New Issue
Block a user