QHL067 commited on
Commit
035c9fd
·
1 Parent(s): 0f7795f
Files changed (1) hide show
  1. app.py +170 -168
app.py CHANGED
@@ -287,175 +287,178 @@ css = """
287
  max-width: 640px;
288
  }
289
  """
290
- with gr.Blocks(css=css) as demo:
291
- with gr.Column(elem_id="col-container"):
292
- gr.Markdown("# CrossFlow")
293
- gr.Markdown("[CrossFlow](https://cross-flow.github.io/) directly transforms text representations into images for text-to-image generation, without the need for both the noise distribution and conditioning mechanism.")
294
- gr.Markdown("This direct mapping enables meaningful 'Linear Interpolation' and 'Arithmetic Operations' in the text latent space, as demonstrated here.")
295
- # with gr.Tabs():
296
- # with gr.Tab("Linear Interpolation"):
297
- # gr.Markdown("This demo uses 256px images, 25 sampling steps (instead of 50), and 10 interpolations (instead of 50) to conserve GPU memory. For better results, see the original [code](https://github.com/qihao067/CrossFlow). (You may adjust them in Advanced Settings, but doing so may trigger OOM errors.)")
298
- # # gr.Markdown("CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
299
-
300
- # with gr.Row():
301
- # prompt1 = gr.Text(
302
- # label="Prompt_1",
303
- # show_label=False,
304
- # max_lines=1,
305
- # placeholder="Enter your prompt for the first image",
306
- # container=False,
307
- # )
308
 
309
- # with gr.Row():
310
- # prompt2 = gr.Text(
311
- # label="Prompt_2",
312
- # show_label=False,
313
- # max_lines=1,
314
- # placeholder="Enter your prompt for the second image",
315
- # container=False,
316
- # )
317
-
318
- # with gr.Row():
319
- # run_button = gr.Button("Run", scale=0, variant="primary")
320
-
321
- # # Create separate outputs for the first image, last image, and the animated GIF
322
- # first_image_output = gr.Image(label="Image of the first prompt", show_label=True)
323
- # last_image_output = gr.Image(label="Image of the second prompt", show_label=True)
324
- # gif_output = gr.Image(label="Linear interpolation", show_label=True)
325
-
326
- # with gr.Accordion("Advanced Settings", open=False):
327
- # seed = gr.Slider(
328
- # label="Seed",
329
- # minimum=0,
330
- # maximum=MAX_SEED,
331
- # step=1,
332
- # value=0,
333
- # )
334
-
335
- # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
336
-
337
- # with gr.Row():
338
- # guidance_scale = gr.Slider(
339
- # label="Guidance scale",
340
- # minimum=0.0,
341
- # maximum=10.0,
342
- # step=0.1,
343
- # value=7.0, # Replace with defaults that work for your model
344
- # )
345
- # with gr.Row():
346
- # num_inference_steps = gr.Slider(
347
- # label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
348
- # minimum=1,
349
- # maximum=50,
350
- # step=1,
351
- # value=25, # Replace with defaults that work for your model
352
- # )
353
- # with gr.Row():
354
- # num_of_interpolation = gr.Slider(
355
- # label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
356
- # minimum=5,
357
- # maximum=50,
358
- # step=1,
359
- # value=10, # Replace with defaults that work for your model
360
- # )
361
-
362
- # gr.Examples(examples=examples, inputs=[prompt1, prompt2])
363
-
364
- # with gr.Tab("Arithmetic Operations"):
365
- # # The second tab is currently empty. You can add more components later.
366
- # gr.Markdown("This demo only supports addition or subtraction between two text latents ('Prompt_1 + Prompt_2' or 'Prompt_1 - Prompt_2'). For the other arithmetic operations, see the original [code](https://github.com/qihao067/CrossFlow).")
367
- # with gr.Row():
368
- # prompt1 = gr.Text(
369
- # label="Prompt_1",
370
- # show_label=False,
371
- # max_lines=1,
372
- # placeholder="Enter your prompt for the first image",
373
- # container=False,
374
- # )
375
 
376
- # with gr.Row():
377
- # prompt2 = gr.Text(
378
- # label="Prompt_2",
379
- # show_label=False,
380
- # max_lines=1,
381
- # placeholder="Enter your prompt for the second image",
382
- # container=False,
383
- # )
384
-
385
- # with gr.Row():
386
- # operation_mode = gr.Radio(
387
- # choices=["Addition", "Subtraction"],
388
- # label="Operation Mode",
389
- # value="Addition",
390
- # )
391
- # with gr.Row():
392
- # run_button = gr.Button("Run", scale=0, variant="primary")
393
-
394
- # # Create separate outputs for the first image, last image, and the animated GIF
395
- # first_image_output = gr.Image(label="Image of the first prompt", show_label=True)
396
- # last_image_output = gr.Image(label="Image of the second prompt", show_label=True)
397
- # gif_output = gr.Image(label="Linear interpolation", show_label=True)
398
-
399
- # with gr.Accordion("Advanced Settings", open=False):
400
- # seed = gr.Slider(
401
- # label="Seed",
402
- # minimum=0,
403
- # maximum=MAX_SEED,
404
- # step=1,
405
- # value=0,
406
- # )
407
-
408
- # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
409
-
410
- # with gr.Row():
411
- # guidance_scale = gr.Slider(
412
- # label="Guidance scale",
413
- # minimum=0.0,
414
- # maximum=10.0,
415
- # step=0.1,
416
- # value=7.0, # Replace with defaults that work for your model
417
- # )
418
- # # with gr.Row():
419
- # # num_inference_steps = gr.Slider(
420
- # # label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
421
- # # minimum=1,
422
- # # maximum=50,
423
- # # step=1,
424
- # # value=55, # Replace with defaults that work for your model
425
- # # )
426
-
427
- # with gr.Row():
428
- # num_of_interpolation = gr.Slider(
429
- # label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
430
- # minimum=5,
431
- # maximum=50,
432
- # step=1,
433
- # value=50, # Replace with defaults that work for your model
434
- # )
435
-
436
- # gr.Examples(examples=examples, inputs=[prompt1, prompt2])
437
-
438
- # gr.on(
439
- # triggers=[run_button.click, prompt1.submit, prompt2.submit],
440
- # fn=infer,
441
- # inputs=[
442
- # prompt1,
443
- # prompt2,
444
- # seed,
445
- # randomize_seed,
446
- # guidance_scale,
447
- # num_inference_steps,
448
- # num_of_interpolation,
449
- # ],
450
- # outputs=[first_image_output, last_image_output, gif_output, seed],
451
- # # outputs=[first_image_output, last_image_output, seed],
452
- # )
453
 
454
  with gr.Blocks(css=css) as demo:
455
  with gr.Tabs():
456
  # --- Tab 1: Interpolation Mode (no operation_mode) ---
457
- with gr.Tab("Tab 1: Interpolation Mode"):
458
- gr.Markdown("**Tab 1:** This tab uses a slider for the number of interpolated images. The operation mode is fixed to *Addition* by default.")
 
 
 
459
 
460
  prompt1_tab1 = gr.Text(placeholder="Prompt for first image", label="Prompt 1")
461
  prompt2_tab1 = gr.Text(placeholder="Prompt for second image", label="Prompt 2")
@@ -485,21 +488,21 @@ with gr.Blocks(css=css) as demo:
485
  )
486
 
487
  # --- Tab 2: Operation Mode (no num_of_interpolation) ---
488
- with gr.Tab("Tab 2: Operation Mode"):
489
- gr.Markdown("**Tab 2:** This tab lets you choose the operation mode (Addition or Subtraction) while fixing the number of interpolations to 3.")
490
 
491
  prompt1_tab2 = gr.Text(placeholder="Prompt for first image", label="Prompt 1")
492
  prompt2_tab2 = gr.Text(placeholder="Prompt for second image", label="Prompt 2")
493
  seed_tab2 = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0, label="Seed")
494
  randomize_seed_tab2 = gr.Checkbox(label="Randomize seed", value=True)
495
  guidance_scale_tab2 = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=7.0, label="Guidance Scale")
496
- num_inference_steps_tab2 = gr.Slider(minimum=1, maximum=50, step=1, value=25, label="Number of Inference Steps")
497
  operation_mode_tab2 = gr.Radio(choices=["Addition", "Subtraction"], label="Operation Mode", value="Addition")
498
  run_button_tab2 = gr.Button("Run")
499
 
500
  first_image_output_tab2 = gr.Image(label="Image of the first prompt")
501
  last_image_output_tab2 = gr.Image(label="Image of the second prompt")
502
- gif_output_tab2 = gr.Image(label="Linear interpolation")
503
 
504
  run_button_tab2.click(
505
  fn=infer_tab2,
@@ -516,6 +519,5 @@ with gr.Blocks(css=css) as demo:
516
  )
517
 
518
 
519
-
520
  if __name__ == "__main__":
521
  demo.launch()
 
287
  max-width: 640px;
288
  }
289
  """
290
+ # with gr.Blocks(css=css) as demo:
291
+ # with gr.Column(elem_id="col-container"):
292
+ # gr.Markdown("# CrossFlow")
293
+ # gr.Markdown("[CrossFlow](https://cross-flow.github.io/) directly transforms text representations into images for text-to-image generation, without the need for both the noise distribution and conditioning mechanism.")
294
+ # gr.Markdown("This direct mapping enables meaningful 'Linear Interpolation' and 'Arithmetic Operations' in the text latent space, as demonstrated here.")
295
+ # with gr.Tabs():
296
+ # with gr.Tab("Linear Interpolation"):
297
+ # gr.Markdown("This demo uses 256px images, 25 sampling steps (instead of 50), and 10 interpolations (instead of 50) to conserve GPU memory. For better results, see the original [code](https://github.com/qihao067/CrossFlow). (You may adjust them in Advanced Settings, but doing so may trigger OOM errors.)")
298
+ # # gr.Markdown("CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
299
+
300
+ # with gr.Row():
301
+ # prompt1 = gr.Text(
302
+ # label="Prompt_1",
303
+ # show_label=False,
304
+ # max_lines=1,
305
+ # placeholder="Enter your prompt for the first image",
306
+ # container=False,
307
+ # )
308
 
309
+ # with gr.Row():
310
+ # prompt2 = gr.Text(
311
+ # label="Prompt_2",
312
+ # show_label=False,
313
+ # max_lines=1,
314
+ # placeholder="Enter your prompt for the second image",
315
+ # container=False,
316
+ # )
317
+
318
+ # with gr.Row():
319
+ # run_button = gr.Button("Run", scale=0, variant="primary")
320
+
321
+ # # Create separate outputs for the first image, last image, and the animated GIF
322
+ # first_image_output = gr.Image(label="Image of the first prompt", show_label=True)
323
+ # last_image_output = gr.Image(label="Image of the second prompt", show_label=True)
324
+ # gif_output = gr.Image(label="Linear interpolation", show_label=True)
325
+
326
+ # with gr.Accordion("Advanced Settings", open=False):
327
+ # seed = gr.Slider(
328
+ # label="Seed",
329
+ # minimum=0,
330
+ # maximum=MAX_SEED,
331
+ # step=1,
332
+ # value=0,
333
+ # )
334
+
335
+ # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
336
+
337
+ # with gr.Row():
338
+ # guidance_scale = gr.Slider(
339
+ # label="Guidance scale",
340
+ # minimum=0.0,
341
+ # maximum=10.0,
342
+ # step=0.1,
343
+ # value=7.0, # Replace with defaults that work for your model
344
+ # )
345
+ # with gr.Row():
346
+ # num_inference_steps = gr.Slider(
347
+ # label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
348
+ # minimum=1,
349
+ # maximum=50,
350
+ # step=1,
351
+ # value=25, # Replace with defaults that work for your model
352
+ # )
353
+ # with gr.Row():
354
+ # num_of_interpolation = gr.Slider(
355
+ # label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
356
+ # minimum=5,
357
+ # maximum=50,
358
+ # step=1,
359
+ # value=10, # Replace with defaults that work for your model
360
+ # )
361
+
362
+ # gr.Examples(examples=examples, inputs=[prompt1, prompt2])
363
+
364
+ # with gr.Tab("Arithmetic Operations"):
365
+ # # The second tab is currently empty. You can add more components later.
366
+ # gr.Markdown("This demo only supports addition or subtraction between two text latents ('Prompt_1 + Prompt_2' or 'Prompt_1 - Prompt_2'). For the other arithmetic operations, see the original [code](https://github.com/qihao067/CrossFlow).")
367
+ # with gr.Row():
368
+ # prompt1 = gr.Text(
369
+ # label="Prompt_1",
370
+ # show_label=False,
371
+ # max_lines=1,
372
+ # placeholder="Enter your prompt for the first image",
373
+ # container=False,
374
+ # )
375
 
376
+ # with gr.Row():
377
+ # prompt2 = gr.Text(
378
+ # label="Prompt_2",
379
+ # show_label=False,
380
+ # max_lines=1,
381
+ # placeholder="Enter your prompt for the second image",
382
+ # container=False,
383
+ # )
384
+
385
+ # with gr.Row():
386
+ # operation_mode = gr.Radio(
387
+ # choices=["Addition", "Subtraction"],
388
+ # label="Operation Mode",
389
+ # value="Addition",
390
+ # )
391
+ # with gr.Row():
392
+ # run_button = gr.Button("Run", scale=0, variant="primary")
393
+
394
+ # # Create separate outputs for the first image, last image, and the animated GIF
395
+ # first_image_output = gr.Image(label="Image of the first prompt", show_label=True)
396
+ # last_image_output = gr.Image(label="Image of the second prompt", show_label=True)
397
+ # gif_output = gr.Image(label="Linear interpolation", show_label=True)
398
+
399
+ # with gr.Accordion("Advanced Settings", open=False):
400
+ # seed = gr.Slider(
401
+ # label="Seed",
402
+ # minimum=0,
403
+ # maximum=MAX_SEED,
404
+ # step=1,
405
+ # value=0,
406
+ # )
407
+
408
+ # randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
409
+
410
+ # with gr.Row():
411
+ # guidance_scale = gr.Slider(
412
+ # label="Guidance scale",
413
+ # minimum=0.0,
414
+ # maximum=10.0,
415
+ # step=0.1,
416
+ # value=7.0, # Replace with defaults that work for your model
417
+ # )
418
+ # # with gr.Row():
419
+ # # num_inference_steps = gr.Slider(
420
+ # # label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
421
+ # # minimum=1,
422
+ # # maximum=50,
423
+ # # step=1,
424
+ # # value=55, # Replace with defaults that work for your model
425
+ # # )
426
+
427
+ # with gr.Row():
428
+ # num_of_interpolation = gr.Slider(
429
+ # label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
430
+ # minimum=5,
431
+ # maximum=50,
432
+ # step=1,
433
+ # value=50, # Replace with defaults that work for your model
434
+ # )
435
+
436
+ # gr.Examples(examples=examples, inputs=[prompt1, prompt2])
437
+
438
+ # gr.on(
439
+ # triggers=[run_button.click, prompt1.submit, prompt2.submit],
440
+ # fn=infer,
441
+ # inputs=[
442
+ # prompt1,
443
+ # prompt2,
444
+ # seed,
445
+ # randomize_seed,
446
+ # guidance_scale,
447
+ # num_inference_steps,
448
+ # num_of_interpolation,
449
+ # ],
450
+ # outputs=[first_image_output, last_image_output, gif_output, seed],
451
+ # # outputs=[first_image_output, last_image_output, seed],
452
+ # )
453
 
454
  with gr.Blocks(css=css) as demo:
455
  with gr.Tabs():
456
  # --- Tab 1: Interpolation Mode (no operation_mode) ---
457
+ gr.Markdown("# CrossFlow")
458
+ gr.Markdown("[CrossFlow](https://cross-flow.github.io/) directly transforms text representations into images for text-to-image generation, without the need for both the noise distribution and conditioning mechanism.")
459
+ gr.Markdown("This direct mapping enables meaningful 'Linear Interpolation' and 'Arithmetic Operations' in the text latent space, as demonstrated here.")
460
+ with gr.Tab("## Linear Interpolation"):
461
+ gr.Markdown("This demo uses 256px images, 25 sampling steps (instead of 50), and 10 interpolations (instead of 50) to conserve GPU memory. For better results, see the original [code](https://github.com/qihao067/CrossFlow). (You may adjust them in Advanced Settings, but doing so may trigger OOM errors.)")
462
 
463
  prompt1_tab1 = gr.Text(placeholder="Prompt for first image", label="Prompt 1")
464
  prompt2_tab1 = gr.Text(placeholder="Prompt for second image", label="Prompt 2")
 
488
  )
489
 
490
  # --- Tab 2: Operation Mode (no num_of_interpolation) ---
491
+ with gr.Tab("## Arithmetic Operations"):
492
+ gr.Markdown("This demo only supports addition or subtraction between two text latents ('Prompt_1 + Prompt_2' or 'Prompt_1 - Prompt_2'). For the other arithmetic operations, see the original [code](https://github.com/qihao067/CrossFlow).")
493
 
494
  prompt1_tab2 = gr.Text(placeholder="Prompt for first image", label="Prompt 1")
495
  prompt2_tab2 = gr.Text(placeholder="Prompt for second image", label="Prompt 2")
496
  seed_tab2 = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0, label="Seed")
497
  randomize_seed_tab2 = gr.Checkbox(label="Randomize seed", value=True)
498
  guidance_scale_tab2 = gr.Slider(minimum=0.0, maximum=10.0, step=0.1, value=7.0, label="Guidance Scale")
499
+ num_inference_steps_tab2 = gr.Slider(minimum=1, maximum=50, step=1, value=50, label="Number of Inference Steps")
500
  operation_mode_tab2 = gr.Radio(choices=["Addition", "Subtraction"], label="Operation Mode", value="Addition")
501
  run_button_tab2 = gr.Button("Run")
502
 
503
  first_image_output_tab2 = gr.Image(label="Image of the first prompt")
504
  last_image_output_tab2 = gr.Image(label="Image of the second prompt")
505
+ gif_output_tab2 = gr.Image(label="Resulting image produced by the arithmetic operations.")
506
 
507
  run_button_tab2.click(
508
  fn=infer_tab2,
 
519
  )
520
 
521
 
 
522
  if __name__ == "__main__":
523
  demo.launch()