songweig commited on
Commit
2793b63
1 Parent(s): d908d7c

enable font color with slower inference

Browse files
Files changed (1) hide show
  1. app.py +177 -187
app.py CHANGED
@@ -158,10 +158,11 @@ def main():
158
  with gr.Blocks(css=css) as demo:
159
  url_params = gr.JSON({}, visible=False, label="URL Params")
160
  gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">Expressive Text-to-Image Generation with Rich Text</h1>
161
- <p> <a href="https://songweige.github.io/">Songwei Ge</a>, <a href="https://taesung.me/">Taesung Park</a>, <a href="https://www.cs.cmu.edu/~junyanz/">Jun-Yan Zhu</a>, <a href="https://jbhuang0604.github.io/">Jia-Bin Huang</a> <p/>
162
  <p> UMD, Adobe, CMU <p/>
 
163
  <p> <a href="https://huggingface.co/spaces/songweig/rich-text-to-image?duplicate=true"><img src="https://bit.ly/3gLdBN6" style="display:inline;"alt="Duplicate Space"></a> | <a href="https://rich-text-to-image.github.io">[Website]</a> | <a href="https://github.com/SongweiGe/rich-text-to-image">[Code]</a> | <a href="https://arxiv.org/abs/2304.06720">[Paper]</a><p/>
164
- <p> For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.""")
165
  with gr.Row():
166
  with gr.Column():
167
  rich_text_el = gr.HTML(canvas_html, elem_id="canvas_html")
@@ -260,89 +261,78 @@ def main():
260
  with gr.Row():
261
  gr.Markdown(help_text)
262
 
263
- # with gr.Row():
264
- # footnote_examples = [
265
- # [
266
- # '{"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."}]}',
267
- # '',
268
- # 9,
269
- # 0.3,
270
- # 0.3,
271
- # 0.5,
272
- # 3,
273
- # 0,
274
- # None,
275
- # ],
276
- # [
277
- # '{"ops":[{"insert":"A cozy "},{"attributes":{"link":"A charming wooden cabin with Christmas decoration, warm light coming out from the windows."},"insert":"cabin"},{"insert":" nestled in a "},{"attributes":{"link":"Towering evergreen trees covered in a thick layer of pristine snow."},"insert":"snowy forest"},{"insert":", and a "},{"attributes":{"link":"A cute snowman wearing a carrot nose, coal eyes, and a colorful scarf, welcoming visitors with a cheerful vibe."},"insert":"snowman"},{"insert":" stands in the yard."}]}',
278
- # '',
279
- # 12,
280
- # 0.4,
281
- # 0.3,
282
- # 0.5,
283
- # 3,
284
- # 0,
285
- # None,
286
- # ],
287
- # [
288
- # '{"ops":[{"insert":"A "},{"attributes":{"link":"Happy Kung fu panda art, elder, asian art, volumetric lighting, dramatic scene, ultra detailed, realism, chinese"},"insert":"panda"},{"insert":" standing on a cliff by a waterfall, wildlife photography, photograph, high quality, wildlife, f 1.8, soft focus, 8k, national geographic, award - winning photograph by nick nichols"}]}',
289
- # '',
290
- # 5,
291
- # 0.3,
292
- # 0,
293
- # 0.1,
294
- # 4,
295
- # 0,
296
- # None,
297
- # ],
298
- # ]
299
 
300
- # gr.Examples(examples=footnote_examples,
301
- # label='Footnote examples',
302
- # inputs=[
303
- # text_input,
304
- # negative_prompt,
305
- # num_segments,
306
- # segment_threshold,
307
- # inject_interval,
308
- # inject_background,
309
- # seed,
310
- # color_guidance_weight,
311
- # rich_text_input,
312
- # ],
313
- # outputs=[
314
- # plaintext_result,
315
- # richtext_result,
316
- # segments,
317
- # token_map,
318
- # ],
319
- # fn=generate,
320
- # cache_examples=True,
321
- # examples_per_page=20)
322
  with gr.Row():
323
  color_examples = [
324
- # [
325
- # '{"ops":[{"insert":"a beautifule girl with big eye, skin, and long "},{"attributes":{"color":"#04a704"},"insert":"hair"},{"insert":", t-shirt, bursting with vivid color, intricate, elegant, highly detailed, photorealistic, digital painting, artstation, illustration, concept art."}]}',
326
- # 'lowres, had anatomy, bad hands, cropped, worst quality',
327
- # 11,
328
- # 0.5,
329
- # 0.3,
330
- # 0.3,
331
- # 6,
332
- # 0.5,
333
- # None,
334
- # ],
335
- # [
336
- # '{"ops":[{"insert":"a beautifule girl with big eye, skin, and long "},{"attributes":{"color":"#ff5df1"},"insert":"hair"},{"insert":", t-shirt, bursting with vivid color, intricate, elegant, highly detailed, photorealistic, digital painting, artstation, illustration, concept art."}]}',
337
- # 'lowres, had anatomy, bad hands, cropped, worst quality',
338
- # 11,
339
- # 0.5,
340
- # 0.3,
341
- # 0.3,
342
- # 6,
343
- # 0.5,
344
- # None,
345
- # ],
346
  [
347
  '{"ops":[{"insert":"a beautifule girl with big eye, skin, and long "},{"attributes":{"color":"#999999"},"insert":"hair"},{"insert":", t-shirt, bursting with vivid color, intricate, elegant, highly detailed, photorealistic, digital painting, artstation, illustration, concept art."}]}',
348
  'lowres, had anatomy, bad hands, cropped, worst quality',
@@ -389,112 +379,112 @@ def main():
389
  cache_examples=True,
390
  examples_per_page=20)
391
 
392
- # with gr.Row():
393
- # style_examples = [
394
- # [
395
- # '{"ops":[{"insert":"a beautiful"},{"attributes":{"font":"mirza"},"insert":" garden"},{"insert":" with a "},{"attributes":{"font":"roboto"},"insert":"snow mountain"},{"insert":" in the background"}]}',
396
- # '',
397
- # 10,
398
- # 0.6,
399
- # 0,
400
- # 0.4,
401
- # 5,
402
- # 0,
403
- # None,
404
- # ],
405
- # [
406
- # '{"ops":[{"insert":"a night"},{"attributes":{"font":"slabo"},"insert":" sky"},{"insert":" filled with stars above a turbulent"},{"attributes":{"font":"roboto"},"insert":" sea"},{"insert":" with giant waves"}]}',
407
- # '',
408
- # 2,
409
- # 0.6,
410
- # 0,
411
- # 0,
412
- # 6,
413
- # 0.5,
414
- # None,
415
- # ],
416
- # ]
417
- # gr.Examples(examples=style_examples,
418
- # label='Font style examples',
419
- # inputs=[
420
- # text_input,
421
- # negative_prompt,
422
- # num_segments,
423
- # segment_threshold,
424
- # inject_interval,
425
- # inject_background,
426
- # seed,
427
- # color_guidance_weight,
428
- # rich_text_input,
429
- # ],
430
- # outputs=[
431
- # plaintext_result,
432
- # richtext_result,
433
- # segments,
434
- # token_map,
435
- # ],
436
- # fn=generate,
437
- # cache_examples=True,
438
- # examples_per_page=20)
439
 
440
- # with gr.Row():
441
- # size_examples = [
442
- # [
443
- # '{"ops": [{"insert": "A pizza with "}, {"attributes": {"size": "60px"}, "insert": "pineapple"}, {"insert": " pepperoni, and mushroom on the top"}]}',
444
- # '',
445
- # 5,
446
- # 0.3,
447
- # 0,
448
- # 0,
449
- # 3,
450
- # 1,
451
- # None,
452
- # ],
453
- # [
454
- # '{"ops": [{"insert": "A pizza with pineapple, "}, {"attributes": {"size": "60px"}, "insert": "pepperoni"}, {"insert": ", and mushroom on the top"}]}',
455
- # '',
456
- # 5,
457
- # 0.3,
458
- # 0,
459
- # 0,
460
- # 3,
461
- # 1,
462
- # None,
463
- # ],
464
- # [
465
- # '{"ops": [{"insert": "A pizza with pineapple, pepperoni, and "}, {"attributes": {"size": "60px"}, "insert": "mushroom"}, {"insert": " on the top"}]}',
466
- # '',
467
- # 5,
468
- # 0.3,
469
- # 0,
470
- # 0,
471
- # 3,
472
- # 1,
473
- # None,
474
- # ],
475
- # ]
476
- # gr.Examples(examples=size_examples,
477
- # label='Font size examples',
478
- # inputs=[
479
- # text_input,
480
- # negative_prompt,
481
- # num_segments,
482
- # segment_threshold,
483
- # inject_interval,
484
- # inject_background,
485
- # seed,
486
- # color_guidance_weight,
487
- # rich_text_input,
488
- # ],
489
- # outputs=[
490
- # plaintext_result,
491
- # richtext_result,
492
- # segments,
493
- # token_map,
494
- # ],
495
- # fn=generate,
496
- # cache_examples=True,
497
- # examples_per_page=20)
498
  generate_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=share_row, queue=False).then(
499
  fn=generate,
500
  inputs=[
 
158
  with gr.Blocks(css=css) as demo:
159
  url_params = gr.JSON({}, visible=False, label="URL Params")
160
  gr.HTML("""<h1 style="font-weight: 900; margin-bottom: 7px;">Expressive Text-to-Image Generation with Rich Text</h1>
161
+ <p> <a href="https://songweige.github.io/">Songwei Ge</a>, <a href="https://taesung.me/">Taesung Park</a>, <a href="https://www.cs.cmu.edu/~junyanz/">Jun-Yan Zhu</a>, <a href="https://jbhuang0604.github.io/">Jia-Bin Huang</a> <p/>
162
  <p> UMD, Adobe, CMU <p/>
163
+ <p> ICCV, 2023 <p/>
164
  <p> <a href="https://huggingface.co/spaces/songweig/rich-text-to-image?duplicate=true"><img src="https://bit.ly/3gLdBN6" style="display:inline;"alt="Duplicate Space"></a> | <a href="https://rich-text-to-image.github.io">[Website]</a> | <a href="https://github.com/SongweiGe/rich-text-to-image">[Code]</a> | <a href="https://arxiv.org/abs/2304.06720">[Paper]</a><p/>
165
+ <p> Our method is now upgraded to use Stable Diffusion XL. For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.""")
166
  with gr.Row():
167
  with gr.Column():
168
  rich_text_el = gr.HTML(canvas_html, elem_id="canvas_html")
 
261
  with gr.Row():
262
  gr.Markdown(help_text)
263
 
264
+ with gr.Row():
265
+ footnote_examples = [
266
+ [
267
+ '{"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."}]}',
268
+ '',
269
+ 9,
270
+ 0.3,
271
+ 0.3,
272
+ 0.5,
273
+ 3,
274
+ 0,
275
+ None,
276
+ ],
277
+ [
278
+ '{"ops":[{"insert":"A cozy "},{"attributes":{"link":"A charming wooden cabin with Christmas decoration, warm light coming out from the windows."},"insert":"cabin"},{"insert":" nestled in a "},{"attributes":{"link":"Towering evergreen trees covered in a thick layer of pristine snow."},"insert":"snowy forest"},{"insert":", and a "},{"attributes":{"link":"A cute snowman wearing a carrot nose, coal eyes, and a colorful scarf, welcoming visitors with a cheerful vibe."},"insert":"snowman"},{"insert":" stands in the yard."}]}',
279
+ '',
280
+ 12,
281
+ 0.4,
282
+ 0.3,
283
+ 0.5,
284
+ 3,
285
+ 0,
286
+ None,
287
+ ],
288
+ [
289
+ '{"ops":[{"insert":"A "},{"attributes":{"link":"Happy Kung fu panda art, elder, asian art, volumetric lighting, dramatic scene, ultra detailed, realism, chinese"},"insert":"panda"},{"insert":" standing on a cliff by a waterfall, wildlife photography, photograph, high quality, wildlife, f 1.8, soft focus, 8k, national geographic, award - winning photograph by nick nichols"}]}',
290
+ '',
291
+ 5,
292
+ 0.3,
293
+ 0,
294
+ 0.1,
295
+ 4,
296
+ 0,
297
+ None,
298
+ ],
299
+ ]
300
 
301
+ gr.Examples(examples=footnote_examples,
302
+ label='Footnote examples',
303
+ inputs=[
304
+ text_input,
305
+ negative_prompt,
306
+ num_segments,
307
+ segment_threshold,
308
+ inject_interval,
309
+ inject_background,
310
+ seed,
311
+ color_guidance_weight,
312
+ rich_text_input,
313
+ ],
314
+ outputs=[
315
+ plaintext_result,
316
+ richtext_result,
317
+ segments,
318
+ token_map,
319
+ ],
320
+ fn=generate,
321
+ cache_examples=True,
322
+ examples_per_page=20)
323
  with gr.Row():
324
  color_examples = [
325
+ [
326
+ '{"ops":[{"insert":"a beautifule girl with big eye, skin, and long "},{"attributes":{"color":"#04a704"},"insert":"hair"},{"insert":", t-shirt, bursting with vivid color, intricate, elegant, highly detailed, photorealistic, digital painting, artstation, illustration, concept art."}]}',
327
+ 'lowres, had anatomy, bad hands, cropped, worst quality',
328
+ 11,
329
+ 0.5,
330
+ 0.3,
331
+ 0.3,
332
+ 6,
333
+ 0.5,
334
+ None,
335
+ ],
 
 
 
 
 
 
 
 
 
 
 
336
  [
337
  '{"ops":[{"insert":"a beautifule girl with big eye, skin, and long "},{"attributes":{"color":"#999999"},"insert":"hair"},{"insert":", t-shirt, bursting with vivid color, intricate, elegant, highly detailed, photorealistic, digital painting, artstation, illustration, concept art."}]}',
338
  'lowres, had anatomy, bad hands, cropped, worst quality',
 
379
  cache_examples=True,
380
  examples_per_page=20)
381
 
382
+ with gr.Row():
383
+ style_examples = [
384
+ [
385
+ '{"ops":[{"insert":"a beautiful"},{"attributes":{"font":"mirza"},"insert":" garden"},{"insert":" with a "},{"attributes":{"font":"roboto"},"insert":"snow mountain"},{"insert":" in the background"}]}',
386
+ '',
387
+ 10,
388
+ 0.6,
389
+ 0,
390
+ 0.4,
391
+ 5,
392
+ 0,
393
+ None,
394
+ ],
395
+ [
396
+ '{"ops":[{"insert":"a night"},{"attributes":{"font":"slabo"},"insert":" sky"},{"insert":" filled with stars above a turbulent"},{"attributes":{"font":"roboto"},"insert":" sea"},{"insert":" with giant waves"}]}',
397
+ '',
398
+ 2,
399
+ 0.6,
400
+ 0,
401
+ 0,
402
+ 6,
403
+ 0.5,
404
+ None,
405
+ ],
406
+ ]
407
+ gr.Examples(examples=style_examples,
408
+ label='Font style examples',
409
+ inputs=[
410
+ text_input,
411
+ negative_prompt,
412
+ num_segments,
413
+ segment_threshold,
414
+ inject_interval,
415
+ inject_background,
416
+ seed,
417
+ color_guidance_weight,
418
+ rich_text_input,
419
+ ],
420
+ outputs=[
421
+ plaintext_result,
422
+ richtext_result,
423
+ segments,
424
+ token_map,
425
+ ],
426
+ fn=generate,
427
+ cache_examples=True,
428
+ examples_per_page=20)
429
 
430
+ with gr.Row():
431
+ size_examples = [
432
+ [
433
+ '{"ops": [{"insert": "A pizza with "}, {"attributes": {"size": "60px"}, "insert": "pineapple"}, {"insert": " pepperoni, and mushroom on the top"}]}',
434
+ '',
435
+ 5,
436
+ 0.3,
437
+ 0,
438
+ 0,
439
+ 3,
440
+ 1,
441
+ None,
442
+ ],
443
+ [
444
+ '{"ops": [{"insert": "A pizza with pineapple, "}, {"attributes": {"size": "60px"}, "insert": "pepperoni"}, {"insert": ", and mushroom on the top"}]}',
445
+ '',
446
+ 5,
447
+ 0.3,
448
+ 0,
449
+ 0,
450
+ 3,
451
+ 1,
452
+ None,
453
+ ],
454
+ [
455
+ '{"ops": [{"insert": "A pizza with pineapple, pepperoni, and "}, {"attributes": {"size": "60px"}, "insert": "mushroom"}, {"insert": " on the top"}]}',
456
+ '',
457
+ 5,
458
+ 0.3,
459
+ 0,
460
+ 0,
461
+ 3,
462
+ 1,
463
+ None,
464
+ ],
465
+ ]
466
+ gr.Examples(examples=size_examples,
467
+ label='Font size examples',
468
+ inputs=[
469
+ text_input,
470
+ negative_prompt,
471
+ num_segments,
472
+ segment_threshold,
473
+ inject_interval,
474
+ inject_background,
475
+ seed,
476
+ color_guidance_weight,
477
+ rich_text_input,
478
+ ],
479
+ outputs=[
480
+ plaintext_result,
481
+ richtext_result,
482
+ segments,
483
+ token_map,
484
+ ],
485
+ fn=generate,
486
+ cache_examples=True,
487
+ examples_per_page=20)
488
  generate_button.click(fn=lambda: gr.update(visible=False), inputs=None, outputs=share_row, queue=False).then(
489
  fn=generate,
490
  inputs=[