From 8378f2b87fcb0108054e0f29b6a2cda9fd79a9f9 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Fri, 31 Mar 2023 13:53:56 +0200 Subject: [PATCH] image2 --- .gitignore | 3 +++ bot.conf2 | 4 ++-- matrix_pygmalion_bot/ai/runpod_pygmalion.py | 8 ++++---- matrix_pygmalion_bot/core.py | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b1445f2..22ed1e2 100644 --- a/.gitignore +++ b/.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__/ diff --git a/bot.conf2 b/bot.conf2 index ad22cfe..18d9a4e 100644 --- a/bot.conf2 +++ b/bot.conf2 @@ -1,6 +1,6 @@ [Julia] -current_tick = 630 +current_tick = 1310 [Hendrik] -current_tick = 350 +current_tick = 1030 diff --git a/matrix_pygmalion_bot/ai/runpod_pygmalion.py b/matrix_pygmalion_bot/ai/runpod_pygmalion.py index 4791c78..0cf5813 100644 --- a/matrix_pygmalion_bot/ai/runpod_pygmalion.py +++ b/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) diff --git a/matrix_pygmalion_bot/core.py b/matrix_pygmalion_bot/core.py index b98c86b..c74df4d 100644 --- a/matrix_pygmalion_bot/core.py +++ b/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)) -asyncio.get_event_loop().run_until_complete(main()) +if __name__ == "__main__": + asyncio.get_event_loop().run_until_complete(main())