Browse Source

image generation

master
Hendrik Langer 2 years ago
parent
commit
2749350820
  1. 65
      matrix_pygmalion_bot/ai/runpod_pygmalion.py
  2. 4
      matrix_pygmalion_bot/core.py

65
matrix_pygmalion_bot/ai/runpod_pygmalion.py

@ -2,6 +2,7 @@ import asyncio
import os, tempfile import os, tempfile
import logging import logging
import json
import requests import requests
from transformers import AutoTokenizer, AutoConfig from transformers import AutoTokenizer, AutoConfig
@ -185,7 +186,7 @@ async def generate_image(input_prompt: str, negative_prompt: str, api_url: str,
"prompt": input_prompt, "prompt": input_prompt,
"negative_prompt": negative_prompt, "negative_prompt": negative_prompt,
"width": 512, "width": 512,
"height": 512, "height": 768,
# "nsfw": True # "nsfw": True
}, },
} }
@ -247,13 +248,12 @@ 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) 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): 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) return await generate_image_automatic(input_prompt, negative_prompt, "https://api.runpod.ai/v1/13rrs00l7yxikf/", api_key)
async def generate_image6(input_prompt: str, negative_prompt: str, api_key: str): 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) 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 serverless_automatic_request(payload, cmd, api_url: str, api_key: str):
# Set the API endpoint URL # Set the API endpoint URL
endpoint = api_url + "run" endpoint = api_url + "run"
@ -264,18 +264,10 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_
} }
# Define your inputs # Define your inputs
payload.update({"api_endpoint": cmd})
input_data = { input_data = {
"input": { "input": payload,
"prompt": input_prompt, "cmd": cmd,
"steps": 20,
# "restore_faces": True,
# "gfpgan_visibility": 0.5,
# "codeformer_visibility": 0.5,
# "codeformer_weight": 0.5,
# "override_settings": {
# "filter_nsfw": False,
# },
},
} }
logger.info(f"sending request to runpod.io") logger.info(f"sending request to runpod.io")
@ -310,7 +302,46 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_
raise ValueError(f"RETURN CODE {status}") raise ValueError(f"RETURN CODE {status}")
if not output: if not output:
raise ValueError(f"<ERROR>") raise ValueError(f"<ERROR> {status}")
return output
async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_url: str, api_key: str):
payload = {
"prompt": input_prompt,
"nagative_prompt": negative_prompt,
"steps": 20,
"seed": -1,
"width": 512,
"height": 768,
"restore_faces": True,
"gfpgan_visibility": 0.5,
"codeformer_visibility": 0.5,
"codeformer_weight": 0.5,
# "override_settings": {
# "filter_nsfw": False,
# },
}
output = await serverless_automatic_request(payload, "txt2img", api_url, api_key)
upscale = False
if upscale:
count = 0
for i in output['images']:
payload = {
"images": [i],
"prompt": input_prompt,
"nagative_prompt": negative_prompt,
"steps": 20,
"seed": -1,
# tile_width, tile_height, mask_blur, padding, seams_fix_width, seams_fix_denoise, seams_fix_padding, upscaler_index, save_upscaled_image, redraw_mode, save_seams_fix_image, seams_fix_mask_blur, seams_fix_type, target_size_type, custom_width, custom_height, custom_scale
# "script_args": ["",512,0,8,32,64,0.275,32,3,False,0,True,8,3,2,1080,1440,1.875],
# "script_name": "Ultimate SD upscale",
}
upscaled_output = await serverless_automatic_request(payload, "img2img", api_url, api_key)
output['images'][count] = upscaled_output['images'][count]
os.makedirs("./images", exist_ok=True) os.makedirs("./images", exist_ok=True)
files = [] files = []
@ -329,5 +360,3 @@ async def generate_image_automatic(input_prompt: str, negative_prompt: str, api_
return files return files

4
matrix_pygmalion_bot/core.py

@ -101,10 +101,12 @@ class Callbacks(object):
prompt = "a beautiful woman" prompt = "a beautiful woman"
if num == 1: 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" 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 num == 5:
negative_prompt = "anime, cartoon, penis, fake, drawing, illustration, boring, 3d render, long neck, out of frame, extra fingers, mutated hands, monochrome, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, glitchy, bokeh, (((long neck))), 3D, 3DCG, cgstation, red eyes, multiple subjects, extra heads, close up, watermarks, logo"
else: else:
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" 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: # else:
# negative_prompt = "ugly, out of frame" # negative_prompt = "ugly, deformed, out of frame"
if self.bot.service == "runpod": if self.bot.service == "runpod":
if num == 1: if num == 1:
output = await ai.generate_image1(prompt, negative_prompt, self.bot.runpod_api_key) output = await ai.generate_image1(prompt, negative_prompt, self.bot.runpod_api_key)

Loading…
Cancel
Save