yamildiego commited on
Commit
71d0dea
·
1 Parent(s): 093fd24

test payload

Browse files
Files changed (3) hide show
  1. handler.py +14 -7
  2. payload.json +4 -1
  3. style_template.py +54 -0
handler.py CHANGED
@@ -9,6 +9,7 @@ from diffusers.utils import load_image
9
  import torch
10
  import torch.nn.functional as F
11
  from torchvision.transforms import Compose
 
12
 
13
  import PIL
14
  from PIL import Image
@@ -20,6 +21,10 @@ from insightface.app import FaceAnalysis
20
  from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
21
  from controlnet_aux import OpenposeDetector
22
 
 
 
 
 
23
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
24
  if device.type != 'cuda':
25
  raise ValueError("Se requiere ejecutar en GPU")
@@ -163,21 +168,23 @@ class EndpointHandler():
163
 
164
  def __call__(self, data):
165
 
166
- default_prompt = "{prompt}, Post-apocalyptic. Mars Colony, Scavengers roam the wastelands searching for valuable resources, rovers, bright morning sunlight shining, (detailed) (intricate) (8k) (HDR) (cinematic lighting) (sharp focus)"
167
- # default_prompt = "watercolor painting, {prompt}. vibrant, beautiful, painterly, detailed, textural, artistic"
 
 
 
168
  default_negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy"
169
 
170
  # hyperparamters
171
-
172
- # original img
173
  face_image_path = data.pop("face_image_path", "https://i.ibb.co/GQzm527/examples-musk-resize.jpg")
174
  pose_image_path = data.pop("pose_image_path", "https://i.ibb.co/TRCK4MS/examples-poses-pose2.jpg")
175
- # prompt_input = data.pop("inputs", "a man")
176
- prompt_input = "a man flying in the sky in Mars"
177
- prompt=default_prompt.replace("{prompt}", prompt_input)
178
  num_inference_steps = data.pop("num_inference_steps", 20)
179
  guidance_scale = data.pop("guidance_scale", 5.0)
180
  negative_prompt = data.pop("negative_prompt", default_negative_prompt)
 
 
 
181
 
182
  adapter_strength_ratio = 0.8
183
 
 
9
  import torch
10
  import torch.nn.functional as F
11
  from torchvision.transforms import Compose
12
+ from style_template import styles
13
 
14
  import PIL
15
  from PIL import Image
 
21
  from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
22
  from controlnet_aux import OpenposeDetector
23
 
24
+
25
+ STYLE_NAMES = list(styles.keys())
26
+ DEFAULT_STYLE_NAME = "Mars"
27
+
28
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
29
  if device.type != 'cuda':
30
  raise ValueError("Se requiere ejecutar en GPU")
 
168
 
169
  def __call__(self, data):
170
 
171
+
172
+ def apply_style(style_name: str, positive: str) -> str:
173
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
174
+ return p.replace("{prompt}", positive)
175
+
176
  default_negative_prompt = "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy"
177
 
178
  # hyperparamters
 
 
179
  face_image_path = data.pop("face_image_path", "https://i.ibb.co/GQzm527/examples-musk-resize.jpg")
180
  pose_image_path = data.pop("pose_image_path", "https://i.ibb.co/TRCK4MS/examples-poses-pose2.jpg")
181
+ prompt_input = data.pop("inputs", "a man flying in the sky in Mars")
 
 
182
  num_inference_steps = data.pop("num_inference_steps", 20)
183
  guidance_scale = data.pop("guidance_scale", 5.0)
184
  negative_prompt = data.pop("negative_prompt", default_negative_prompt)
185
+ style_name = data.pop("style_name", DEFAULT_STYLE_NAME)
186
+
187
+ prompt = apply_style(style_name, prompt_input, negative_prompt)
188
 
189
  adapter_strength_ratio = 0.8
190
 
payload.json CHANGED
@@ -1,5 +1,8 @@
1
  {
2
- "inputs": "a man",
 
 
 
3
  "guidance_scale": 5.0,
4
  "num_inference_steps": 20
5
  }
 
1
  {
2
+ "face_image_path": "https://i.ibb.co/GQzm527/examples-musk-resize.jpg",
3
+ "pose_image_path": "https://i.ibb.co/TRCK4MS/examples-poses-pose2.jpg",
4
+ "inputs": "a man flying in the sky in Mars",
5
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy",
6
  "guidance_scale": 5.0,
7
  "num_inference_steps": 20
8
  }
style_template.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ style_list = [
2
+ {
3
+ "name": "(No style)",
4
+ "prompt": "{prompt}",
5
+ "negative_prompt": "",
6
+ },
7
+ {
8
+ "name": "Spring Festival",
9
+ "prompt": "Flat illustration, a Chinese {prompt}, ancient style, wearing a red cloth, smile face, white skin, clean background, fireworks blooming, red lanterns",
10
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast, realistic, cropped, worst quality, missing fingers, extra digit, jpeg artifacts, signature, multiple, (lowres, low quality, worst quality:1.2)",
11
+ },
12
+ {
13
+ "name": "Watercolor",
14
+ "prompt": "watercolor painting, {prompt}. vibrant, beautiful, painterly, detailed, textural, artistic",
15
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, anime, photorealistic, 35mm film, deformed, glitch, low contrast, noisy",
16
+ },
17
+ {
18
+ "name": "Film Noir",
19
+ "prompt": "film noir style, ink sketch|vector, {prompt} highly detailed, sharp focus, ultra sharpness, monochrome, high contrast, dramatic shadows, 1940s style, mysterious, cinematic",
20
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
21
+ },
22
+ {
23
+ "name": "Neon",
24
+ "prompt": "masterpiece painting, buildings in the backdrop, kaleidoscope, lilac orange blue cream fuchsia bright vivid gradient colors, the scene is cinematic, {prompt}, emotional realism, double exposure, watercolor ink pencil, graded wash, color layering, magic realism, figurative painting, intricate motifs, organic tracery, polished",
25
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
26
+ },
27
+ {
28
+ "name": "Jungle",
29
+ "prompt": 'waist-up "{prompt} in a Jungle" by Syd Mead, tangerine cold color palette, muted colors, detailed, 8k,photo r3al,dripping paint,3d toon style,3d style,Movie Still',
30
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
31
+ },
32
+ {
33
+ "name": "Mars",
34
+ "prompt": "{prompt}, Post-apocalyptic. Mars Colony, Scavengers roam the wastelands searching for valuable resources, rovers, bright morning sunlight shining, (detailed) (intricate) (8k) (HDR) (cinematic lighting) (sharp focus)",
35
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
36
+ },
37
+ {
38
+ "name": "Vibrant Color",
39
+ "prompt": "vibrant colorful, ink sketch|vector|2d colors, at nightfall, sharp focus, {prompt}, highly detailed, sharp focus, the clouds,colorful,ultra sharpness",
40
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
41
+ },
42
+ {
43
+ "name": "Snow",
44
+ "prompt": "cinema 4d render, {prompt}, high contrast, vibrant and saturated, sico style, surrounded by magical glow,floating ice shards, snow crystals, cold, windy background, frozen natural landscape in background cinematic atmosphere,highly detailed, sharp focus, intricate design, 3d, unreal engine, octane render, CG best quality, highres, photorealistic, dramatic lighting, artstation, concept art, cinematic, epic Steven Spielberg movie still, sharp focus, smoke, sparks, art by pascal blanche and greg rutkowski and repin, trending on artstation, hyperrealism painting, matte painting, 4k resolution",
45
+ "negative_prompt": "(lowres, low quality, worst quality:1.2), (text:1.2), watermark, (frame:1.2), deformed, ugly, deformed eyes, blur, out of focus, blurry, deformed cat, deformed, photo, anthropomorphic cat, monochrome, photo, pet collar, gun, weapon, blue, 3d, drones, drone, buildings in background, green",
46
+ },
47
+ {
48
+ "name": "Line art",
49
+ "prompt": "line art drawing {prompt} . professional, sleek, modern, minimalist, graphic, line art, vector graphics",
50
+ "negative_prompt": "anime, photorealistic, 35mm film, deformed, glitch, blurry, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, mutated, realism, realistic, impressionism, expressionism, oil, acrylic",
51
+ },
52
+ ]
53
+
54
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}