QHL067 commited on
Commit
9666147
·
1 Parent(s): 9b01db5
Files changed (1) hide show
  1. app.py +79 -3
app.py CHANGED
@@ -282,9 +282,9 @@ with gr.Blocks(css=css) as demo:
282
  with gr.Column(elem_id="col-container"):
283
  gr.Markdown("# CrossFlow")
284
  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.")
 
285
  with gr.Tabs():
286
- with gr.Tab("Linear interpolation"):
287
- gr.Markdown("This allows interpolation in the input text latent space, as demonstrated here.")
288
  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.)")
289
  # gr.Markdown("CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
290
 
@@ -354,7 +354,83 @@ with gr.Blocks(css=css) as demo:
354
 
355
  with gr.Tab("Arithmetic Operations"):
356
  # The second tab is currently empty. You can add more components later.
357
- gr.Markdown("This tab is intentionally left empty.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
 
359
  gr.on(
360
  triggers=[run_button.click, prompt1.submit, prompt2.submit],
 
282
  with gr.Column(elem_id="col-container"):
283
  gr.Markdown("# CrossFlow")
284
  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.")
285
+ gr.Markdown("This direct mapping enables meaningful 'Linear Interpolation' and 'Arithmetic Operations' in the text latent space, as demonstrated here.")
286
  with gr.Tabs():
287
+ with gr.Tab("Linear Interpolation"):
 
288
  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.)")
289
  # gr.Markdown("CrossFlow directly transforms text representations into images for text-to-image generation, enabling interpolation in the input text latent space.")
290
 
 
354
 
355
  with gr.Tab("Arithmetic Operations"):
356
  # The second tab is currently empty. You can add more components later.
357
+ 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).")
358
+ with gr.Row():
359
+ prompt1 = gr.Text(
360
+ label="Prompt_1",
361
+ show_label=False,
362
+ max_lines=1,
363
+ placeholder="Enter your prompt for the first image",
364
+ container=False,
365
+ )
366
+
367
+ with gr.Row():
368
+ prompt2 = gr.Text(
369
+ label="Prompt_2",
370
+ show_label=False,
371
+ max_lines=1,
372
+ placeholder="Enter your prompt for the second image",
373
+ container=False,
374
+ )
375
+
376
+ with gr.Row():
377
+ operation_mode = gr.Radio(
378
+ choices=["Addition", "Subtraction"],
379
+ label="Operation Mode",
380
+ value="Addition",
381
+ )
382
+ with gr.Row():
383
+ run_button = gr.Button("Run", scale=0, variant="primary")
384
+
385
+ # Create separate outputs for the first image, last image, and the animated GIF
386
+ first_image_output = gr.Image(label="Image of the first prompt", show_label=True)
387
+ last_image_output = gr.Image(label="Image of the second prompt", show_label=True)
388
+ gif_output = gr.Image(label="Linear interpolation", show_label=True)
389
+
390
+ with gr.Accordion("Advanced Settings", open=False):
391
+ seed = gr.Slider(
392
+ label="Seed",
393
+ minimum=0,
394
+ maximum=MAX_SEED,
395
+ step=1,
396
+ value=0,
397
+ )
398
+
399
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
400
+
401
+ with gr.Row():
402
+ guidance_scale = gr.Slider(
403
+ label="Guidance scale",
404
+ minimum=0.0,
405
+ maximum=10.0,
406
+ step=0.1,
407
+ value=7.0, # Replace with defaults that work for your model
408
+ )
409
+ # with gr.Row():
410
+ # num_inference_steps = gr.Slider(
411
+ # label="Number of inference steps - 50 inference steps are recommended; but you can reduce to 20 if the demo fails.",
412
+ # minimum=1,
413
+ # maximum=50,
414
+ # step=1,
415
+ # value=55, # Replace with defaults that work for your model
416
+ # )
417
+ if operation_mode == "Addition":
418
+ num_inference_steps = -1
419
+ elif operation_mode == "Subtraction":
420
+ num_inference_steps = -2
421
+ else:
422
+ num_inference_steps = 0
423
+
424
+ with gr.Row():
425
+ num_of_interpolation = gr.Slider(
426
+ label="Number of images for interpolation - More images yield smoother transitions but require more resources and may fail.",
427
+ minimum=5,
428
+ maximum=50,
429
+ step=1,
430
+ value=50, # Replace with defaults that work for your model
431
+ )
432
+
433
+ gr.Examples(examples=examples, inputs=[prompt1, prompt2])
434
 
435
  gr.on(
436
  triggers=[run_button.click, prompt1.submit, prompt2.submit],