sdwebui : add help reply

This commit is contained in:
lanvent
2023-03-14 12:07:03 +08:00
parent e6d148e729
commit e6b65437e4
2 changed files with 64 additions and 35 deletions

View File

@@ -31,7 +31,8 @@
"params": { "params": {
"width": 640, "width": 640,
"height": 384 "height": 384
} },
"desc": "分辨率会变成640x384"
}, },
{ {
"keywords": [ "keywords": [
@@ -49,7 +50,8 @@
"params": { "params": {
"enable_hr": true, "enable_hr": true,
"hr_scale": 1.6 "hr_scale": 1.6
} },
"desc": "出图分辨率长宽都会提高1.6倍"
}, },
{ {
"keywords": [ "keywords": [
@@ -61,7 +63,8 @@
}, },
"options": { "options": {
"sd_model_checkpoint": "meinamix_meinaV8" "sd_model_checkpoint": "meinamix_meinaV8"
} },
"desc": "使用二次元风格模型出图"
} }
] ]
} }

View File

@@ -4,6 +4,7 @@ import json
import os import os
from bridge.context import ContextType from bridge.context import ContextType
from bridge.reply import Reply, ReplyType from bridge.reply import Reply, ReplyType
from config import conf
import plugins import plugins
from plugins import * from plugins import *
from common.log import logger from common.log import logger
@@ -45,9 +46,18 @@ class SDWebUI(Plugin):
try: try:
content = e_context['context'].content[:] content = e_context['context'].content[:]
# 解析用户输入 如"横版 高清 二次元:cat" # 解析用户输入 如"横版 高清 二次元:cat"
if ":" in content:
keywords, prompt = content.split(":", 1) keywords, prompt = content.split(":", 1)
else:
keywords = content
prompt = ""
keywords = keywords.split() keywords = keywords.split()
if "help" in keywords or "帮助" in keywords:
reply.type = ReplyType.INFO
reply.content = self.get_help_text()
else:
rule_params = {} rule_params = {}
rule_options = {} rule_options = {}
for keyword in keywords: for keyword in keywords:
@@ -78,7 +88,7 @@ class SDWebUI(Plugin):
b_img = io.BytesIO() b_img = io.BytesIO()
result.image.save(b_img, format="PNG") result.image.save(b_img, format="PNG")
reply.content = b_img reply.content = b_img
e_context.action = EventAction.BREAK_PASS # 事件结束后,跳过处理context的默认逻辑 e_context.action = EventAction.BREAK_PASS # 事件结束后跳过处理context的默认逻辑
except Exception as e: except Exception as e:
reply.type = ReplyType.ERROR reply.type = ReplyType.ERROR
reply.content = "[SD] "+str(e) reply.content = "[SD] "+str(e)
@@ -86,3 +96,19 @@ class SDWebUI(Plugin):
e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑 e_context.action = EventAction.CONTINUE # 事件继续,交付给下个插件或默认逻辑
finally: finally:
e_context['reply'] = reply e_context['reply'] = reply
def get_help_text(self):
if not conf().get('image_create_prefix'):
return "画图功能未启用"
else:
trigger = conf()['image_create_prefix'][0]
help_text = f"请使用<{trigger}[关键词1] [关键词2]...:提示语>的格式作画,如\"{trigger}横版 高清:cat\"\n"
help_text += "目前可用关键词:\n"
for rule in self.rules:
keywords = [f"[{keyword}]" for keyword in rule['keywords']]
help_text += f"{','.join(keywords)}"
if "desc" in rule:
help_text += f"-{rule['desc']}\n"
else:
help_text += "\n"
return help_text