Warlord-K commited on
Commit
d49a403
1 Parent(s): ca76a99
Files changed (1) hide show
  1. app.py +73 -1
app.py CHANGED
@@ -26,6 +26,70 @@ ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
26
  ENABLE_REFINER = os.getenv("ENABLE_REFINER", "0") == "1"
27
 
28
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  if torch.cuda.is_available():
30
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
31
  pipe = StableDiffusionXLPipeline.from_pretrained(
@@ -73,6 +137,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
73
  def generate(
74
  prompt: str,
75
  negative_prompt: str = "",
 
76
  prompt_2: str = "",
77
  negative_prompt_2: str = "",
78
  use_negative_prompt: bool = False,
@@ -98,7 +163,7 @@ def generate(
98
  prompt_2 = None # type: ignore
99
  if not use_negative_prompt_2:
100
  negative_prompt_2 = None # type: ignore
101
-
102
  if not apply_refiner:
103
  image = pipe(
104
  prompt=prompt,
@@ -166,6 +231,12 @@ with gr.Blocks(css="style.css") as demo:
166
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
167
  use_prompt_2 = gr.Checkbox(label="Use prompt 2", value=False)
168
  use_negative_prompt_2 = gr.Checkbox(label="Use negative prompt 2", value=False)
 
 
 
 
 
 
169
  negative_prompt = gr.Text(
170
  label="Negative prompt",
171
  max_lines=1,
@@ -288,6 +359,7 @@ with gr.Blocks(css="style.css") as demo:
288
  inputs=[
289
  prompt,
290
  negative_prompt,
 
291
  prompt_2,
292
  negative_prompt_2,
293
  use_negative_prompt,
 
26
  ENABLE_REFINER = os.getenv("ENABLE_REFINER", "0") == "1"
27
 
28
  device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
29
+
30
+ style_list = [
31
+ {
32
+ "name": "(No style)",
33
+ "prompt": "{prompt}",
34
+ "negative_prompt": "",
35
+ },
36
+ {
37
+ "name": "Cinematic",
38
+ "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
39
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
40
+ },
41
+ {
42
+ "name": "Photographic",
43
+ "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
44
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
45
+ },
46
+ {
47
+ "name": "Anime",
48
+ "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
49
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
50
+ },
51
+ {
52
+ "name": "Manga",
53
+ "prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
54
+ "negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
55
+ },
56
+ {
57
+ "name": "Digital Art",
58
+ "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
59
+ "negative_prompt": "photo, photorealistic, realism, ugly",
60
+ },
61
+ {
62
+ "name": "Pixel art",
63
+ "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
64
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
65
+ },
66
+ {
67
+ "name": "Fantasy art",
68
+ "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
69
+ "negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
70
+ },
71
+ {
72
+ "name": "Neonpunk",
73
+ "prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
74
+ "negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
75
+ },
76
+ {
77
+ "name": "3D Model",
78
+ "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
79
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
80
+ },
81
+ ]
82
+
83
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
84
+ STYLE_NAMES = list(styles.keys())
85
+ DEFAULT_STYLE_NAME = "Cinematic"
86
+
87
+
88
+ def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
89
+ p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
90
+ return p.replace("{prompt}", positive), n + negative
91
+
92
+
93
  if torch.cuda.is_available():
94
  vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
95
  pipe = StableDiffusionXLPipeline.from_pretrained(
 
137
  def generate(
138
  prompt: str,
139
  negative_prompt: str = "",
140
+ style: str = DEFAULT_STYLE_NAME,
141
  prompt_2: str = "",
142
  negative_prompt_2: str = "",
143
  use_negative_prompt: bool = False,
 
163
  prompt_2 = None # type: ignore
164
  if not use_negative_prompt_2:
165
  negative_prompt_2 = None # type: ignore
166
+ prompt, negative_prompt = apply_refiner(style, prompt, negative_prompt)
167
  if not apply_refiner:
168
  image = pipe(
169
  prompt=prompt,
 
231
  use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False)
232
  use_prompt_2 = gr.Checkbox(label="Use prompt 2", value=False)
233
  use_negative_prompt_2 = gr.Checkbox(label="Use negative prompt 2", value=False)
234
+ style_selection = gr.Radio(
235
+ show_label=True, container=True, interactive=True,
236
+ choices=STYLE_NAMES,
237
+ value=DEFAULT_STYLE_NAME,
238
+ label='Image Style'
239
+ )
240
  negative_prompt = gr.Text(
241
  label="Negative prompt",
242
  max_lines=1,
 
359
  inputs=[
360
  prompt,
361
  negative_prompt,
362
+ style_selection,
363
  prompt_2,
364
  negative_prompt_2,
365
  use_negative_prompt,