From b33c572c497f263274fb812bbb673a15222a96d9 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Wed, 5 Apr 2023 02:05:14 +0200 Subject: [PATCH] fix --- matrix_pygmalion_bot/ai/runpod_pygmalion.py | 21 ++-- matrix_pygmalion_bot/core.py | 101 +++++++------------- 2 files changed, 52 insertions(+), 70 deletions(-) diff --git a/matrix_pygmalion_bot/ai/runpod_pygmalion.py b/matrix_pygmalion_bot/ai/runpod_pygmalion.py index 0a76e02..87d4bbc 100644 --- a/matrix_pygmalion_bot/ai/runpod_pygmalion.py +++ b/matrix_pygmalion_bot/ai/runpod_pygmalion.py @@ -243,6 +243,15 @@ async def generate_image2(input_prompt: str, negative_prompt: str, api_key: str) async def generate_image3(input_prompt: str, negative_prompt: str, api_key: str): return await generate_image(input_prompt, negative_prompt, "https://api.runpod.ai/v1/mf5f6mocy8bsvx/", api_key) +async def generate_image4(input_prompt: str, negative_prompt: str, api_key: str): + return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/lxdhmiccp3vdsf/", api_key) + +async def generate_image5(input_prompt: str, negative_prompt: str, api_key: str): + return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/p63t8o9si30nkh/", api_key) + +async def generate_image6(input_prompt: str, negative_prompt: str, api_key: str): + return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/5j1xzlsyw84vk5/", api_key) + async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_url: str, api_key: str): # Set the API endpoint URL @@ -259,12 +268,12 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_ "input": { "prompt": input_prompt, "steps": 20, - "restore_faces": True, - "gfpgan_visibility": 0.5, - "codeformer_visibility": 0.5, - "codeformer_weight": 0.5, - "override_settings": { - "filter_nsfw": False, +# "restore_faces": True, +# "gfpgan_visibility": 0.5, +# "codeformer_visibility": 0.5, +# "codeformer_weight": 0.5, +# "override_settings": { +# "filter_nsfw": False, }, }, } diff --git a/matrix_pygmalion_bot/core.py b/matrix_pygmalion_bot/core.py index dc6daf1..7f1537d 100644 --- a/matrix_pygmalion_bot/core.py +++ b/matrix_pygmalion_bot/core.py @@ -83,30 +83,15 @@ class Callbacks(object): print(event) await self.bot.send_message(self.client, room.room_id, "Hello World!") return - elif event.body == "!image" or event.body.startswith('!image ') or event.body.startswith('!image1'): - prompt = event.body.removeprefix('!image').removeprefix('!image1').strip() - negative_prompt = "out of frame, (ugly:1.3), (fused fingers), (too many fingers), (bad anatomy:1.5), (watermark:1.5), (words), letters, untracked eyes, asymmetric eyes, floating head, (logo:1.5), (bad hands:1.3), (mangled hands:1.2), (missing hands), (missing arms), backward hands, floating jewelry, unattached jewelry, floating head, doubled head, unattached head, doubled head, head in body, (misshapen body:1.1), (badly fitted headwear:1.2), floating arms, (too many arms:1.5), limbs fused with body, (facial blemish:1.5), badly fitted clothes, imperfect eyes, untracked eyes, crossed eyes, hair growing from clothes, partial faces, hair not attached to head" - if len(prompt) > 0: - if self.bot.image_prompt: - prompt.replace(self.bot.name, self.bot.image_prompt) + + elif re.search("^!image(?P[0-9])(\s(?P.*))?$", event.body): + m = re.search("^!image(?P[0-9])?(\s(?P.*))?$", event.body) + if m['num']: + num = int(m['num']) else: - if self.bot.image_prompt: - prompt = self.bot.image_prompt - else: - prompt = "a beautiful woman" - if self.bot.service == "runpod": - output = await ai.generate_image1(prompt, negative_prompt, self.bot.runpod_api_key) - elif self.bot.service == "stablehorde": - output = await ai.generate_image1(prompt, negative_prompt, self.bot.stablehorde_api_key) - else: - pass - for imagefile in output: - await self.bot.send_image(self.client, room.room_id, imagefile) - return - elif event.body.startswith('!image2'): - prompt = event.body.removeprefix('!image2').strip() - negative_prompt = "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face" - if len(prompt) > 0: + num = 1 + if m['cmd']: + prompt = m['cmd'].strip() if self.bot.image_prompt: prompt.replace(self.bot.name, self.bot.image_prompt) else: @@ -114,55 +99,43 @@ class Callbacks(object): prompt = self.bot.image_prompt else: prompt = "a beautiful woman" - if self.bot.service == "runpod": - output = await ai.generate_image2(prompt, negative_prompt, self.bot.runpod_api_key) - elif self.bot.service == "stablehorde": - output = await ai.generate_image2(prompt, negative_prompt, self.bot.stablehorde_api_key) - else: - pass - for imagefile in output: - await self.bot.send_image(self.client, room.room_id, imagefile) - return - elif event.body.startswith('!image3'): - prompt = event.body.removeprefix('!image3').strip() - negative_prompt = "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face" - if len(prompt) > 0: - if self.bot.image_prompt: - prompt.replace(self.bot.name, self.bot.image_prompt) + if num == 1: + negative_prompt = "out of frame, (ugly:1.3), (fused fingers), (too many fingers), (bad anatomy:1.5), (watermark:1.5), (words), letters, untracked eyes, asymmetric eyes, floating head, (logo:1.5), (bad hands:1.3), (mangled hands:1.2), (missing hands), (missing arms), backward hands, floating jewelry, unattached jewelry, floating head, doubled head, unattached head, doubled head, head in body, (misshapen body:1.1), (badly fitted headwear:1.2), floating arms, (too many arms:1.5), limbs fused with body, (facial blemish:1.5), badly fitted clothes, imperfect eyes, untracked eyes, crossed eyes, hair growing from clothes, partial faces, hair not attached to head" else: - if self.bot.image_prompt: - prompt = self.bot.image_prompt - else: - prompt = "a beautiful woman" + negative_prompt = "ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, bad anatomy, watermark, signature, cut off, low contrast, underexposed, overexposed, bad art, beginner, amateur, distorted face" +# else: +# negative_prompt = "ugly, out of frame" if self.bot.service == "runpod": - output = await ai.generate_image3(prompt, negative_prompt, self.bot.runpod_api_key) - elif self.bot.service == "stablehorde": - output = await ai.generate_image3(prompt, negative_prompt, self.bot.stablehorde_api_key) - else: - pass - for imagefile in output: - await self.bot.send_image(self.client, room.room_id, imagefile) - return - elif event.body.startswith('!image4'): - prompt = event.body.removeprefix('!image4').strip() - negative_prompt = "ugly, out of frame" - if len(prompt) > 0: - if self.bot.image_prompt: - prompt.replace(self.bot.name, self.bot.image_prompt) - else: - if self.bot.image_prompt: - prompt = self.bot.image_prompt + if num == 1: + output = await ai.generate_image1(prompt, negative_prompt, self.bot.runpod_api_key) + elif num == 2: + output = await ai.generate_image2(prompt, negative_prompt, self.bot.runpod_api_key) + elif num == 3: + output = await ai.generate_image3(prompt, negative_prompt, self.bot.runpod_api_key) + elif num == 4: + output = await ai.generate_image4(prompt, negative_prompt, self.bot.runpod_api_key) + elif num == 5: + output = await ai.generate_image5(prompt, negative_prompt, self.bot.runpod_api_key) + elif num == 6: + output = await ai.generate_image6(prompt, negative_prompt, self.bot.runpod_api_key) else: - prompt = "a beautiful woman" - if self.bot.service == "runpod": - output = await ai.generate_image_automatic(prompt, negative_prompt, "https://api.runpod.ai/v1/lxdhmiccp3vdsf/", self.bot.runpod_api_key) + return elif self.bot.service == "stablehorde": - pass + if num == 1: + output = await ai.generate_image1(prompt, negative_prompt, self.bot.stablehorde_api_key) + elif num == 2: + output = await ai.generate_image2(prompt, negative_prompt, self.bot.stablehorde_api_key) + elif num == 3: + output = await ai.generate_image3(prompt, negative_prompt, self.bot.stablehorde_api_key) + else: + return else: - pass + return + for imagefile in output: await self.bot.send_image(self.client, room.room_id, imagefile) return + elif event.body.startswith('!begin'): self.bot.chat_history.room(room.display_name).clear() self.bot.room_config[room.room_id]["tick"] = 0