Added clearer error notifications

This commit is contained in:
phixxy 2023-07-16 16:40:49 -07:00
parent d4cca24392
commit f02263a9b4

View file

@ -1255,6 +1255,7 @@ async def imagine(ctx):
async with session.post(url, headers=headers, json=payload) as resp:
r = await resp.json()
except Exception as error:
await ctx.send("My image generation service may not be running.")
await handle_error(error)
for i in r['images']:
@ -1269,6 +1270,7 @@ async def imagine(ctx):
async with session.post(url, json=png_payload) as resp:
response2 = await resp.json()
except Exception as error:
await ctx.send("My image generation service may not be running.")
await handle_error(error)
pnginfo = PngImagePlugin.PngInfo()
@ -1354,6 +1356,7 @@ async def reimagine(ctx):
key_value_pairs, prompt = extract_key_value_pairs(prompt)
try:
async with aiohttp.ClientSession() as session:
async with session.get(file_url) as response:
imageName = "tmp/" + str(len(os.listdir("tmp/"))) + ".png"
@ -1365,6 +1368,10 @@ async def reimagine(ctx):
break
out_file.write(chunk)
except Exception as error:
await ctx.send("My image generation service may not be running.")
await handle_error(error)
img_link = my_open_img_file(imageName)
#negative_prompt = ""
@ -1375,6 +1382,7 @@ async def reimagine(ctx):
payload = {"init_images": [img_link], "prompt": prompt, "steps": 40, "negative_prompt": negative_prompt, "denoising_strength": 0.5}
payload = combine_dicts(payload, key_value_pairs)
try:
async with aiohttp.ClientSession() as session:
async with session.post(url=f'{url}/sdapi/v1/img2img', json=payload) as response:
data = await response.json()
@ -1392,6 +1400,9 @@ async def reimagine(ctx):
with open(my_filename, "rb") as fh:
f = discord.File(fh, filename=my_filename)
await ctx.send(file=f)
except Exception as error:
await ctx.send("My image generation service may not be running.")
await handle_error(error)
@bot.command()