Browse Source

image2

master
Hendrik Langer 2 years ago
parent
commit
8378f2b87f
  1. 3
      .gitignore
  2. 4
      bot.conf2
  3. 8
      matrix_pygmalion_bot/ai/runpod_pygmalion.py
  4. 16
      matrix_pygmalion_bot/core.py

3
.gitignore

@ -2,9 +2,12 @@
bot.conf
bot.conf2
.store
credentials.json
images/
chatlogs/
runpod-test*
Pipfile
Pipfile.lock
# Byte-compiled / optimized / DLL files
__pycache__/

4
bot.conf2

@ -1,6 +1,6 @@
[Julia]
current_tick = 630
current_tick = 1310
[Hendrik]
current_tick = 350
current_tick = 1030

8
matrix_pygmalion_bot/ai/runpod_pygmalion.py

@ -32,7 +32,7 @@ async def generate_sync(
"input": {
"prompt": prompt,
"max_length": max(prompt_num_tokens+max_new_tokens, 2048),
"temperature": 0.75,
"temperature": 0.80,
"do_sample": True,
}
}
@ -153,10 +153,10 @@ async def estimate_num_tokens(input_text: str):
return len(input_text)//4+1
async def generate_image(input_prompt: str, negative_prompt: str, api_key: str):
async def generate_image(input_prompt: str, negative_prompt: str, api_url: str, api_key: str):
# Set the API endpoint URL
endpoint = "https://api.runpod.ai/v1/sd-anything-v4/run"
endpoint = api_url + "run"
# Set the headers for the request
headers = {
@ -190,7 +190,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_key: str):
TIMEOUT = 180
DELAY = 5
for i in range(TIMEOUT//DELAY):
endpoint = "https://api.runpod.ai/v1/sd-anything-v4/status/" + job_id
endpoint = api_url + "status/" + job_id
r = requests.get(endpoint, headers=headers)
r_json = r.json()
logger.info(r_json)

16
matrix_pygmalion_bot/core.py

@ -75,12 +75,21 @@ class Callbacks(object):
print(event)
await self.bot.send_message(self.client, room.room_id, "Hello World!")
return
elif event.body.startswith('!image'):
prompt = event.body.removeprefix('!image').strip()
elif 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:
prompt = "a beautiful woman"
output = await ai.generate_image(prompt, negative_prompt, self.bot.runpod_api_key)
output = await ai.generate_image(prompt, negative_prompt, "https://api.runpod.ai/v1/sd-anything-v4/", self.bot.runpod_api_key)
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:
prompt = "a beautiful woman"
output = await ai.generate_image(prompt, negative_prompt, "https://api.runpod.ai/v1/stable-diffusion-v1/", self.bot.runpod_api_key)
for imagefile in output:
await self.bot.send_image(self.client, room.room_id, imagefile)
return
@ -357,4 +366,5 @@ async def main() -> None:
for bot in bots:
task = tg.create_task(bot.client.sync_forever(timeout=30000, full_state=True))
if __name__ == "__main__":
asyncio.get_event_loop().run_until_complete(main())

Loading…
Cancel
Save