TaiYouWeb commited on
Commit
d32a354
1 Parent(s): 4bb3ac6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +128 -377
app.py CHANGED
@@ -1,288 +1,92 @@
 
 
 
 
 
 
1
  import gradio as gr
2
  from PIL import Image
3
  import os
 
4
 
5
- import spaces
 
 
6
 
7
  from OmniGen import OmniGenPipeline
8
 
9
- pipe = OmniGenPipeline.from_pretrained(
10
- "Shitao/OmniGen-v1"
11
- )
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,
24
- input_images=input_images,
25
- height=height,
26
- width=width,
27
- guidance_scale=guidance_scale,
28
- img_guidance_scale=img_guidance_scale,
29
- num_inference_steps=inference_steps,
30
- separate_cfg_infer=separate_cfg_infer,
31
- use_kv_cache=True,
32
- offload_kv_cache=True,
33
- offload_model=offload_model,
34
- use_input_image_size_as_output=use_input_image_size_as_output,
35
- seed=seed,
36
- max_input_image_size=max_input_image_size,
37
- )
38
- img = output[0]
39
- return img
40
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
 
43
- def get_example():
44
- case = [
45
- [
46
- "A curly-haired man in a red shirt is drinking tea.",
47
- None,
48
- None,
49
- None,
50
- 1024,
51
- 1024,
52
- 2.5,
53
- 1.6,
54
- 50,
55
- 0,
56
- True,
57
- False,
58
- False,
59
- 1024,
60
- ],
61
- [
62
- "The woman in <img><|image_1|></img> waves her hand happily in the crowd",
63
- "./imgs/test_cases/zhang.png",
64
- None,
65
- None,
66
- 1024,
67
- 1024,
68
- 2.5,
69
- 1.9,
70
- 50,
71
- 128,
72
- True,
73
- False,
74
- False,
75
- 1024,
76
- ],
77
- [
78
- "A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
79
- "./imgs/test_cases/two_man.jpg",
80
- None,
81
- None,
82
- 1024,
83
- 1024,
84
- 2.5,
85
- 1.6,
86
- 50,
87
- 0,
88
- True,
89
- False,
90
- False,
91
- 1024,
92
- ],
93
- [
94
- "Two woman are raising fried chicken legs in a bar. A woman is <img><|image_1|></img>. The other woman is <img><|image_2|></img>.",
95
- "./imgs/test_cases/mckenna.jpg",
96
- "./imgs/test_cases/Amanda.jpg",
97
- None,
98
- 1024,
99
- 1024,
100
- 2.5,
101
- 1.8,
102
- 50,
103
- 168,
104
- True,
105
- False,
106
- False,
107
- 768,
108
- ],
109
- [
110
- "A man and a short-haired woman with a wrinkled face are standing in front of a bookshelf in a library. The man is the man in the middle of <img><|image_1|></img>, and the woman is oldest woman in <img><|image_2|></img>",
111
- "./imgs/test_cases/1.jpg",
112
- "./imgs/test_cases/2.jpg",
113
- None,
114
- 1024,
115
- 1024,
116
- 2.5,
117
- 1.6,
118
- 50,
119
- 60,
120
- True,
121
- False,
122
- False,
123
- 768,
124
- ],
125
- [
126
- "A man and a woman are sitting at a classroom desk. The man is the man with yellow hair in <img><|image_1|></img>. The woman is the woman on the left of <img><|image_2|></img>",
127
- "./imgs/test_cases/3.jpg",
128
- "./imgs/test_cases/4.jpg",
129
- None,
130
- 1024,
131
- 1024,
132
- 2.5,
133
- 1.8,
134
- 50,
135
- 66,
136
- True,
137
- False,
138
- False,
139
- 768,
140
- ],
141
- [
142
- "The flower <img><|image_1|><\/img> is placed in the vase which is in the middle of <img><|image_2|><\/img> on a wooden table of a living room",
143
- "./imgs/test_cases/rose.jpg",
144
- "./imgs/test_cases/vase.jpg",
145
- None,
146
- 1024,
147
- 1024,
148
- 2.5,
149
- 1.6,
150
- 50,
151
- 0,
152
- True,
153
- False,
154
- False,
155
- 768,
156
- ],
157
- [
158
- "<img><|image_1|><img>\n Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola.",
159
- "./imgs/demo_cases/t2i_woman_with_book.png",
160
- None,
161
- None,
162
- None,
163
- None,
164
- 2.5,
165
- 1.6,
166
- 50,
167
- 222,
168
- True,
169
- False,
170
- True,
171
- 1024,
172
- ],
173
- [
174
- "Detect the skeleton of human in this image: <img><|image_1|></img>.",
175
- "./imgs/test_cases/control.jpg",
176
- None,
177
- None,
178
- None,
179
- None,
180
- 2.0,
181
- 1.6,
182
- 50,
183
- 0,
184
- True,
185
- False,
186
- True,
187
- 1024,
188
- ],
189
- [
190
- "Generate a new photo using the following picture and text as conditions: <img><|image_1|><img>\n A young boy is sitting on a sofa in the library, holding a book. His hair is neatly combed, and a faint smile plays on his lips, with a few freckles scattered across his cheeks. The library is quiet, with rows of shelves filled with books stretching out behind him.",
191
- "./imgs/demo_cases/skeletal.png",
192
- None,
193
- None,
194
- None,
195
- None,
196
- 2,
197
- 1.6,
198
- 50,
199
- 42,
200
- True,
201
- False,
202
- True,
203
- 1024,
204
- ],
205
- [
206
- "Following the pose of this image <img><|image_1|><img>, generate a new photo: A young boy is sitting on a sofa in the library, holding a book. His hair is neatly combed, and a faint smile plays on his lips, with a few freckles scattered across his cheeks. The library is quiet, with rows of shelves filled with books stretching out behind him.",
207
- "./imgs/demo_cases/edit.png",
208
- None,
209
- None,
210
- None,
211
- None,
212
- 2.0,
213
- 1.6,
214
- 50,
215
- 123,
216
- True,
217
- False,
218
- True,
219
- 1024,
220
- ],
221
- [
222
- "Following the depth mapping of this image <img><|image_1|><img>, generate a new photo: A young girl is sitting on a sofa in the library, holding a book. His hair is neatly combed, and a faint smile plays on his lips, with a few freckles scattered across his cheeks. The library is quiet, with rows of shelves filled with books stretching out behind him.",
223
- "./imgs/demo_cases/edit.png",
224
- None,
225
- None,
226
- None,
227
- None,
228
- 2.0,
229
- 1.6,
230
- 50,
231
- 1,
232
- True,
233
- False,
234
- True,
235
- 1024,
236
- ],
237
- [
238
- "<img><|image_1|><\/img> What item can be used to see the current time? Please remove it.",
239
- "./imgs/test_cases/watch.jpg",
240
- None,
241
- None,
242
- None,
243
- None,
244
- 2.5,
245
- 1.6,
246
- 50,
247
- 0,
248
- True,
249
- False,
250
- True,
251
- 1024,
252
- ],
253
- [
254
- "According to the following examples, generate an output for the input.\nInput: <img><|image_1|></img>\nOutput: <img><|image_2|></img>\n\nInput: <img><|image_3|></img>\nOutput: ",
255
- "./imgs/test_cases/icl1.jpg",
256
- "./imgs/test_cases/icl2.jpg",
257
- "./imgs/test_cases/icl3.jpg",
258
- 224,
259
- 224,
260
- 2.5,
261
- 1.6,
262
- 50,
263
- 1,
264
- True,
265
- False,
266
- False,
267
- 768,
268
- ],
269
- ]
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.
279
  For multi-modal to image generation, you should pass a string as `prompt`, and a list of image paths as `input_images`. The placeholder in the prompt should be in the format of `<img><|image_*|></img>` (for the first image, the placeholder is <img><|image_1|></img>. for the second image, the the placeholder is <img><|image_2|></img>).
280
  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.
@@ -290,8 +94,7 @@ Tips:
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>`.
292
  - For image editing task and controlnet task, we recommend to set the height and width of output image as the same as input image. For example, if you want to edit a 512x512 image, you should set the height and width of output image as 512x512. You also can set the `use_input_image_size_as_output` to automatically set the height and width of output image as the same as input image.
293
-
294
-
295
  """
296
 
297
  article = """
@@ -307,120 +110,68 @@ If you find this repository useful, please consider giving a star ⭐ and citati
307
  year={2024}
308
  }
309
  ```
 
310
  **Contact**
311
  <br>
312
- If you have any questions, please feel free to open an issue or directly reach us out via email.
313
  """
314
 
315
 
316
- # Gradio
317
  with gr.Blocks() as demo:
318
- gr.Markdown("# OmniGen: Unified Image Generation [paper](https://arxiv.org/abs/2409.11340) [code](https://github.com/VectorSpaceLab/OmniGen)")
319
- gr.Markdown(description)
320
- with gr.Row():
321
  with gr.Column():
322
- # text prompt
323
- prompt_input = gr.Textbox(
324
- label="Enter your prompt, use <img><|image_i|></img> to represent i-th input image", placeholder="Type your prompt here..."
325
- )
326
-
327
- with gr.Row(equal_height=True):
328
- # input images
329
- image_input_1 = gr.Image(label="<img><|image_1|></img>", type="filepath")
330
- image_input_2 = gr.Image(label="<img><|image_2|></img>", type="filepath")
331
- image_input_3 = gr.Image(label="<img><|image_3|></img>", type="filepath")
332
-
333
- # slider
334
- height_input = gr.Slider(
335
- label="Height", minimum=128, maximum=2048, value=1024, step=16
336
- )
337
- width_input = gr.Slider(
338
- label="Width", minimum=128, maximum=2048, value=1024, step=16
339
- )
340
-
341
- guidance_scale_input = gr.Slider(
342
- label="Guidance Scale", minimum=1.0, maximum=5.0, value=2.5, step=0.1
343
- )
344
-
345
- img_guidance_scale_input = gr.Slider(
346
- label="img_guidance_scale", minimum=1.0, maximum=2.0, value=1.6, step=0.1
347
- )
348
-
349
- num_inference_steps = gr.Slider(
350
- label="Inference Steps", minimum=1, maximum=100, value=50, step=1
351
- )
352
-
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
359
- )
360
-
361
- separate_cfg_infer = gr.Checkbox(
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
372
- generate_button = gr.Button("Generate Image")
373
-
374
-
375
  with gr.Column():
376
- # output image
377
- output_image = gr.Image(label="Output Image")
378
-
379
- # click
380
- generate_button.click(
381
- generate_image,
382
- inputs=[
383
- prompt_input,
384
- image_input_1,
385
- image_input_2,
386
- image_input_3,
387
- height_input,
388
- width_input,
389
- guidance_scale_input,
390
- img_guidance_scale_input,
391
- num_inference_steps,
392
- seed_input,
393
- separate_cfg_infer,
394
- offload_model,
395
- use_input_image_size_as_output,
396
- max_input_image_size,
397
- ],
398
- outputs=output_image,
399
  )
400
 
401
- gr.Examples(
402
- examples=get_example(),
403
- fn=run_for_examples,
404
- inputs=[
405
- prompt_input,
406
- image_input_1,
407
- image_input_2,
408
- image_input_3,
409
- height_input,
410
- width_input,
411
- guidance_scale_input,
412
- img_guidance_scale_input,
413
- num_inference_steps,
414
- seed_input,
415
- separate_cfg_infer,
416
- offload_model,
417
- use_input_image_size_as_output,
418
- max_input_image_size,
419
- ],
420
- outputs=output_image,
421
  )
422
 
423
- gr.Markdown(article)
424
-
425
- # launch
426
- demo.launch()
 
1
+ try:
2
+ import spaces
3
+ USING_SPACES = True
4
+ except ImportError:
5
+ USING_SPACES = False
6
+
7
  import gradio as gr
8
  from PIL import Image
9
  import os
10
+ import torch
11
 
12
+ import random
13
+ import time
14
+ import numpy as np
15
 
16
  from OmniGen import OmniGenPipeline
17
 
18
+ random.seed(time.time())
19
+ MAX_SEED = np.iinfo(np.int32).max
20
+ SPACES_GPU_DURATION = 180
21
+
22
+ def gpu_decorator(duration=60):
23
+ def actual_decorator(func):
24
+ if USING_SPACES:
25
+ return spaces.GPU(duration=duration)(func)
26
+ return func
27
+ return actual_decorator
28
+
29
+ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
30
+ if randomize_seed:
31
+ seed = random.randint(0, MAX_SEED)
32
+ return seed
33
+
34
+ def updata_input_images(images):
35
+ if not images:
36
+ return gr.Gallery(label="Input Images", value=[], show_label=False, show_share_button=False, container=False)
37
+ images_with_names = [(image, f"image_{i + 1}") for i, image in enumerate(images)]
38
+ return gr.Gallery(label="Input Images", value=images_with_names, show_label=False, show_share_button=False, container=False)
39
+
40
+ def add_more_images(input_images, more_images):
41
+ input_images = input_images if input_images is not None else []
42
+ image_list = input_images + more_images
43
+ return gr.File(value=image_list, file_count="multiple",label="Input Images (Multi-select)"), gr.File(value=[], file_count="multiple",label="Add Image (More)")
44
+
45
+ pipe = OmniGenPipeline.from_pretrained("Shitao/OmniGen-v1")
46
+
47
+ @gpu_decorator(duration=SPACES_GPU_DURATION)
48
+ def generate(prompt, input_images, width, height, inference_steps, guidance_scale, randomize_seed, separate_cfg_infer, use_kv_cache, img_guidance_scale, offload_kv_cache, offload_model, use_input_image_size_as_output, max_input_image_size, progress=gr.Progress(track_tqdm=True)):
49
+ print({"prompt": prompt, "input_images": input_images, "width": width, "height": height, "inference_steps": inference_steps, "guidance_scale": guidance_scale, "randomize_seed": randomize_seed, "separate_cfg_infer": separate_cfg_infer, "use_kv_cache": use_kv_cache, "img_guidance_scale": img_guidance_scale, "offload_model": offload_model, "use_input_image_size_as_output": use_input_image_size_as_output, "max_input_image_size": max_input_image_size})
50
+ try:
51
+ seed = randomize_seed_fn(0, randomize_seed)
52
+
53
+ img = pipe(
54
+ prompt=prompt,
55
+ input_images=input_images,
56
+ width=width,
57
+ height=height,
58
+ num_inference_steps=inference_steps,
59
+ guidance_scale=guidance_scale,
60
+ seed=seed,
61
+ separate_cfg_infer=separate_cfg_infer,
62
+ use_kv_cache=use_kv_cache,
63
+ img_guidance_scale=img_guidance_scale,
64
+ offload_kv_cache=offload_kv_cache,
65
+ offload_model=offload_model,
66
+ use_input_image_size_as_output=use_input_image_size_as_output,
67
+ max_input_image_size=max_input_image_size,
68
+ )
69
+
70
+ return img[0], seed
71
+
72
+ except Exception as e:
73
+ error_message = str(e)
74
+ raise gr.Error(error_message)
75
 
76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  description = """
78
+ ### Description
79
  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.
80
  For multi-modal to image generation, you should pass a string as `prompt`, and a list of image paths as `input_images`. The placeholder in the prompt should be in the format of `<img><|image_*|></img>` (for the first image, the placeholder is <img><|image_1|></img>. for the second image, the the placeholder is <img><|image_2|></img>).
81
  For example, use an image of a woman to generate a new image:
82
  prompt = "A woman holds a bouquet of flowers and faces the camera. Thw woman is \<img\>\<|image_1|\>\</img\>."
83
 
84
+ ---
85
+
86
+ ### Tips
87
+ For out of memory or time cost, you can refer to [./docs/inference.md#requiremented-resources](https://github.com/VectorSpaceLab/OmniGen/blob/main/docs/inference.md#requiremented-resources) to select a appropriate setting.
88
+ ```
89
+ - If time cost is too long, please try to reduce the `max_input_image_size`.
90
  - Oversaturated: If the image appears oversaturated, please reduce the `guidance_scale`.
91
  - Not match the prompt: If the image does not match the prompt, please try to increase the `guidance_scale`.
92
  - Low-quality: More detailed prompt will lead to better results.
 
94
  - 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.
95
  - 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>`.
96
  - For image editing task and controlnet task, we recommend to set the height and width of output image as the same as input image. For example, if you want to edit a 512x512 image, you should set the height and width of output image as 512x512. You also can set the `use_input_image_size_as_output` to automatically set the height and width of output image as the same as input image.
97
+ ```
 
98
  """
99
 
100
  article = """
 
110
  year={2024}
111
  }
112
  ```
113
+
114
  **Contact**
115
  <br>
116
+ If you have any questions, please feel free to open an issue or directly reach us out via [email(Shitao Xiao)](mailto:2906698981@qq.com).
117
  """
118
 
119
 
 
120
  with gr.Blocks() as demo:
121
+ gr.Markdown("### Description\nThis is a duplicate from [Shitao/OmniGen](https://huggingface.co/spaces/Shitao/OmniGen). For more detailed information, please refer to the original source.\n")
122
+ with gr.Row(equal_height=True):
 
123
  with gr.Column():
124
+ input_images_gallery = gr.Gallery(label="Input Images", show_label=False, show_share_button=False, object_fit="contain")
125
+ with gr.Row():
126
+ input_images = gr.File(file_count="multiple",label="Input Images (Multi-select)")
127
+ add_more_input_image = gr.File(file_count="multiple",label="Add Image (More, additional)")
128
+ with gr.Accordion("Advanced Settings", open=True):
129
+ with gr.Row():
130
+ offload_kv_cache = gr.Checkbox(label="offload_kv_cache", value=True)
131
+ offload_model = gr.Checkbox(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)
132
+ with gr.Row():
133
+ separate_cfg_infer = gr.Checkbox(label="Separate cfg infer", info="Whether to use separate inference process for different guidance. This will reduce the memory cost.", value=True)
134
+ use_kv_cache = gr.Checkbox(label="Use kv cache", value=True)
135
+ img_guidance_scale = gr.Slider(label="Image guidance scale", minimum=1.0, maximum=2.0, value=1.6, step=0.1)
136
+ with gr.Row():
137
+ randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
138
+ seed = gr.Slider(0, MAX_SEED, value=0, step=1, label="Seed")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  with gr.Column():
140
+ result = gr.Image(label="Generated Image", show_label=False, show_download_button=True, format="png")
141
+ gr.Markdown(value=f"### Notice\nPlease note that the ZeroGPU duration limit is **{SPACES_GPU_DURATION}** seconds.\nConfigure parameters wisely to ensure task completion within this time.", container=True, line_breaks=True)
142
+ prompt = gr.TextArea(label="Prompt", placeholder="Enter your prompt", value="The woman in <img><|image_1|></img> waves her hand happily in the crowd.", show_copy_button=True)
143
+ with gr.Row():
144
+ use_input_image_size_as_output = gr.Checkbox(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)
145
+ max_input_image_size = gr.Slider(label="max_input_image_size", minimum=128, maximum=1920, value=1024, step=16)
146
+ with gr.Row():
147
+ width = gr.Slider(128, 1920, value=1024, step=16, label="Width")
148
+ height = gr.Slider(128, 1920, value=1024, step=16, label="Height")
149
+ with gr.Row():
150
+ inference_steps = gr.Slider(10, 100, value=50, step=1, label="Inference Steps")
151
+ guidance_scale = gr.Slider(1.0, 20.0, value=2.5, step=0.1, label="Guidance Scale")
152
+ run_button = gr.Button("Generate")
153
+
154
+ gr.Markdown(description)
155
+ gr.Markdown("### Example prompts\n```\n1.A woman holds a bouquet of flowers and faces the camera. The woman is <img><|image_1|></img>.\n2.<img><|image_1|></img> What item can be used to see the current time? Please remove it.\n3.Two men are celebrating with raised glasses in a restaurant. One man is <img><|image_1|></img>. The other man is <img><|image_2|></img>.\n4.The flower <img><|image_1|></img> is placed in the vase which is in the middle of <img><|image_2|></img> on a wooden table of a living room.\n```")
156
+ gr.Markdown(article)
157
+
158
+ input_images.change(
159
+ updata_input_images,
160
+ inputs=input_images,
161
+ outputs=input_images_gallery
 
162
  )
163
 
164
+ add_more_input_image.change(
165
+ add_more_images,
166
+ inputs=[input_images, add_more_input_image],
167
+ outputs=[input_images, add_more_input_image]
168
+ )
169
+
170
+ run_button.click(
171
+ generate,
172
+ inputs=[prompt, input_images, width, height, inference_steps, guidance_scale, randomize_seed, separate_cfg_infer, use_kv_cache, img_guidance_scale, offload_kv_cache, offload_model, use_input_image_size_as_output, max_input_image_size],
173
+ outputs=[result, seed]
 
 
 
 
 
 
 
 
 
 
174
  )
175
 
176
+ if __name__ == "__main__":
177
+ demo.queue(max_size=10).launch(ssr_mode=False)