Skip to content

Commit

Permalink
novelai0.4.12
Browse files Browse the repository at this point in the history
  • Loading branch information
sena-nana committed Oct 29, 2022
1 parent e17b0dc commit 1d8d303
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
6 changes: 5 additions & 1 deletion nonebot-plugin-novelai/nonebot-plugin-novelai/aidraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .data import htags
from .novelai import post
path = Path("data/novelai/output").resolve()
txt2img = on_command(".aidraw", aliases={"绘画", "咏唱", "约稿", "召唤"})
txt2img = on_command(".aidraw", aliases={"绘画", "咏唱", "召唤"})

cd = {}
gennerating = False
Expand All @@ -38,6 +38,10 @@ async def txt2img_handle(bot: Bot, event: GroupMessageEvent, args: Message = Com
count = 1
# 以图生图预处理
img_url = ""
reply=event.reply
if reply:
for seg in reply.message['image']:
img_url = seg.data["url"]
for seg in event.message['image']:
img_url = seg.data["url"]
imgbytes = ""
Expand Down
35 changes: 21 additions & 14 deletions nonebot-plugin-novelai/nonebot-plugin-novelai/fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36",
}

#自动切换模型
# 自动切换模型


def set_model():
if config.novelai_h:
return "nai-diffusion"
Expand All @@ -40,15 +42,16 @@ class FIFO():
uc: str = ""
width: int = 512
height: int = 512
img2img: bool = False
image: str = field(default=None, repr=False)

def __post_init__(self):
#数值合法检查
# 数值合法检查
if self.steps <= 0 or self.steps > 50:
self.steps = 28
self.uc = lowQuality+self.uc
self.__image_check()
#计算cost
# 计算cost
if config.novelai_paid == 1:
anlas = 0
if (self.width*self.height > 409600) or self.image or self.count > 1:
Expand All @@ -62,7 +65,7 @@ def __post_init__(self):
self.cost = 0

def __image_check(self):
#根据图片重写长宽
# 根据图片重写长宽
if self.image is not None:
tmpfile = BytesIO(self.image)
image = Image.open(tmpfile)
Expand All @@ -75,9 +78,10 @@ def __image_check(self):
self.width = 512
self.image = str(base64.b64encode(self.image), "utf-8")
self.steps = 50
self.img2img = True

def body(self):
#获取请求体
# 获取请求体
parameters = {
"width": self.width,
"height": self.height,
Expand All @@ -90,7 +94,7 @@ def body(self):
"ucPreset": 0,
"uc": self.uc,
}
if self.image is not None:
if self.img2img:
parameters.update({
"image": self.image,
"strength": self.strength,
Expand All @@ -101,13 +105,16 @@ def body(self):
"model": self.model,
"parameters": parameters
}

def keys(self):
return ("seed","tags","uc","scale","strength","noise","samper","model","steps","width","height")
def __getitem__(self,item):
return getattr(self,item)
return ("seed", "tags", "uc", "scale", "strength", "noise", "samper", "model", "steps", "width", "height","img2img")

def __getitem__(self, item):
return getattr(self, item)

def format(self):
dict_self=dict(self)
str=""
for i,v in dict_self.items():
str+=f"{i}={v}\n"
return str
dict_self = dict(self)
str = ""
for i, v in dict_self.items():
str += f"{i}={v}\n"
return str
2 changes: 1 addition & 1 deletion nonebot-plugin-novelai/nonebot-plugin-novelai/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self):
try:
self.version = version(self.package)
except:
self.version = "0.4.11"
self.version = "0.4.12"

async def check_update(self):
"""检查更新,并推送"""
Expand Down

0 comments on commit 1d8d303

Please sign in to comment.