adamelliotfields commited on
Commit
97256ff
1 Parent(s): 1a688bc

Add config

Browse files
Files changed (3) hide show
  1. app.py +85 -80
  2. cli.py +18 -13
  3. config.py +54 -0
app.py CHANGED
@@ -1,33 +1,29 @@
1
  import argparse
 
2
 
3
  import gradio as gr
4
 
 
5
  from generate import generate
6
 
7
- DEFAULT_NEGATIVE_PROMPT = "<fast_negative>"
8
-
9
- # base font stacks
10
- MONO_FONTS = ["monospace"]
11
- SANS_FONTS = [
12
- "sans-serif",
13
- "Apple Color Emoji",
14
- "Segoe UI Emoji",
15
- "Segoe UI Symbol",
16
- "Noto Color Emoji",
17
- ]
18
-
19
- # random seed JS
20
- # display the seed as hover text
21
- # note that the CSS `content` attribute expects a string so we need to wrap the number in quotes
22
- SEED_JS = """
23
  () => {
24
- const n = Math.floor(Math.random() * 2**32);
25
  const button = document.getElementById("random");
26
  button.style.setProperty("--seed", `"${n}"`);
27
  return n;
28
  }
29
  """
30
 
 
 
 
 
 
 
 
 
31
 
32
  def read_file(path: str) -> str:
33
  with open(path, "r", encoding="utf-8") as file:
@@ -48,6 +44,9 @@ def handle_generate(*args):
48
  return images
49
 
50
 
 
 
 
51
  with gr.Blocks(
52
  head=read_file("./partials/head.html"),
53
  css="./app.css",
@@ -62,8 +61,8 @@ with gr.Blocks(
62
  radius_size=gr.themes.sizes.radius_sm,
63
  spacing_size=gr.themes.sizes.spacing_md,
64
  # fonts
65
- font=[gr.themes.GoogleFont("Inter"), *SANS_FONTS],
66
- font_mono=[gr.themes.GoogleFont("Ubuntu Mono"), *MONO_FONTS],
67
  ).set(
68
  layout_gap="8px",
69
  block_shadow="0 0 #0000",
@@ -85,86 +84,84 @@ with gr.Blocks(
85
  with gr.Group():
86
  negative_prompt = gr.Textbox(
87
  label="Negative Prompt",
88
- value=DEFAULT_NEGATIVE_PROMPT,
89
- placeholder="",
90
  lines=2,
91
  )
92
 
 
 
 
 
 
 
 
93
  with gr.Row():
94
- num_images = gr.Dropdown(
95
- choices=list(range(1, 5)),
96
- filterable=False,
97
- label="Images",
98
- value=4,
99
  scale=1,
100
  )
101
- width = gr.Slider(
102
- label="Width",
103
- minimum=256,
104
- maximum=1024,
105
- value=448,
106
- step=32,
107
- scale=2,
108
- )
109
- height = gr.Slider(
110
- label="Height",
111
- minimum=256,
112
- maximum=1024,
113
- value=576,
114
- step=32,
115
- scale=2,
116
  )
117
 
118
  with gr.Row():
119
  guidance_scale = gr.Slider(
 
120
  label="Guidance Scale",
121
  minimum=1.0,
122
  maximum=15.0,
123
- value=7,
124
  step=0.1,
125
  )
126
  inference_steps = gr.Slider(
 
127
  label="Inference Steps",
128
  minimum=1,
129
  maximum=50,
130
- value=30,
131
  step=1,
132
  )
 
 
 
 
 
 
 
133
 
134
  with gr.Row():
135
- model = gr.Dropdown(
136
- value="Lykon/dreamshaper-8",
137
- filterable=False,
138
- min_width=200,
139
- label="Model",
140
- scale=2,
141
- choices=[
142
- "fluently/Fluently-v4",
143
- "Linaqruf/anything-v3-1",
144
- "Lykon/dreamshaper-8",
145
- "prompthero/openjourney-v4",
146
- "runwayml/stable-diffusion-v1-5",
147
- "SG161222/Realistic_Vision_V5.1_Novae",
148
- ],
149
  )
150
- scheduler = gr.Dropdown(
151
- elem_id="scheduler",
152
- label="Scheduler",
 
 
 
 
 
 
 
 
153
  filterable=False,
154
- value="DEIS 2M",
155
- min_width=200,
156
- scale=2,
157
- choices=[
158
- "DEIS 2M",
159
- "DPM++ 2M",
160
- "DPM2 a",
161
- "Euler a",
162
- "Heun",
163
- "LMS",
164
- "PNDM",
165
- ],
166
  )
167
- seed = gr.Number(label="Seed", value=0, scale=1)
168
 
169
  with gr.Row():
170
  use_karras = gr.Checkbox(
@@ -177,24 +174,24 @@ with gr.Blocks(
177
  elem_classes=["checkbox"],
178
  label="Autoincrement",
179
  value=True,
180
- scale=4,
181
  )
182
 
183
  with gr.TabItem("🛠️ Advanced"):
184
  with gr.Group():
185
  with gr.Row():
186
  deepcache_interval = gr.Slider(
 
187
  label="DeepCache Interval",
188
  minimum=1,
189
  maximum=4,
190
- value=2,
191
  step=1,
192
  )
193
  tgate_step = gr.Slider(
 
 
194
  label="T-GATE Step",
195
  minimum=0,
196
- maximum=30,
197
- value=0,
198
  step=1,
199
  )
200
 
@@ -206,10 +203,10 @@ with gr.Blocks(
206
  value="png",
207
  )
208
  tome_ratio = gr.Slider(
 
209
  label="ToMe Ratio",
210
  minimum=0.0,
211
  maximum=0.5,
212
- value=0.0,
213
  step=0.01,
214
  )
215
 
@@ -275,8 +272,15 @@ with gr.Blocks(
275
  scale=1,
276
  )
277
 
278
- # update the random seed using JavaScript
279
- random_btn.click(None, outputs=[seed], js=SEED_JS)
 
 
 
 
 
 
 
280
 
281
  file_format.change(
282
  lambda f: gr.Gallery(format=f),
@@ -299,6 +303,7 @@ with gr.Blocks(
299
  inputs=[
300
  prompt,
301
  negative_prompt,
 
302
  seed,
303
  model,
304
  scheduler,
 
1
  import argparse
2
+ import json
3
 
4
  import gradio as gr
5
 
6
+ import config as cfg
7
  from generate import generate
8
 
9
+ # the CSS `content` attribute expects a string so we need to wrap the number in quotes
10
+ random_seed_js = """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  () => {
12
+ const n = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
13
  const button = document.getElementById("random");
14
  button.style.setProperty("--seed", `"${n}"`);
15
  return n;
16
  }
17
  """
18
 
19
+ seed_js = """
20
+ (seed) => {
21
+ const button = document.getElementById("random");
22
+ button.style.setProperty("--seed", `"${seed}"`);
23
+ return seed;
24
+ }
25
+ """
26
+
27
 
28
  def read_file(path: str) -> str:
29
  with open(path, "r", encoding="utf-8") as file:
 
44
  return images
45
 
46
 
47
+ with open("./styles/twri.json", "r") as f:
48
+ styles = json.load(f)
49
+
50
  with gr.Blocks(
51
  head=read_file("./partials/head.html"),
52
  css="./app.css",
 
61
  radius_size=gr.themes.sizes.radius_sm,
62
  spacing_size=gr.themes.sizes.spacing_md,
63
  # fonts
64
+ font=[gr.themes.GoogleFont("Inter"), *cfg.SANS_FONTS],
65
+ font_mono=[gr.themes.GoogleFont("Ubuntu Mono"), *cfg.MONO_FONTS],
66
  ).set(
67
  layout_gap="8px",
68
  block_shadow="0 0 #0000",
 
84
  with gr.Group():
85
  negative_prompt = gr.Textbox(
86
  label="Negative Prompt",
87
+ value=cfg.NEGATIVE_PROMPT,
88
+ placeholder="ugly, bad",
89
  lines=2,
90
  )
91
 
92
+ model = gr.Dropdown(
93
+ value=cfg.MODEL,
94
+ filterable=False,
95
+ label="Model",
96
+ choices=cfg.MODELS,
97
+ )
98
+
99
  with gr.Row():
100
+ style = gr.Dropdown(
101
+ label="Style",
102
+ choices=["None"] + [f"{style['name']}" for style in styles],
103
+ value=cfg.STYLE,
 
104
  scale=1,
105
  )
106
+ scheduler = gr.Dropdown(
107
+ elem_id="scheduler",
108
+ label="Scheduler",
109
+ filterable=False,
110
+ value=cfg.SCHEDULER,
111
+ min_width=200,
112
+ scale=1,
113
+ choices=cfg.SCHEDULERS,
 
 
 
 
 
 
 
114
  )
115
 
116
  with gr.Row():
117
  guidance_scale = gr.Slider(
118
+ value=cfg.GUIDANCE_SCALE,
119
  label="Guidance Scale",
120
  minimum=1.0,
121
  maximum=15.0,
122
+ scale=1,
123
  step=0.1,
124
  )
125
  inference_steps = gr.Slider(
126
+ value=cfg.INFERENCE_STEPS,
127
  label="Inference Steps",
128
  minimum=1,
129
  maximum=50,
130
+ scale=1,
131
  step=1,
132
  )
133
+ seed = gr.Number(
134
+ value=cfg.SEED,
135
+ label="Seed",
136
+ minimum=-1,
137
+ maximum=(2**64) - 1,
138
+ scale=1,
139
+ )
140
 
141
  with gr.Row():
142
+ width = gr.Slider(
143
+ value=cfg.WIDTH,
144
+ label="Width",
145
+ minimum=256,
146
+ maximum=1024,
147
+ step=32,
148
+ scale=1,
 
 
 
 
 
 
 
149
  )
150
+ height = gr.Slider(
151
+ value=cfg.HEIGHT,
152
+ label="Height",
153
+ minimum=256,
154
+ maximum=1024,
155
+ step=32,
156
+ scale=1,
157
+ )
158
+ num_images = gr.Dropdown(
159
+ choices=list(range(1, 5)),
160
+ value=cfg.NUM_IMAGES,
161
  filterable=False,
162
+ label="Images",
163
+ scale=1,
 
 
 
 
 
 
 
 
 
 
164
  )
 
165
 
166
  with gr.Row():
167
  use_karras = gr.Checkbox(
 
174
  elem_classes=["checkbox"],
175
  label="Autoincrement",
176
  value=True,
177
+ scale=3,
178
  )
179
 
180
  with gr.TabItem("🛠️ Advanced"):
181
  with gr.Group():
182
  with gr.Row():
183
  deepcache_interval = gr.Slider(
184
+ value=cfg.DEEPCACHE_INTERVAL,
185
  label="DeepCache Interval",
186
  minimum=1,
187
  maximum=4,
 
188
  step=1,
189
  )
190
  tgate_step = gr.Slider(
191
+ maximum=cfg.INFERENCE_STEPS,
192
+ value=cfg.TGATE_STEP,
193
  label="T-GATE Step",
194
  minimum=0,
 
 
195
  step=1,
196
  )
197
 
 
203
  value="png",
204
  )
205
  tome_ratio = gr.Slider(
206
+ value=cfg.TOME_RATIO,
207
  label="ToMe Ratio",
208
  minimum=0.0,
209
  maximum=0.5,
 
210
  step=0.01,
211
  )
212
 
 
272
  scale=1,
273
  )
274
 
275
+ # update the seed using JavaScript
276
+ random_btn.click(None, outputs=[seed], js=random_seed_js)
277
+
278
+ seed.change(
279
+ None,
280
+ inputs=[seed],
281
+ outputs=[],
282
+ js=seed_js,
283
+ )
284
 
285
  file_format.change(
286
  lambda f: gr.Gallery(format=f),
 
303
  inputs=[
304
  prompt,
305
  negative_prompt,
306
+ style,
307
  seed,
308
  model,
309
  scheduler,
cli.py CHANGED
@@ -1,5 +1,6 @@
1
  import argparse
2
 
 
3
  from generate import generate
4
 
5
 
@@ -10,31 +11,35 @@ def save_images(images, filename="image.png"):
10
 
11
 
12
  def main():
 
13
  parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
14
  parser.add_argument("prompt", type=str, metavar="PROMPT")
15
- parser.add_argument("-n", "--negative", type=str, metavar="STR", default="<fast_negative>")
16
- parser.add_argument("-s", "--seed", type=int, metavar="INT")
17
  parser.add_argument("-i", "--images", type=int, metavar="INT", default=1)
18
  parser.add_argument("-f", "--filename", type=str, metavar="STR", default="image.png")
19
- parser.add_argument("-w", "--width", type=int, metavar="INT", default=448)
20
- parser.add_argument("-h", "--height", type=int, metavar="INT", default=576)
21
- parser.add_argument("-m", "--model", type=str, metavar="STR", default="Lykon/dreamshaper-8")
22
- parser.add_argument("-d", "--deepcache", type=int, metavar="INT", default=2)
23
- parser.add_argument("-t", "--tgate", type=int, metavar="INT", default=20)
24
- parser.add_argument("--scheduler", type=str, metavar="STR", default="DEIS 2M")
25
- parser.add_argument("--guidance", type=float, metavar="FLOAT", default=7)
26
- parser.add_argument("--steps", type=int, metavar="INT", default=30)
27
- parser.add_argument("--tome", type=float, metavar="FLOAT", default=0.0)
 
28
  parser.add_argument("--taesd", action="store_true")
29
  parser.add_argument("--clip-skip", action="store_true")
30
  parser.add_argument("--truncate", action="store_true")
31
- parser.add_argument("--no-karras", action="store_false")
32
  parser.add_argument("--no-increment", action="store_false")
 
33
 
34
  args = parser.parse_args()
35
  images = generate(
36
  args.prompt,
37
  args.negative,
 
38
  args.seed,
39
  args.model,
40
  args.scheduler,
@@ -43,7 +48,7 @@ def main():
43
  args.guidance,
44
  args.steps,
45
  args.images,
46
- args.no_karras,
47
  args.taesd,
48
  args.clip_skip,
49
  args.truncate,
 
1
  import argparse
2
 
3
+ import config as cfg
4
  from generate import generate
5
 
6
 
 
11
 
12
 
13
  def main():
14
+ # fmt: off
15
  parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False)
16
  parser.add_argument("prompt", type=str, metavar="PROMPT")
17
+ parser.add_argument("-n", "--negative", type=str, metavar="STR", default=cfg.NEGATIVE_PROMPT)
18
+ parser.add_argument("-s", "--seed", type=int, metavar="INT", default=cfg.SEED)
19
  parser.add_argument("-i", "--images", type=int, metavar="INT", default=1)
20
  parser.add_argument("-f", "--filename", type=str, metavar="STR", default="image.png")
21
+ parser.add_argument("-w", "--width", type=int, metavar="INT", default=cfg.WIDTH)
22
+ parser.add_argument("-h", "--height", type=int, metavar="INT", default=cfg.HEIGHT)
23
+ parser.add_argument("-m", "--model", type=str, metavar="STR", default=cfg.MODEL)
24
+ parser.add_argument("-d", "--deepcache", type=int, metavar="INT", default=cfg.DEEPCACHE_INTERVAL)
25
+ parser.add_argument("-t", "--tgate", type=int, metavar="INT", default=cfg.TGATE_STEP)
26
+ parser.add_argument("--style", type=str, metavar="STR", default=cfg.STYLE)
27
+ parser.add_argument("--scheduler", type=str, metavar="STR", default=cfg.SCHEDULER)
28
+ parser.add_argument("--guidance", type=float, metavar="FLOAT", default=cfg.GUIDANCE_SCALE)
29
+ parser.add_argument("--steps", type=int, metavar="INT", default=cfg.INFERENCE_STEPS)
30
+ parser.add_argument("--tome", type=float, metavar="FLOAT", default=cfg.TOME_RATIO)
31
  parser.add_argument("--taesd", action="store_true")
32
  parser.add_argument("--clip-skip", action="store_true")
33
  parser.add_argument("--truncate", action="store_true")
34
+ parser.add_argument("--karras", action="store_true")
35
  parser.add_argument("--no-increment", action="store_false")
36
+ # fmt: on
37
 
38
  args = parser.parse_args()
39
  images = generate(
40
  args.prompt,
41
  args.negative,
42
+ args.style,
43
  args.seed,
44
  args.model,
45
  args.scheduler,
 
48
  args.guidance,
49
  args.steps,
50
  args.images,
51
+ args.karras,
52
  args.taesd,
53
  args.clip_skip,
54
  args.truncate,
config.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MONO_FONTS = ["monospace"]
2
+
3
+ SANS_FONTS = [
4
+ "sans-serif",
5
+ "Apple Color Emoji",
6
+ "Segoe UI Emoji",
7
+ "Segoe UI Symbol",
8
+ "Noto Color Emoji",
9
+ ]
10
+
11
+ NEGATIVE_PROMPT = "<fast_negative>"
12
+
13
+ MODEL = "Lykon/dreamshaper-8"
14
+
15
+ MODELS = [
16
+ "fluently/Fluently-v4",
17
+ "Linaqruf/anything-v3-1",
18
+ "Lykon/dreamshaper-8",
19
+ "prompthero/openjourney-v4",
20
+ "runwayml/stable-diffusion-v1-5",
21
+ "SG161222/Realistic_Vision_V5.1_Novae",
22
+ ]
23
+
24
+ SCHEDULER = "DEIS 2M"
25
+
26
+ SCHEDULERS = [
27
+ "DEIS 2M",
28
+ "DPM++ 2M",
29
+ "DPM2 a",
30
+ "Euler a",
31
+ "Heun",
32
+ "LMS",
33
+ "PNDM",
34
+ ]
35
+
36
+ STYLE = "None"
37
+
38
+ WIDTH = 576
39
+
40
+ HEIGHT = 448
41
+
42
+ NUM_IMAGES = 4
43
+
44
+ SEED = -1
45
+
46
+ GUIDANCE_SCALE = 7
47
+
48
+ INFERENCE_STEPS = 30
49
+
50
+ DEEPCACHE_INTERVAL = 2
51
+
52
+ TGATE_STEP = 0
53
+
54
+ TOME_RATIO = 0.0