songweig commited on
Commit
f5cbba2
1 Parent(s): d019488

add more examples

Browse files
Files changed (1) hide show
  1. app.py +116 -11
app.py CHANGED
@@ -62,6 +62,8 @@ def main():
62
  ):
63
  run_dir = 'results/'
64
  # Load region diffusion model.
 
 
65
  steps = 41 if not steps else steps
66
  guidance_weight = 8.5 if not guidance_weight else guidance_weight
67
  text_input = text_input if text_input != '' else rich_text_input
@@ -119,7 +121,7 @@ def main():
119
  return [plain_img[0], rich_img[0], token_maps]
120
 
121
  with gr.Blocks() as demo:
122
- demo.load(None, None, None, _js=load_js)
123
  gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">Expressive Text-to-Image Generation with Rich Text</h1>
124
  <p> Visit our <a href="https://rich-text-to-image.github.io/rich-text-to-json.html">rich-text-to-json interface</a> to generate rich-text JSON input.<p/>
125
  <p> <a href="https://rich-text-to-image.github.io">[Website]</a> | <a href="https://github.com/SongweiGe/rich-text-to-image">[Code]</a> <p/> """)
@@ -134,7 +136,7 @@ def main():
134
  negative_prompt = gr.Textbox(
135
  label='Negative Prompt',
136
  max_lines=1,
137
- placeholder='')
138
  seed = gr.Slider(label='Seed',
139
  minimum=0,
140
  maximum=100000,
@@ -179,7 +181,7 @@ def main():
179
  gr.Markdown(help_text)
180
 
181
  with gr.Row():
182
- examples = [
183
  [
184
  '{"ops":[{"insert":"a "},{"attributes":{"font":"slabo"},"insert":"night sky filled with stars"},{"insert":" above a "},{"attributes":{"font":"roboto"},"insert":"turbulent sea with giant waves"}]}',
185
  '',
@@ -189,6 +191,15 @@ def main():
189
  1,
190
  None
191
  ],
 
 
 
 
 
 
 
 
 
192
  [
193
  '{"ops":[{"attributes":{"link":"the awe-inspiring sky and ocean in the style of J.M.W. Turner"},"insert":"the awe-inspiring sky and sea"},{"insert":" by "},{"attributes":{"font":"mirza"},"insert":"a coast with flowers and grasses in spring"}]}',
194
  '',
@@ -198,6 +209,28 @@ def main():
198
  1,
199
  None
200
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  [
202
  '{"ops":[{"insert":"a Gothic "},{"attributes":{"color":"#b26b00"},"insert":"church"},{"insert":" in a the sunset with a beautiful landscape in the background."}]}',
203
  '',
@@ -208,23 +241,94 @@ def main():
208
  None
209
  ],
210
  [
211
- '{"ops": [{"insert": "A pizza with "}, {"attributes": {"size": "50px"}, "insert": "pineapples"}, {"insert": ", pepperonis, and mushrooms on the top, 4k, photorealistic"}]}',
212
- 'blurry, art, painting, rendering, drawing, sketch, ugly, duplicate, morbid, mutilated, mutated, deformed, disfigured low quality, worst quality',
213
- 768,
214
- 896,
215
- 6,
216
  1,
217
  None
218
  ],
219
  [
220
- '{"ops":[{"insert":"a "},{"attributes":{"font":"mirza"},"insert":"beautiful garden"},{"insert":" with a "},{"attributes":{"font":"roboto"},"insert":"snow mountain in the background"},{"insert":""}]}',
221
  '',
222
  512,
223
  512,
224
- 3,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
225
  1,
226
  None
227
  ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  [
229
  '{"ops":[{"insert":"A close-up 4k dslr photo of a "},{"attributes":{"link":"A cat wearing sunglasses and a bandana around its neck."},"insert":"cat"},{"insert":" riding a scooter. Palm trees in the background."}]}',
230
  '',
@@ -235,7 +339,8 @@ def main():
235
  None
236
  ],
237
  ]
238
- gr.Examples(examples=examples,
 
239
  inputs=[
240
  text_input,
241
  negative_prompt,
 
62
  ):
63
  run_dir = 'results/'
64
  # Load region diffusion model.
65
+ height = int(height)
66
+ width = int(width)
67
  steps = 41 if not steps else steps
68
  guidance_weight = 8.5 if not guidance_weight else guidance_weight
69
  text_input = text_input if text_input != '' else rich_text_input
 
121
  return [plain_img[0], rich_img[0], token_maps]
122
 
123
  with gr.Blocks() as demo:
124
+ # demo.load(None, None, None, _js=load_js)
125
  gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">Expressive Text-to-Image Generation with Rich Text</h1>
126
  <p> Visit our <a href="https://rich-text-to-image.github.io/rich-text-to-json.html">rich-text-to-json interface</a> to generate rich-text JSON input.<p/>
127
  <p> <a href="https://rich-text-to-image.github.io">[Website]</a> | <a href="https://github.com/SongweiGe/rich-text-to-image">[Code]</a> <p/> """)
 
136
  negative_prompt = gr.Textbox(
137
  label='Negative Prompt',
138
  max_lines=1,
139
+ placeholder='Example: poor quality, blurry, dark, low resolution, low quality, worst quality')
140
  seed = gr.Slider(label='Seed',
141
  minimum=0,
142
  maximum=100000,
 
181
  gr.Markdown(help_text)
182
 
183
  with gr.Row():
184
+ style_examples = [
185
  [
186
  '{"ops":[{"insert":"a "},{"attributes":{"font":"slabo"},"insert":"night sky filled with stars"},{"insert":" above a "},{"attributes":{"font":"roboto"},"insert":"turbulent sea with giant waves"}]}',
187
  '',
 
191
  1,
192
  None
193
  ],
194
+ [
195
+ '{"ops":[{"insert":"a "},{"attributes":{"font":"mirza"},"insert":"beautiful garden"},{"insert":" with a "},{"attributes":{"font":"roboto"},"insert":"snow mountain in the background"},{"insert":""}]}',
196
+ '',
197
+ 512,
198
+ 512,
199
+ 3,
200
+ 1,
201
+ None
202
+ ],
203
  [
204
  '{"ops":[{"attributes":{"link":"the awe-inspiring sky and ocean in the style of J.M.W. Turner"},"insert":"the awe-inspiring sky and sea"},{"insert":" by "},{"attributes":{"font":"mirza"},"insert":"a coast with flowers and grasses in spring"}]}',
205
  '',
 
209
  1,
210
  None
211
  ],
212
+ ]
213
+ gr.Examples(examples=style_examples,
214
+ label='Font style examples',
215
+ inputs=[
216
+ text_input,
217
+ negative_prompt,
218
+ height,
219
+ width,
220
+ seed,
221
+ color_guidance_weight,
222
+ rich_text_input,
223
+ ],
224
+ outputs=[
225
+ plaintext_result,
226
+ richtext_result,
227
+ token_map,
228
+ ],
229
+ fn=generate,
230
+ # cache_examples=True,
231
+ examples_per_page=20)
232
+ with gr.Row():
233
+ color_examples = [
234
  [
235
  '{"ops":[{"insert":"a Gothic "},{"attributes":{"color":"#b26b00"},"insert":"church"},{"insert":" in a the sunset with a beautiful landscape in the background."}]}',
236
  '',
 
241
  None
242
  ],
243
  [
244
+ '{"ops":[{"insert":"A mesmerizing sight that captures the beauty of a "},{"attributes":{"color":"#4775fc"},"insert":"rose"},{"insert":" blooming, close up"}]}',
245
+ '',
246
+ 512,
247
+ 512,
248
+ 8,
249
  1,
250
  None
251
  ],
252
  [
253
+ '{"ops":[{"insert":"A "},{"attributes":{"color":"#FFD700"},"insert":"marble statue of a wolf\'s head and shoulder"},{"insert":", surrounded by colorful flowers michelangelo, detailed, intricate, full of color, led lighting, trending on artstation, 4 k, hyperrealistic, 3 5 mm, focused, extreme details, unreal engine 5, masterpiece "}]}',
254
  '',
255
  512,
256
  512,
257
+ 5,
258
+ 0.6,
259
+ None
260
+ ],
261
+ ]
262
+ gr.Examples(examples=color_examples,
263
+ label='Font color examples',
264
+ inputs=[
265
+ text_input,
266
+ negative_prompt,
267
+ height,
268
+ width,
269
+ seed,
270
+ color_guidance_weight,
271
+ rich_text_input,
272
+ ],
273
+ outputs=[
274
+ plaintext_result,
275
+ richtext_result,
276
+ token_map,
277
+ ],
278
+ fn=generate,
279
+ # cache_examples=True,
280
+ examples_per_page=20)
281
+ with gr.Row():
282
+ size_examples = [
283
+ [
284
+ '{"ops": [{"insert": "A pizza with "}, {"attributes": {"size": "60px"}, "insert": "pineapple"}, {"insert": ", pepperoni, and mushroom on the top, 4k, photorealistic"}]}',
285
+ 'blurry, art, painting, rendering, drawing, sketch, ugly, duplicate, morbid, mutilated, mutated, deformed, disfigured low quality, worst quality',
286
+ 512,
287
+ 512,
288
+ 13,
289
+ 1,
290
+ None
291
+ ],
292
+ [
293
+ '{"ops": [{"insert": "A pizza with pineapple, "}, {"attributes": {"size": "20px"}, "insert": "pepperoni"}, {"insert": ", and mushroom on the top, 4k, photorealistic"}]}',
294
+ 'blurry, art, painting, rendering, drawing, sketch, ugly, duplicate, morbid, mutilated, mutated, deformed, disfigured low quality, worst quality',
295
+ 512,
296
+ 512,
297
+ 13,
298
+ 1,
299
+ None
300
+ ],
301
+ [
302
+ '{"ops": [{"insert": "A pizza with pineapple, pepperoni, and"}, {"attributes": {"size": "70px"}, "insert": "mushroom"}, {"insert": " on the top, 4k, photorealistic"}]}',
303
+ 'blurry, art, painting, rendering, drawing, sketch, ugly, duplicate, morbid, mutilated, mutated, deformed, disfigured low quality, worst quality',
304
+ 512,
305
+ 512,
306
+ 13,
307
  1,
308
  None
309
  ],
310
+ ]
311
+ gr.Examples(examples=size_examples,
312
+ label='Font size examples',
313
+ inputs=[
314
+ text_input,
315
+ negative_prompt,
316
+ height,
317
+ width,
318
+ seed,
319
+ color_guidance_weight,
320
+ rich_text_input,
321
+ ],
322
+ outputs=[
323
+ plaintext_result,
324
+ richtext_result,
325
+ token_map,
326
+ ],
327
+ fn=generate,
328
+ # cache_examples=True,
329
+ examples_per_page=20)
330
+ with gr.Row():
331
+ footnote_examples = [
332
  [
333
  '{"ops":[{"insert":"A close-up 4k dslr photo of a "},{"attributes":{"link":"A cat wearing sunglasses and a bandana around its neck."},"insert":"cat"},{"insert":" riding a scooter. Palm trees in the background."}]}',
334
  '',
 
339
  None
340
  ],
341
  ]
342
+ gr.Examples(examples=footnote_examples,
343
+ label='Footnote examples',
344
  inputs=[
345
  text_input,
346
  negative_prompt,