Spaces:
Runtime error
Runtime error
update separate_cfg_infer,
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ pipe = OmniGenPipeline.from_pretrained(
|
|
| 11 |
|
| 12 |
@spaces.GPU(duration=180)
|
| 13 |
# 示例处理函数:生成图像
|
| 14 |
-
def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed):
|
| 15 |
input_images = [img1, img2, img3]
|
| 16 |
# 去除 None
|
| 17 |
input_images = [img for img in input_images if img is not None]
|
|
@@ -29,6 +29,7 @@ def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_gu
|
|
| 29 |
separate_cfg_infer=True, # set False can speed up the inference process
|
| 30 |
use_kv_cache=False,
|
| 31 |
seed=seed,
|
|
|
|
| 32 |
)
|
| 33 |
img = output[0]
|
| 34 |
return img
|
|
@@ -57,6 +58,7 @@ def get_example():
|
|
| 57 |
1.6,
|
| 58 |
50,
|
| 59 |
0,
|
|
|
|
| 60 |
],
|
| 61 |
[
|
| 62 |
"The woman in <img><|image_1|></img> waves her hand happily in the crowd",
|
|
@@ -69,6 +71,7 @@ def get_example():
|
|
| 69 |
1.9,
|
| 70 |
50,
|
| 71 |
128,
|
|
|
|
| 72 |
],
|
| 73 |
[
|
| 74 |
"A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
|
|
@@ -81,6 +84,7 @@ def get_example():
|
|
| 81 |
1.6,
|
| 82 |
50,
|
| 83 |
0,
|
|
|
|
| 84 |
],
|
| 85 |
[
|
| 86 |
"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,6 +97,7 @@ def get_example():
|
|
| 93 |
1.8,
|
| 94 |
50,
|
| 95 |
168,
|
|
|
|
| 96 |
],
|
| 97 |
[
|
| 98 |
"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>",
|
|
@@ -105,6 +110,7 @@ def get_example():
|
|
| 105 |
1.6,
|
| 106 |
50,
|
| 107 |
60,
|
|
|
|
| 108 |
],
|
| 109 |
[
|
| 110 |
"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>",
|
|
@@ -117,6 +123,7 @@ def get_example():
|
|
| 117 |
1.8,
|
| 118 |
50,
|
| 119 |
66,
|
|
|
|
| 120 |
],
|
| 121 |
[
|
| 122 |
"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",
|
|
@@ -129,6 +136,7 @@ def get_example():
|
|
| 129 |
1.6,
|
| 130 |
50,
|
| 131 |
0,
|
|
|
|
| 132 |
],
|
| 133 |
[
|
| 134 |
"<img><|image_1|><img>\n Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola.",
|
|
@@ -141,6 +149,7 @@ def get_example():
|
|
| 141 |
1.6,
|
| 142 |
50,
|
| 143 |
222,
|
|
|
|
| 144 |
],
|
| 145 |
[
|
| 146 |
"Detect the skeleton of human in this image: <img><|image_1|></img>.",
|
|
@@ -153,6 +162,7 @@ def get_example():
|
|
| 153 |
1.6,
|
| 154 |
50,
|
| 155 |
0,
|
|
|
|
| 156 |
],
|
| 157 |
[
|
| 158 |
"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.",
|
|
@@ -165,6 +175,7 @@ def get_example():
|
|
| 165 |
1.6,
|
| 166 |
50,
|
| 167 |
42,
|
|
|
|
| 168 |
],
|
| 169 |
[
|
| 170 |
"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.",
|
|
@@ -177,6 +188,7 @@ def get_example():
|
|
| 177 |
1.6,
|
| 178 |
50,
|
| 179 |
123,
|
|
|
|
| 180 |
],
|
| 181 |
[
|
| 182 |
"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.",
|
|
@@ -189,6 +201,7 @@ def get_example():
|
|
| 189 |
1.6,
|
| 190 |
50,
|
| 191 |
1,
|
|
|
|
| 192 |
],
|
| 193 |
[
|
| 194 |
"<img><|image_1|><\/img> What item can be used to see the current time? Please remove it.",
|
|
@@ -201,6 +214,7 @@ def get_example():
|
|
| 201 |
1.6,
|
| 202 |
50,
|
| 203 |
0,
|
|
|
|
| 204 |
],
|
| 205 |
[
|
| 206 |
"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: ",
|
|
@@ -213,12 +227,13 @@ def get_example():
|
|
| 213 |
1.6,
|
| 214 |
50,
|
| 215 |
1,
|
|
|
|
| 216 |
],
|
| 217 |
]
|
| 218 |
return case
|
| 219 |
|
| 220 |
-
def run_for_examples(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed):
|
| 221 |
-
return generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed)
|
| 222 |
|
| 223 |
description = """
|
| 224 |
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.
|
|
@@ -235,6 +250,8 @@ Tips:
|
|
| 235 |
- 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>`.
|
| 236 |
"""
|
| 237 |
|
|
|
|
|
|
|
| 238 |
# Gradio 接口
|
| 239 |
with gr.Blocks() as demo:
|
| 240 |
gr.Markdown("# OmniGen: Unified Image Generation [paper](https://arxiv.org/abs/2409.11340) [code](https://github.com/VectorSpaceLab/OmniGen)")
|
|
@@ -277,6 +294,10 @@ with gr.Blocks() as demo:
|
|
| 277 |
label="Seed", minimum=0, maximum=2147483647, value=42, step=1
|
| 278 |
)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
# 生成按钮
|
| 281 |
generate_button = gr.Button("Generate Image")
|
| 282 |
|
|
@@ -298,6 +319,7 @@ with gr.Blocks() as demo:
|
|
| 298 |
img_guidance_scale_input,
|
| 299 |
num_inference_steps,
|
| 300 |
seed_input,
|
|
|
|
| 301 |
],
|
| 302 |
outputs=output_image,
|
| 303 |
)
|
|
@@ -316,6 +338,7 @@ with gr.Blocks() as demo:
|
|
| 316 |
img_guidance_scale_input,
|
| 317 |
num_inference_steps,
|
| 318 |
seed_input,
|
|
|
|
| 319 |
],
|
| 320 |
outputs=output_image,
|
| 321 |
)
|
|
|
|
| 11 |
|
| 12 |
@spaces.GPU(duration=180)
|
| 13 |
# 示例处理函数:生成图像
|
| 14 |
+
def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer):
|
| 15 |
input_images = [img1, img2, img3]
|
| 16 |
# 去除 None
|
| 17 |
input_images = [img for img in input_images if img is not None]
|
|
|
|
| 29 |
separate_cfg_infer=True, # set False can speed up the inference process
|
| 30 |
use_kv_cache=False,
|
| 31 |
seed=seed,
|
| 32 |
+
separate_cfg_infer=separate_cfg_infer,
|
| 33 |
)
|
| 34 |
img = output[0]
|
| 35 |
return img
|
|
|
|
| 58 |
1.6,
|
| 59 |
50,
|
| 60 |
0,
|
| 61 |
+
False,
|
| 62 |
],
|
| 63 |
[
|
| 64 |
"The woman in <img><|image_1|></img> waves her hand happily in the crowd",
|
|
|
|
| 71 |
1.9,
|
| 72 |
50,
|
| 73 |
128,
|
| 74 |
+
False,
|
| 75 |
],
|
| 76 |
[
|
| 77 |
"A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
|
|
|
|
| 84 |
1.6,
|
| 85 |
50,
|
| 86 |
0,
|
| 87 |
+
False,
|
| 88 |
],
|
| 89 |
[
|
| 90 |
"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>.",
|
|
|
|
| 97 |
1.8,
|
| 98 |
50,
|
| 99 |
168,
|
| 100 |
+
False,
|
| 101 |
],
|
| 102 |
[
|
| 103 |
"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>",
|
|
|
|
| 110 |
1.6,
|
| 111 |
50,
|
| 112 |
60,
|
| 113 |
+
False,
|
| 114 |
],
|
| 115 |
[
|
| 116 |
"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>",
|
|
|
|
| 123 |
1.8,
|
| 124 |
50,
|
| 125 |
66,
|
| 126 |
+
False,
|
| 127 |
],
|
| 128 |
[
|
| 129 |
"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",
|
|
|
|
| 136 |
1.6,
|
| 137 |
50,
|
| 138 |
0,
|
| 139 |
+
False,
|
| 140 |
],
|
| 141 |
[
|
| 142 |
"<img><|image_1|><img>\n Remove the woman's earrings. Replace the mug with a clear glass filled with sparkling iced cola.",
|
|
|
|
| 149 |
1.6,
|
| 150 |
50,
|
| 151 |
222,
|
| 152 |
+
False,
|
| 153 |
],
|
| 154 |
[
|
| 155 |
"Detect the skeleton of human in this image: <img><|image_1|></img>.",
|
|
|
|
| 162 |
1.6,
|
| 163 |
50,
|
| 164 |
0,
|
| 165 |
+
False,
|
| 166 |
],
|
| 167 |
[
|
| 168 |
"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.",
|
|
|
|
| 175 |
1.6,
|
| 176 |
50,
|
| 177 |
42,
|
| 178 |
+
False,
|
| 179 |
],
|
| 180 |
[
|
| 181 |
"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.",
|
|
|
|
| 188 |
1.6,
|
| 189 |
50,
|
| 190 |
123,
|
| 191 |
+
False,
|
| 192 |
],
|
| 193 |
[
|
| 194 |
"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.",
|
|
|
|
| 201 |
1.6,
|
| 202 |
50,
|
| 203 |
1,
|
| 204 |
+
False,
|
| 205 |
],
|
| 206 |
[
|
| 207 |
"<img><|image_1|><\/img> What item can be used to see the current time? Please remove it.",
|
|
|
|
| 214 |
1.6,
|
| 215 |
50,
|
| 216 |
0,
|
| 217 |
+
False,
|
| 218 |
],
|
| 219 |
[
|
| 220 |
"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: ",
|
|
|
|
| 227 |
1.6,
|
| 228 |
50,
|
| 229 |
1,
|
| 230 |
+
False,
|
| 231 |
],
|
| 232 |
]
|
| 233 |
return case
|
| 234 |
|
| 235 |
+
def run_for_examples(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer,):
|
| 236 |
+
return generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, separate_cfg_infer,)
|
| 237 |
|
| 238 |
description = """
|
| 239 |
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 |
- 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>`.
|
| 251 |
"""
|
| 252 |
|
| 253 |
+
separate_cfg_infer_arg = False
|
| 254 |
+
|
| 255 |
# Gradio 接口
|
| 256 |
with gr.Blocks() as demo:
|
| 257 |
gr.Markdown("# OmniGen: Unified Image Generation [paper](https://arxiv.org/abs/2409.11340) [code](https://github.com/VectorSpaceLab/OmniGen)")
|
|
|
|
| 294 |
label="Seed", minimum=0, maximum=2147483647, value=42, step=1
|
| 295 |
)
|
| 296 |
|
| 297 |
+
separate_cfg_infer = gr.Checkbox(
|
| 298 |
+
label="separate_cfg_infer", info="enable separate cfg infer"
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
# 生成按钮
|
| 302 |
generate_button = gr.Button("Generate Image")
|
| 303 |
|
|
|
|
| 319 |
img_guidance_scale_input,
|
| 320 |
num_inference_steps,
|
| 321 |
seed_input,
|
| 322 |
+
separate_cfg_infer,
|
| 323 |
],
|
| 324 |
outputs=output_image,
|
| 325 |
)
|
|
|
|
| 338 |
img_guidance_scale_input,
|
| 339 |
num_inference_steps,
|
| 340 |
seed_input,
|
| 341 |
+
separate_cfg_infer,
|
| 342 |
],
|
| 343 |
outputs=output_image,
|
| 344 |
)
|