hysts HF staff commited on
Commit
910b076
1 Parent(s): 5898cfd

pre-commit

Browse files
Files changed (2) hide show
  1. app.py +25 -23
  2. requirements.txt +3 -3
app.py CHANGED
@@ -7,64 +7,72 @@ import numpy as np
7
  import PIL.Image
8
  import torch
9
  import torchvision.transforms.functional as TF
10
- from diffusers import EulerAncestralDiscreteScheduler, StableDiffusionXLAdapterPipeline, T2IAdapter, AutoencoderKL
 
 
 
 
 
11
 
12
  DESCRIPTION = "# T2I-Adapter-SDXL Sketch"
13
 
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",
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": "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": "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": "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": "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": "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": "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['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"
67
- adapter = T2IAdapter.from_pretrained("TencentARC/t2i-adapter-sketch-sdxl-1.0", torch_dtype=torch.float16, variant="fp16")
 
 
68
  scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
69
  pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
70
  model_id,
@@ -135,14 +143,8 @@ with gr.Blocks() as demo:
135
  prompt = gr.Textbox(label="Prompt")
136
  run_button = gr.Button("Run")
137
  with gr.Accordion("Advanced options", open=False):
138
- style = gr.Dropdown(
139
- choices=style_names,
140
- value=default_style,
141
- label="Style"
142
- )
143
- negative_prompt = gr.Textbox(
144
- label="Negative prompt", value=""
145
- )
146
  num_steps = gr.Slider(
147
  label="Number of steps",
148
  minimum=1,
@@ -162,14 +164,14 @@ with gr.Blocks() as demo:
162
  minimum=0.5,
163
  maximum=1,
164
  step=0.1,
165
- value=.8,
166
  )
167
  cond_tau = gr.Slider(
168
  label="Fraction of timesteps for which adapter should be applied",
169
  minimum=0.5,
170
  maximum=1,
171
  step=0.1,
172
- value=.8,
173
  )
174
  seed = gr.Slider(
175
  label="Seed",
 
7
  import PIL.Image
8
  import torch
9
  import torchvision.transforms.functional as TF
10
+ from diffusers import (
11
+ AutoencoderKL,
12
+ EulerAncestralDiscreteScheduler,
13
+ StableDiffusionXLAdapterPipeline,
14
+ T2IAdapter,
15
+ )
16
 
17
  DESCRIPTION = "# T2I-Adapter-SDXL Sketch"
18
 
19
  if not torch.cuda.is_available():
20
  DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p>"
21
 
22
+ style_list = [
23
  {
24
  "name": "Cinematic",
25
  "prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
26
+ "negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
27
  },
28
  {
29
  "name": "3D Model",
30
  "prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
31
+ "negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
32
  },
33
  {
34
  "name": "Anime",
35
  "prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
36
+ "negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
37
  },
38
  {
39
  "name": "Digital Art",
40
  "prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
41
+ "negative_prompt": "photo, photorealistic, realism, ugly",
42
  },
43
  {
44
  "name": "Photographic",
45
  "prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
46
+ "negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
47
  },
48
  {
49
  "name": "Pixel art",
50
  "prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
51
+ "negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
52
  },
53
  {
54
  "name": "Fantasy art",
55
  "prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
56
+ "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",
57
  },
58
  ]
59
 
60
+ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
61
+ default_style = styles["Photographic"]
62
  style_names = list(styles.keys())
63
 
64
 
65
  def apply_style(style, positive, negative=""):
66
  p, n = styles.get(style, default_style)
67
+ return p.replace("{prompt}", positive), n + negative
68
+
69
 
70
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
71
  if torch.cuda.is_available():
72
  model_id = "stabilityai/stable-diffusion-xl-base-1.0"
73
+ adapter = T2IAdapter.from_pretrained(
74
+ "TencentARC/t2i-adapter-sketch-sdxl-1.0", torch_dtype=torch.float16, variant="fp16"
75
+ )
76
  scheduler = EulerAncestralDiscreteScheduler.from_pretrained(model_id, subfolder="scheduler")
77
  pipe = StableDiffusionXLAdapterPipeline.from_pretrained(
78
  model_id,
 
143
  prompt = gr.Textbox(label="Prompt")
144
  run_button = gr.Button("Run")
145
  with gr.Accordion("Advanced options", open=False):
146
+ style = gr.Dropdown(choices=style_names, value=default_style, label="Style")
147
+ negative_prompt = gr.Textbox(label="Negative prompt", value="")
 
 
 
 
 
 
148
  num_steps = gr.Slider(
149
  label="Number of steps",
150
  minimum=1,
 
164
  minimum=0.5,
165
  maximum=1,
166
  step=0.1,
167
+ value=0.8,
168
  )
169
  cond_tau = gr.Slider(
170
  label="Fraction of timesteps for which adapter should be applied",
171
  minimum=0.5,
172
  maximum=1,
173
  step=0.1,
174
+ value=0.8,
175
  )
176
  seed = gr.Slider(
177
  label="Seed",
requirements.txt CHANGED
@@ -1,8 +1,8 @@
 
1
  git+https://github.com/huggingface/diffusers@t2iadapterxl
2
- accelerate
3
- safetensors
4
  gradio==3.42.0
5
  Pillow==10.0.0
 
6
  torch==2.0.1
 
7
  transformers==4.33.0
8
- torchvision
 
1
+ accelerate==0.22.0
2
  git+https://github.com/huggingface/diffusers@t2iadapterxl
 
 
3
  gradio==3.42.0
4
  Pillow==10.0.0
5
+ safetensors==0.3.3
6
  torch==2.0.1
7
+ torchvision==0.15.2
8
  transformers==4.33.0