Skip to content

Commit

Permalink
fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
eaidova committed Dec 27, 2024
1 parent ad9a9c4 commit 9a56b2f
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 170 deletions.
2 changes: 2 additions & 0 deletions .ci/spellcheck/.pyspelling.wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ ocr
OCRBench
OCRv
odometry
OmniGen
OmniGen's
OmniParser
OMZ
OneFormer
Expand Down
2 changes: 1 addition & 1 deletion notebooks/omnigen/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Unified image generation using OmniGena and OpenVINO
# Unified image generation using OmniGen and OpenVINO

OmniGen is a unified image generation model that can generate a wide range of images from multi-modal prompts. It is designed to be simple, flexible, and easy to use. Existing image generation models often require loading several additional network modules (such as ControlNet, IP-Adapter, Reference-Net, etc.) and performing extra preprocessing steps (e.g., face detection, pose estimation, cropping, etc.) to generate a satisfactory image. OmniGen can generate various images directly through arbitrarily multi-modal instructions without additional plugins and operations. it can automatically identify the features (e.g., required object, human pose, depth mapping) in input images according to the text prompt.

Expand Down
66 changes: 30 additions & 36 deletions notebooks/omnigen/gradio_helper.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import gradio as gr
import random


def make_demo(pipe):
def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_guidance_scale, inference_steps, seed, max_input_image_size, randomize_seed, _=gr.Progress(track_tqdm=True)):
def generate_image(
text,
img1,
img2,
img3,
height,
width,
guidance_scale,
img_guidance_scale,
inference_steps,
seed,
max_input_image_size,
randomize_seed,
_=gr.Progress(track_tqdm=True),
):
input_images = [img1, img2, img3]
# Delete None
input_images = [img for img in input_images if img is not None]
if len(input_images) == 0:
input_images = None

if randomize_seed:
seed = random.randint(0, 10000000)

Expand All @@ -20,18 +35,14 @@ def generate_image(text, img1, img2, img3, height, width, guidance_scale, img_gu
guidance_scale=guidance_scale,
img_guidance_scale=img_guidance_scale,
num_inference_steps=inference_steps,
separate_cfg_infer=True,
separate_cfg_infer=True,
seed=seed,
max_input_image_size=max_input_image_size,

)
img = output[0]
return img



def get_example():

case = [
[
"A curly-haired man in a red shirt is drinking tea.",
Expand Down Expand Up @@ -151,12 +162,11 @@ def get_example():
2.5,
1.6,
12,
768
768,
],
]
return case


description = """
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.
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>).
Expand All @@ -172,8 +182,7 @@ def get_example():
- 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>`.
"""


# Gradio
# Gradio
with gr.Blocks() as demo:
gr.Markdown("# OmniGen: Unified Image Generation")
gr.Markdown(description)
Expand All @@ -191,37 +200,22 @@ def get_example():
image_input_3 = gr.Image(label="<img><|image_3|></img>", type="filepath")

# slider
height_input = gr.Slider(
label="Height", minimum=128, maximum=2048, value=256, step=16
)
width_input = gr.Slider(
label="Width", minimum=128, maximum=2048, value=256, step=16
)
height_input = gr.Slider(label="Height", minimum=128, maximum=2048, value=256, step=16)
width_input = gr.Slider(label="Width", minimum=128, maximum=2048, value=256, step=16)

guidance_scale_input = gr.Slider(
label="Guidance Scale", minimum=1.0, maximum=5.0, value=2.5, step=0.1
)
guidance_scale_input = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=5.0, value=2.5, step=0.1)

img_guidance_scale_input = gr.Slider(
label="img_guidance_scale", minimum=1.0, maximum=2.0, value=1.6, step=0.1
)
img_guidance_scale_input = gr.Slider(label="img_guidance_scale", minimum=1.0, maximum=2.0, value=1.6, step=0.1)

num_inference_steps = gr.Slider(
label="Inference Steps", minimum=1, maximum=100, value=20, step=1
)
num_inference_steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, value=20, step=1)

seed_input = gr.Slider(
label="Seed", minimum=0, maximum=2147483647, value=42, step=1
)
seed_input = gr.Slider(label="Seed", minimum=0, maximum=2147483647, value=42, step=1)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)

max_input_image_size = gr.Slider(
label="max_input_image_size", minimum=128, maximum=2048, value=256, step=16
)
max_input_image_size = gr.Slider(label="max_input_image_size", minimum=128, maximum=2048, value=256, step=16)

# generate
generate_button = gr.Button("Generate Image")


with gr.Column():
# output image
Expand Down Expand Up @@ -261,7 +255,7 @@ def get_example():
seed_input,
max_input_image_size,
randomize_seed,
]
],
)
return demo

return demo
43 changes: 22 additions & 21 deletions notebooks/omnigen/omnigen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unified image generation using OmniGena and OpenVINO\n",
"# Unified image generation using OmniGen and OpenVINO\n",
"\n",
"OmniGen is a unified image generation model that can generate a wide range of images from multi-modal prompts. It is designed to be simple, flexible, and easy to use. Existing image generation models often require loading several additional network modules (such as ControlNet, IP-Adapter, Reference-Net, etc.) and performing extra preprocessing steps (e.g., face detection, pose estimation, cropping, etc.) to generate a satisfactory image. OmniGen can generate various images directly through arbitrarily multi-modal instructions without additional plugins and operations. it can automatically identify the features (e.g., required object, human pose, depth mapping) in input images according to the text prompt.\n",
"\n",
Expand Down Expand Up @@ -51,7 +51,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prereqisites\n",
"## Prerequisites\n",
"[back to top ⬆️](#Table-of-contents:)"
]
},
Expand Down Expand Up @@ -333,13 +333,13 @@
],
"source": [
"images = pipe(\n",
" prompt=\"Two cute cats, one of them is ginger and another one is black, quality details, hyper realistic, high definition, photorealistic\", \n",
" height=320, \n",
" width=320, \n",
" prompt=\"Two cute cats, one of them is ginger and another one is black, quality details, hyper realistic, high definition, photorealistic\",\n",
" height=320,\n",
" width=320,\n",
" guidance_scale=2.5,\n",
" seed=0,\n",
" max_input_image_size=320,\n",
" num_inference_steps=25\n",
" num_inference_steps=25,\n",
")\n",
"images[0]"
]
Expand Down Expand Up @@ -389,13 +389,13 @@
"images = pipe(\n",
" prompt=\"A cat is reading a blue book. The cat is the left cat in <img><|image_1|></img>.\",\n",
" input_images=[\"cats.png\"],\n",
" height=320, \n",
" height=320,\n",
" width=320,\n",
" guidance_scale=2.5, \n",
" guidance_scale=2.5,\n",
" img_guidance_scale=1.6,\n",
" seed=0,\n",
" max_input_image_size=320,\n",
" num_inference_steps=30\n",
" num_inference_steps=30,\n",
")\n",
"images[0]"
]
Expand Down Expand Up @@ -444,21 +444,22 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"openvino_notebooks": {
"imageUrl": "https://github.com/user-attachments/assets/ca0929af-f766-4e69-872f-95ceceeac634",
"tags": {
"categories": [
"Model Demos"
],
"libraries": [],
"tasks": [
"Text-to-Image"
]
}
},
"pygments_lexer": "ipython3",
"version": "3.11.4"
},
"openvino_notebooks": {
"imageUrl": "https://github.com/user-attachments/assets/ca0929af-f766-4e69-872f-95ceceeac634",
"tags": {
"categories": [
"Model Demos",
"AI trends"
],
"libraries": [],
"tasks": [
"Text-to-Image"
]
}
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {
Expand Down
Loading

0 comments on commit 9a56b2f

Please sign in to comment.