Hendrik Langer 2 years ago
parent
commit
b33c572c49
  1. 21
      matrix_pygmalion_bot/ai/runpod_pygmalion.py
  2. 101
      matrix_pygmalion_bot/core.py

21
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): 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) 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): async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_url: str, api_key: str):
# Set the API endpoint URL # Set the API endpoint URL
@ -259,12 +268,12 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_
"input": { "input": {
"prompt": input_prompt, "prompt": input_prompt,
"steps": 20, "steps": 20,
"restore_faces": True, # "restore_faces": True,
"gfpgan_visibility": 0.5, # "gfpgan_visibility": 0.5,
"codeformer_visibility": 0.5, # "codeformer_visibility": 0.5,
"codeformer_weight": 0.5, # "codeformer_weight": 0.5,
"override_settings": { # "override_settings": {
"filter_nsfw": False, # "filter_nsfw": False,
}, },
}, },
} }

101
matrix_pygmalion_bot/core.py

@ -83,30 +83,15 @@ class Callbacks(object):
print(event) print(event)
await self.bot.send_message(self.client, room.room_id, "Hello World!") await self.bot.send_message(self.client, room.room_id, "Hello World!")
return return
elif event.body == "!image" or event.body.startswith('!image ') or event.body.startswith('!image1'):
prompt = event.body.removeprefix('!image').removeprefix('!image1').strip() elif re.search("^!image(?P<num>[0-9])(\s(?P<cmd>.*))?$", event.body):
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" m = re.search("^!image(?P<num>[0-9])?(\s(?P<cmd>.*))?$", event.body)
if len(prompt) > 0: if m['num']:
if self.bot.image_prompt: num = int(m['num'])
prompt.replace(self.bot.name, self.bot.image_prompt)
else: else:
if self.bot.image_prompt: num = 1
prompt = self.bot.image_prompt if m['cmd']:
else: prompt = m['cmd'].strip()
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:
if self.bot.image_prompt: if self.bot.image_prompt:
prompt.replace(self.bot.name, self.bot.image_prompt) prompt.replace(self.bot.name, self.bot.image_prompt)
else: else:
@ -114,55 +99,43 @@ class Callbacks(object):
prompt = self.bot.image_prompt prompt = self.bot.image_prompt
else: else:
prompt = "a beautiful woman" prompt = "a beautiful woman"
if self.bot.service == "runpod": if num == 1:
output = await ai.generate_image2(prompt, negative_prompt, self.bot.runpod_api_key) 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"
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)
else: else:
if self.bot.image_prompt: 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"
prompt = self.bot.image_prompt # else:
else: # negative_prompt = "ugly, out of frame"
prompt = "a beautiful woman"
if self.bot.service == "runpod": if self.bot.service == "runpod":
output = await ai.generate_image3(prompt, negative_prompt, self.bot.runpod_api_key) if num == 1:
elif self.bot.service == "stablehorde": output = await ai.generate_image1(prompt, negative_prompt, self.bot.runpod_api_key)
output = await ai.generate_image3(prompt, negative_prompt, self.bot.stablehorde_api_key) elif num == 2:
else: output = await ai.generate_image2(prompt, negative_prompt, self.bot.runpod_api_key)
pass elif num == 3:
for imagefile in output: output = await ai.generate_image3(prompt, negative_prompt, self.bot.runpod_api_key)
await self.bot.send_image(self.client, room.room_id, imagefile) elif num == 4:
return output = await ai.generate_image4(prompt, negative_prompt, self.bot.runpod_api_key)
elif event.body.startswith('!image4'): elif num == 5:
prompt = event.body.removeprefix('!image4').strip() output = await ai.generate_image5(prompt, negative_prompt, self.bot.runpod_api_key)
negative_prompt = "ugly, out of frame" elif num == 6:
if len(prompt) > 0: output = await ai.generate_image6(prompt, negative_prompt, self.bot.runpod_api_key)
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
else: else:
prompt = "a beautiful woman" return
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)
elif self.bot.service == "stablehorde": 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: else:
pass return
for imagefile in output: for imagefile in output:
await self.bot.send_image(self.client, room.room_id, imagefile) await self.bot.send_image(self.client, room.room_id, imagefile)
return return
elif event.body.startswith('!begin'): elif event.body.startswith('!begin'):
self.bot.chat_history.room(room.display_name).clear() self.bot.chat_history.room(room.display_name).clear()
self.bot.room_config[room.room_id]["tick"] = 0 self.bot.room_config[room.room_id]["tick"] = 0

Loading…
Cancel
Save