Shitao commited on
Commit
aac204e
1 Parent(s): a9f51f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -67
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  from PIL import Image
3
  import os
4
  import random
5
-
6
  import spaces
7
 
8
  from OmniGen import OmniGenPipeline
@@ -55,12 +54,9 @@ def get_example():
55
  1024,
56
  2.5,
57
  1.6,
58
- 50,
59
  0,
60
- True,
61
- False,
62
- False,
63
  1024,
 
64
  ],
65
  [
66
  "The woman in <img><|image_1|></img> waves her hand happily in the crowd",
@@ -71,12 +67,9 @@ def get_example():
71
  1024,
72
  2.5,
73
  1.9,
74
- 50,
75
  128,
76
- True,
77
- False,
78
- False,
79
  1024,
 
80
  ],
81
  [
82
  "A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
@@ -87,12 +80,9 @@ def get_example():
87
  1024,
88
  2.5,
89
  1.6,
90
- 50,
91
  0,
92
- True,
93
- False,
94
- False,
95
  1024,
 
96
  ],
97
  [
98
  "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>.",
@@ -103,12 +93,9 @@ def get_example():
103
  1024,
104
  2.5,
105
  1.8,
106
- 50,
107
  168,
108
- True,
109
- False,
110
- False,
111
  1024,
 
112
  ],
113
  [
114
  "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>",
@@ -119,12 +106,9 @@ def get_example():
119
  1024,
120
  2.5,
121
  1.6,
122
- 50,
123
  60,
124
- True,
125
- False,
126
- False,
127
  1024,
 
128
  ],
129
  [
130
  "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>",
@@ -135,12 +119,9 @@ def get_example():
135
  1024,
136
  2.5,
137
  1.8,
138
- 50,
139
  66,
140
- True,
141
- False,
142
- False,
143
  1024,
 
144
  ],
145
  [
146
  "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",
@@ -151,12 +132,9 @@ def get_example():
151
  1024,
152
  2.5,
153
  1.6,
154
- 50,
155
  0,
156
- True,
157
- False,
158
- False,
159
  1024,
 
160
  ],
161
  [
162
  "<img><|image_1|><img>\n Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola.",
@@ -167,12 +145,9 @@ def get_example():
167
  None,
168
  2.5,
169
  1.6,
170
- 50,
171
  222,
172
- True,
173
- False,
174
- True,
175
  1024,
 
176
  ],
177
  [
178
  "Detect the skeleton of human in this image: <img><|image_1|></img>.",
@@ -183,12 +158,9 @@ def get_example():
183
  None,
184
  2.0,
185
  1.6,
186
- 50,
187
  0,
188
- True,
189
- False,
190
- True,
191
  1024,
 
192
  ],
193
  [
194
  "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.",
@@ -199,12 +171,9 @@ def get_example():
199
  None,
200
  2,
201
  1.6,
202
- 50,
203
  42,
204
- True,
205
- False,
206
- True,
207
  1024,
 
208
  ],
209
  [
210
  "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.",
@@ -215,12 +184,9 @@ def get_example():
215
  None,
216
  2.0,
217
  1.6,
218
- 50,
219
  123,
220
- True,
221
- False,
222
- True,
223
  1024,
 
224
  ],
225
  [
226
  "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.",
@@ -231,12 +197,9 @@ def get_example():
231
  None,
232
  2.0,
233
  1.6,
234
- 50,
235
  1,
236
- True,
237
- False,
238
- True,
239
  1024,
 
240
  ],
241
  [
242
  "<img><|image_1|><\/img> What item can be used to see the current time? Please remove it.",
@@ -247,12 +210,9 @@ def get_example():
247
  None,
248
  2.5,
249
  1.6,
250
- 50,
251
  0,
252
- True,
253
- False,
254
- True,
255
  1024,
 
256
  ],
257
  [
258
  "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: ",
@@ -263,20 +223,25 @@ def get_example():
263
  224,
264
  2.5,
265
  1.6,
266
- 50,
267
  1,
268
- True,
269
- False,
270
- False,
271
  768,
 
272
  ],
273
  ]
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,17 +250,18 @@ For example, use an image of a woman to generate a new image:
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>`.
296
- - 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.
297
 
298
 
 
 
299
  """
300
 
301
  article = """
@@ -416,12 +382,9 @@ with gr.Blocks() as demo:
416
  width_input,
417
  guidance_scale_input,
418
  img_guidance_scale_input,
419
- num_inference_steps,
420
  seed_input,
421
- separate_cfg_infer,
422
- offload_model,
423
- use_input_image_size_as_output,
424
  max_input_image_size,
 
425
  ],
426
  outputs=output_image,
427
  )
 
2
  from PIL import Image
3
  import os
4
  import random
 
5
  import spaces
6
 
7
  from OmniGen import OmniGenPipeline
 
54
  1024,
55
  2.5,
56
  1.6,
 
57
  0,
 
 
 
58
  1024,
59
+ False,
60
  ],
61
  [
62
  "The woman in <img><|image_1|></img> waves her hand happily in the crowd",
 
67
  1024,
68
  2.5,
69
  1.9,
 
70
  128,
 
 
 
71
  1024,
72
+ False,
73
  ],
74
  [
75
  "A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
 
80
  1024,
81
  2.5,
82
  1.6,
 
83
  0,
 
 
 
84
  1024,
85
+ False,
86
  ],
87
  [
88
  "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>.",
 
93
  1024,
94
  2.5,
95
  1.8,
 
96
  168,
 
 
 
97
  1024,
98
+ False,
99
  ],
100
  [
101
  "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>",
 
106
  1024,
107
  2.5,
108
  1.6,
 
109
  60,
 
 
 
110
  1024,
111
+ False,
112
  ],
113
  [
114
  "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>",
 
119
  1024,
120
  2.5,
121
  1.8,
 
122
  66,
 
 
 
123
  1024,
124
+ False,
125
  ],
126
  [
127
  "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",
 
132
  1024,
133
  2.5,
134
  1.6,
 
135
  0,
 
 
 
136
  1024,
137
+ False,
138
  ],
139
  [
140
  "<img><|image_1|><img>\n Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola.",
 
145
  None,
146
  2.5,
147
  1.6,
 
148
  222,
 
 
 
149
  1024,
150
+ False,
151
  ],
152
  [
153
  "Detect the skeleton of human in this image: <img><|image_1|></img>.",
 
158
  None,
159
  2.0,
160
  1.6,
 
161
  0,
 
 
 
162
  1024,
163
+ False,
164
  ],
165
  [
166
  "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.",
 
171
  None,
172
  2,
173
  1.6,
 
174
  42,
 
 
 
175
  1024,
176
+ False,
177
  ],
178
  [
179
  "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.",
 
184
  None,
185
  2.0,
186
  1.6,
 
187
  123,
 
 
 
188
  1024,
189
+ False,
190
  ],
191
  [
192
  "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.",
 
197
  None,
198
  2.0,
199
  1.6,
 
200
  1,
 
 
 
201
  1024,
202
+ False,
203
  ],
204
  [
205
  "<img><|image_1|><\/img> What item can be used to see the current time? Please remove it.",
 
210
  None,
211
  2.5,
212
  1.6,
 
213
  0,
 
 
 
214
  1024,
215
+ False,
216
  ],
217
  [
218
  "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: ",
 
223
  224,
224
  2.5,
225
  1.6,
 
226
  1,
 
 
 
227
  768,
228
+ False,
229
  ],
230
  ]
231
  return case
232
 
233
+ def run_for_examples(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, seed, max_input_image_size, randomize_seed):
234
+ # 在函数内部设置默认值
235
+ inference_steps = 50
236
+ separate_cfg_infer = True
237
+ offload_model = False
238
+ use_input_image_size_as_output = False
239
+
240
+ return generate_image(
241
+ text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale,
242
+ inference_steps, seed, separate_cfg_infer, offload_model,
243
+ use_input_image_size_as_output, max_input_image_size, randomize_seed
244
+ )
245
 
246
  description = """
247
  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.
 
250
  prompt = "A woman holds a bouquet of flowers and faces the camera. Thw woman is \<img\>\<|image_1|\>\</img\>."
251
 
252
  Tips:
253
+ - 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.
254
  - 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.
255
  - 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).
256
  - Oversaturated: If the image appears oversaturated, please reduce the `guidance_scale`.
 
257
  - Low-quality: More detailed prompts will lead to better results.
258
  - Animate Style: If the genereate images is in animate style, you can try to add `photo` to the prompt`.
259
  - 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.
260
  - 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>`.
 
261
 
262
 
263
+ HF Spaces often encounter errors due to quota limitations, so recommend to run it locally.
264
+
265
  """
266
 
267
  article = """
 
382
  width_input,
383
  guidance_scale_input,
384
  img_guidance_scale_input,
 
385
  seed_input,
 
 
 
386
  max_input_image_size,
387
+ randomize_seed,
388
  ],
389
  outputs=output_image,
390
  )