valhalla commited on
Commit
74ca97e
1 Parent(s): 336be84

add styles in base app

Browse files
Files changed (1) hide show
  1. app_base.py +53 -0
app_base.py CHANGED
@@ -6,12 +6,61 @@ import PIL.Image
6
  from model import ADAPTER_NAMES, Model
7
  from utils import MAX_SEED, randomize_seed_fn
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
  def create_demo(model: Model) -> gr.Blocks:
11
  def run(
12
  image: PIL.Image.Image,
13
  prompt: str,
14
  negative_prompt: str,
 
15
  adapter_name: str,
16
  num_inference_steps: int = 30,
17
  guidance_scale: float = 5.0,
@@ -21,6 +70,8 @@ def create_demo(model: Model) -> gr.Blocks:
21
  apply_preprocess: bool = True,
22
  progress=gr.Progress(track_tqdm=True),
23
  ) -> list[PIL.Image.Image]:
 
 
24
  return model.run(
25
  image=image,
26
  prompt=prompt,
@@ -48,6 +99,7 @@ def create_demo(model: Model) -> gr.Blocks:
48
  label="Negative prompt",
49
  value="anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
50
  )
 
51
  num_inference_steps = gr.Slider(
52
  label="Number of steps",
53
  minimum=1,
@@ -91,6 +143,7 @@ def create_demo(model: Model) -> gr.Blocks:
91
  image,
92
  prompt,
93
  negative_prompt,
 
94
  adapter_name,
95
  num_inference_steps,
96
  guidance_scale,
 
6
  from model import ADAPTER_NAMES, Model
7
  from utils import MAX_SEED, randomize_seed_fn
8
 
9
+ style_list = [
10
+ {
11
+ "name": "Cinematic",
12
+ "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
13
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
14
+ },
15
+ {
16
+ "name": "3D Model",
17
+ "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
18
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
19
+ },
20
+ {
21
+ "name": "Anime",
22
+ "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
23
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
24
+ },
25
+ {
26
+ "name": "Digital Art",
27
+ "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
28
+ "negative_prompt": "photo, photorealistic, realism, ugly",
29
+ },
30
+ {
31
+ "name": "Photographic",
32
+ "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
33
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
34
+ },
35
+ {
36
+ "name": "Pixel art",
37
+ "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
38
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
39
+ },
40
+ {
41
+ "name": "Fantasy art",
42
+ "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
43
+ "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",
44
+ },
45
+ ]
46
+
47
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
48
+ default_style_name = "Photographic"
49
+ default_style = styles[default_style_name]
50
+ style_names = list(styles.keys())
51
+
52
+
53
+ def apply_style(style_name: str, positive: str, negative: str = "") -> tuple[str, str]:
54
+ p, n = styles.get(style_name, default_style)
55
+ return p.replace("{prompt}", positive), n + negative
56
+
57
 
58
  def create_demo(model: Model) -> gr.Blocks:
59
  def run(
60
  image: PIL.Image.Image,
61
  prompt: str,
62
  negative_prompt: str,
63
+ style_name: str = default_style_name,
64
  adapter_name: str,
65
  num_inference_steps: int = 30,
66
  guidance_scale: float = 5.0,
 
70
  apply_preprocess: bool = True,
71
  progress=gr.Progress(track_tqdm=True),
72
  ) -> list[PIL.Image.Image]:
73
+ prompt, negative_prompt = apply_style(style_name, prompt, negative_prompt)
74
+
75
  return model.run(
76
  image=image,
77
  prompt=prompt,
 
99
  label="Negative prompt",
100
  value="anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
101
  )
102
+ style = gr.Dropdown(choices=style_names, value=default_style_name, label="Style")
103
  num_inference_steps = gr.Slider(
104
  label="Number of steps",
105
  minimum=1,
 
143
  image,
144
  prompt,
145
  negative_prompt,
146
+ style,
147
  adapter_name,
148
  num_inference_steps,
149
  guidance_scale,