Adding time taken to stable diffusion renders

This commit is contained in:
Luke Robles 2022-10-14 09:40:44 -07:00
parent 2381957cd1
commit e3339da557
2 changed files with 10 additions and 5 deletions

View File

@ -121,7 +121,7 @@ class ActualUtils(commands.Cog):
original_message = await ctx.followup.send(
"Please be patient, I'm generating your image"
)
file_path = await stable_diffusion.generate_image(
file_path, time_taken = await stable_diffusion.generate_image(
ip=ip,
port=port,
positives=positive_prompt,
@ -129,7 +129,7 @@ class ActualUtils(commands.Cog):
steps=steps,
)
await original_message.edit(
content="",
content=time_taken,
file=discord.File(
file_path,
filename="unknown.png",

View File

@ -1,6 +1,8 @@
from bs4 import BeautifulSoup
import base64
import json
import httpx
import json
import requests
import socket
import tempfile
@ -59,10 +61,13 @@ async def generate_image(ip, port, positives, negatives, steps):
client = httpx.AsyncClient()
response = await client.post(url, headers=headers, json=json_data, timeout=1200)
imageb64 = response.json()["data"][0][0].split("data:image/png;base64,")[1]
imgdata = base64.b64decode(imageb64)
file, file_path = tempfile.mkstemp()
with open(file_path, "wb") as f:
f.write(imgdata)
return file_path
soup = BeautifulSoup(response.json()["data"][2], "html.parser")
time_taken = soup.find("p", class_="time").text
return file_path, time_taken