valhalla commited on
Commit
ebd0807
1 Parent(s): 21e8f52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py CHANGED
@@ -14,6 +14,53 @@ DESCRIPTION = "# T2I-Adapter-SDXL Sketch"
14
  if not torch.cuda.is_available():
15
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18
  if torch.cuda.is_available():
19
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
@@ -84,6 +131,11 @@ with gr.Blocks() as demo:
84
  prompt = gr.Textbox(label="Prompt")
85
  run_button = gr.Button("Run")
86
  with gr.Accordion("Advanced options", open=False):
 
 
 
 
 
87
  negative_prompt = gr.Textbox(
88
  label="Negative prompt", value="extra digit, fewer digits, cropped, worst quality, low quality"
89
  )
@@ -140,6 +192,25 @@ with gr.Blocks() as demo:
140
  outputs=result,
141
  api_name=False,
142
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  run_button.click(
144
  fn=randomize_seed_fn,
145
  inputs=[seed, randomize_seed],
 
14
  if not torch.cuda.is_available():
15
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
16
 
17
+ styles = [
18
+ {
19
+ "name": "cinematic-default",
20
+ "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
21
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured"
22
+ },
23
+ {
24
+ "name": "sai-3d-model",
25
+ "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
26
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting"
27
+ },
28
+ {
29
+ "name": "sai-anime",
30
+ "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
31
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast"
32
+ },
33
+ {
34
+ "name": "sai-digital art",
35
+ "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
36
+ "negative_prompt": "photo, photorealistic, realism, ugly"
37
+ },
38
+ {
39
+ "name": "sai-photographic",
40
+ "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
41
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly"
42
+ },
43
+ {
44
+ "name": "sai-pixel art",
45
+ "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
46
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic"
47
+ },
48
+ {
49
+ "name": "sai-fantasy art",
50
+ "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
51
+ "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"
52
+ },
53
+ ]
54
+
55
+ styles = {k['name']: (k['prompt'], k['negative_prompt']) for k in styles}
56
+ default_style = styles['sai-photographic']
57
+ style_names = list(styles.keys())
58
+
59
+
60
+ def apply_style(style, positive, negative=""):
61
+ p, n = styles.get(style, default_style)
62
+ return p.replace('{prompt}', positive), n + negative
63
+
64
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
65
  if torch.cuda.is_available():
66
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
 
131
  prompt = gr.Textbox(label="Prompt")
132
  run_button = gr.Button("Run")
133
  with gr.Accordion("Advanced options", open=False):
134
+ style = gr.Dropdown(
135
+ choices=style_names,
136
+ value=default_style,
137
+ label="Style"
138
+ )
139
  negative_prompt = gr.Textbox(
140
  label="Negative prompt", value="extra digit, fewer digits, cropped, worst quality, low quality"
141
  )
 
192
  outputs=result,
193
  api_name=False,
194
  )
195
+ prompt.submit(
196
+ fn=apply_style,
197
+ inputs=[style, prompt, negative_prompt],
198
+ outputs=[prompt, negative_prompt],
199
+ queue=False,
200
+ api_name=False,
201
+ ).then(
202
+ fn=run,
203
+ inputs=inputs,
204
+ outputs=result,
205
+ api_name=False,
206
+ )
207
+ style.change(
208
+ fn=apply_style,
209
+ inputs=[style, prompt, negative_prompt],
210
+ outputs=[prompt, negative_prompt],
211
+ queue=False,
212
+ api_name=False,
213
+ )
214
  run_button.click(
215
  fn=randomize_seed_fn,
216
  inputs=[seed, randomize_seed],