Shitao commited on
Commit
d8e8827
1 Parent(s): 6aff343

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import gradio as gr
2
  from PIL import Image
3
  import os
 
4
 
5
  import spaces
6
 
@@ -12,12 +13,15 @@ pipe = OmniGenPipeline.from_pretrained(
12
 
13
  @spaces.GPU(duration=160)
14
  def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
15
- use_input_image_size_as_output, max_input_image_size):
16
  input_images = [img1, img2, img3]
17
  # Delete None
18
  input_images = [img for img in input_images if img is not None]
19
  if len(input_images) == 0:
20
  input_images = None
 
 
 
21
 
22
  output = pipe(
23
  prompt=text,
@@ -270,9 +274,9 @@ def get_example():
270
  return case
271
 
272
  def run_for_examples(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
273
- use_input_image_size_as_output, max_input_image_size):
274
  return generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
275
- use_input_image_size_as_output, max_input_image_size)
276
 
277
  description = """
278
  OmniGen is a unified image generation model that you can use to perform various tasks, including but not limited to text-to-image generation, subject-driven generation, Identity-Preserving Generation, and image-conditioned generation.
@@ -281,11 +285,11 @@ For example, use an image of a woman to generate a new image:
281
  prompt = "A woman holds a bouquet of flowers and faces the camera. Thw woman is \<img\>\<|image_1|\>\</img\>."
282
 
283
  Tips:
284
- - For out of memory or time cost, you can refer to [inference.md#requiremented-resources](https://github.com/VectorSpaceLab/OmniGen/blob/main/docs/inference.md#requiremented-resources) to select a appropriate setting.
285
- - If time cost is too long, please try to reduce the `max_input_image_size`. More details please refer to [inference.md](https://github.com/VectorSpaceLab/OmniGen/blob/main/docs/inference.md#requiremented-resources)
286
  - Oversaturated: If the image appears oversaturated, please reduce the `guidance_scale`.
287
  - Not match the prompt: If the image does not match the prompt, please try to increase the `guidance_scale`.
288
- - Low-quality: More detailed prompt will lead to better results.
289
  - Animate Style: If the genereate images is in animate style, you can try to add `photo` to the prompt`.
290
  - Edit generated image. If you generate a image by omnigen and then want to edit it, you cannot use the same seed to edit this image. For example, use seed=0 to generate image, and should use seed=1 to edit this image.
291
  - For image editing tasks, we recommend placing the image before the editing instruction. For example, use `<img><|image_1|></img> remove suit`, rather than `remove suit <img><|image_1|></img>`.
@@ -353,6 +357,7 @@ with gr.Blocks() as demo:
353
  seed_input = gr.Slider(
354
  label="Seed", minimum=0, maximum=2147483647, value=42, step=1
355
  )
 
356
 
357
  max_input_image_size = gr.Slider(
358
  label="max_input_image_size", minimum=128, maximum=2048, value=1024, step=16
@@ -362,10 +367,10 @@ with gr.Blocks() as demo:
362
  label="separate_cfg_infer", info="Whether to use separate inference process for different guidance. This will reduce the memory cost.", value=True,
363
  )
364
  offload_model = gr.Checkbox(
365
- label="offload_model", info="Offload model to CPU, which will significantly reduce the memory cost but slow down the generation speed. You can cancle separate_cfg_infer and set offload_model=True. If both separate_cfg_infer and offload_model be True, further reduce the memory, but slowest generation", value=False,
366
  )
367
  use_input_image_size_as_output = gr.Checkbox(
368
- label="use_input_image_size_as_output", info="Automatically adjust the output image size to be same as input image size. For editing and controlnet task, it can make sure the output image has the same size with input image leading to better performance", value=False,
369
  )
370
 
371
  # generate
@@ -394,6 +399,7 @@ with gr.Blocks() as demo:
394
  offload_model,
395
  use_input_image_size_as_output,
396
  max_input_image_size,
 
397
  ],
398
  outputs=output_image,
399
  )
@@ -423,4 +429,4 @@ with gr.Blocks() as demo:
423
  gr.Markdown(article)
424
 
425
  # launch
426
- demo.launch()
 
1
  import gradio as gr
2
  from PIL import Image
3
  import os
4
+ import random
5
 
6
  import spaces
7
 
 
13
 
14
  @spaces.GPU(duration=160)
15
  def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
16
+ use_input_image_size_as_output, max_input_image_size, randomize_seed):
17
  input_images = [img1, img2, img3]
18
  # Delete None
19
  input_images = [img for img in input_images if img is not None]
20
  if len(input_images) == 0:
21
  input_images = None
22
+
23
+ if randomize_seed:
24
+ seed = random.randint(0, 10000000)
25
 
26
  output = pipe(
27
  prompt=text,
 
274
  return case
275
 
276
  def run_for_examples(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
277
+ use_input_image_size_as_output, max_input_image_size, randomize_seed=False):
278
  return generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer, offload_model,
279
+ use_input_image_size_as_output, max_input_image_size, randomize_seed=randomize_seed)
280
 
281
  description = """
282
  OmniGen is a unified image generation model that you can use to perform various tasks, including but not limited to text-to-image generation, subject-driven generation, Identity-Preserving Generation, and image-conditioned generation.
 
285
  prompt = "A woman holds a bouquet of flowers and faces the camera. Thw woman is \<img\>\<|image_1|\>\</img\>."
286
 
287
  Tips:
288
+ - For out-of-memory or time cost, you can set `offload_model=True` or refer to [./docs/inference.md#requiremented-resources](https://github.com/VectorSpaceLab/OmniGen/blob/main/docs/inference.md#requiremented-resources) to select a appropriate setting.
289
+ - If inference time is too long when inputting multiple images, please try to reduce the `max_input_image_size`. For more details please refer to [./docs/inference.md#requiremented-resources](https://github.com/VectorSpaceLab/OmniGen/blob/main/docs/inference.md#requiremented-resources).
290
  - Oversaturated: If the image appears oversaturated, please reduce the `guidance_scale`.
291
  - Not match the prompt: If the image does not match the prompt, please try to increase the `guidance_scale`.
292
+ - Low-quality: More detailed prompts will lead to better results.
293
  - Animate Style: If the genereate images is in animate style, you can try to add `photo` to the prompt`.
294
  - Edit generated image. If you generate a image by omnigen and then want to edit it, you cannot use the same seed to edit this image. For example, use seed=0 to generate image, and should use seed=1 to edit this image.
295
  - For image editing tasks, we recommend placing the image before the editing instruction. For example, use `<img><|image_1|></img> remove suit`, rather than `remove suit <img><|image_1|></img>`.
 
357
  seed_input = gr.Slider(
358
  label="Seed", minimum=0, maximum=2147483647, value=42, step=1
359
  )
360
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
361
 
362
  max_input_image_size = gr.Slider(
363
  label="max_input_image_size", minimum=128, maximum=2048, value=1024, step=16
 
367
  label="separate_cfg_infer", info="Whether to use separate inference process for different guidance. This will reduce the memory cost.", value=True,
368
  )
369
  offload_model = gr.Checkbox(
370
+ label="offload_model", info="Offload model to CPU, which will significantly reduce the memory cost but slow down the generation speed. You can cancel separate_cfg_infer and set offload_model=True. If both separate_cfg_infer and offload_model are True, further reduce the memory, but slowest generation", value=False,
371
  )
372
  use_input_image_size_as_output = gr.Checkbox(
373
+ label="use_input_image_size_as_output", info="Automatically adjust the output image size to be same as input image size. For editing and controlnet task, it can make sure the output image has the same size as input image leading to better performance", value=False,
374
  )
375
 
376
  # generate
 
399
  offload_model,
400
  use_input_image_size_as_output,
401
  max_input_image_size,
402
+ randomize_seed,
403
  ],
404
  outputs=output_image,
405
  )
 
429
  gr.Markdown(article)
430
 
431
  # launch
432
+ demo.launch()