SD plugin update image info
This commit is contained in:
parent
c4b6c750fb
commit
4ef6f3beb7
@ -8,6 +8,11 @@ from asyncio import Queue
|
||||
import argparse
|
||||
import simplematrixbotlib as botlib
|
||||
import markdown2
|
||||
from slugify import slugify
|
||||
|
||||
def slugify_prompt(prompt):
|
||||
# Generate a slug from the prompt
|
||||
return slugify(prompt)
|
||||
|
||||
# Queue to store pending commands
|
||||
command_queue = Queue()
|
||||
@ -58,9 +63,18 @@ async def handle_command(room, message, bot, prefix, config):
|
||||
|
||||
response = requests.post(url=url, json=payload)
|
||||
r = response.json()
|
||||
with open("/tmp/output.jpg", 'wb') as f:
|
||||
|
||||
# Slugify the prompt
|
||||
prompt_slug = (prompt)
|
||||
|
||||
# Construct filename
|
||||
filename = f"{prompt_slug}_{args.steps}_{args.h}x{args.w}_{sampler_name}_{args.cfg}.jpg"
|
||||
with open(f"/tmp/{filename}", 'wb') as f:
|
||||
f.write(base64.b64decode(r['images'][0]))
|
||||
await bot.api.send_image_message(room_id=room.room_id, image_filepath="/tmp/output.jpg") # Corrected argument name
|
||||
await bot.api.send_image_message(room_id=room.room_id, image_filepath=f"/tmp/{filename}") # Corrected argument name
|
||||
neg = neg.replace(" ", "")
|
||||
info_msg = f"""<details><summary>🍄⤵︎Image Info:⤵︎</summary><strong>Prompt:</strong> {prompt_slug}<br><strong>Steps:</strong> {args.steps}<br><strong>Dimensions:</strong> {args.h}x{args.w}<br><strong>Sampler:</strong> {sampler_name}<br><strong>CFG Scale:</strong> {args.cfg}<br><strong>Negative Prompt: {neg}</strong></details>"""
|
||||
await bot.api.send_markdown_message(room.room_id, info_msg)
|
||||
except argparse.ArgumentError as e:
|
||||
await bot.api.send_text_message(room.room_id, f"Error: {e}")
|
||||
await bot.api.send_markdown_message(room.room_id, "<details><summary>Stable Diffusion Help</summary>" + print_help() + "</details>")
|
||||
@ -71,6 +85,7 @@ async def handle_command(room, message, bot, prefix, config):
|
||||
next_command = await command_queue.get()
|
||||
await handle_command(*next_command)
|
||||
|
||||
|
||||
def print_help():
|
||||
return """
|
||||
<p>Generate images using self-hosted Stable Diffusion</p>
|
||||
|
@ -6,3 +6,4 @@ nio
|
||||
markdown2
|
||||
watchdog
|
||||
emoji
|
||||
python-slugify
|
||||
|
Loading…
Reference in New Issue
Block a user