diff --git a/.gitattributes b/.gitattributes index a6344aac8c09253b3b630fb776ae94478aa0275b..dd04d6a78d02f75aee556e4fee410d58b3cf1d37 100644 --- a/.gitattributes +++ b/.gitattributes @@ -33,3 +33,9 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text *.zst filter=lfs diff=lfs merge=lfs -text *tfevents* filter=lfs diff=lfs merge=lfs -text +assets/banner/banner.png filter=lfs diff=lfs merge=lfs -text +assets/banner/thumbnail.png filter=lfs diff=lfs merge=lfs -text +assets/examples/11_layout.png filter=lfs diff=lfs merge=lfs -text +assets/image_gallery_en/-017.jpg filter=lfs diff=lfs merge=lfs -text +assets/image_gallery_en/062.jpg filter=lfs diff=lfs merge=lfs -text +assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf filter=lfs diff=lfs merge=lfs -text diff --git a/app.py b/app.py new file mode 100644 index 0000000000000000000000000000000000000000..5bddccb4256b5dce3b2c90f2d30f179ac675b45c --- /dev/null +++ b/app.py @@ -0,0 +1,388 @@ +##!/usr/bin/python3 +# -*- coding: utf-8 -*- +# @Time : 2024-01-29 +# @Author : Junjie He +import json +import os +import time +import uuid + +import cv2 +import gradio as gr +import numpy as np +from PIL import Image +from modelscope.outputs import OutputKeys +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks + +from src.generation import call_generation +from src.util import upload_np_2_oss, upload_json_string_2_oss, upload_preprocess, merge_images + +universal_matting = pipeline(Tasks.universal_matting, model='damo/cv_unet_universal-matting') + +img = "assets/image_gallery_en/" +files = os.listdir(img) +files = [file for file in files if file.lower().endswith(('.png', '.jpg', '.jpeg'))] +files = sorted(files) +basic_usage = [] +showcases = [] +for idx, name in enumerate(files): + temp = os.path.join(os.path.dirname(__file__), img, name) + if idx < 4: + basic_usage.append(temp) + else: + showcases.append(temp) + +# - - - - - examples - - - - - # +ep = "assets/examples" +# Layout, Style, Color, Subject, Prompt,Strict Layout Edge,Layout Content Scale, Automatic Image Matting +image_examples = [ + [0, f"{ep}/00_layout.png", f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0., False], + [1, f"{ep}/01_layout.png", f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0.8, False], + [2, f"{ep}/empty.png", f"{ep}/02_style.png", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0.8, False], + [3, f"{ep}/empty.png", f"{ep}/03_style.png", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0.8, False], + [4, f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/04_color.png", f"{ep}/empty.png", "A moose, Merry Christmas", True, 0.8, False], + [5, f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/05_color.png", f"{ep}/empty.png", "A photo about cherry blossom", + True, 0.8, False], + [6, f"{ep}/06_layout.png", f"{ep}/06_style.jpeg", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0.8, False], + [7, f"{ep}/07_layout.jpeg", f"{ep}/07_style.jpeg", f"{ep}/empty.png", f"{ep}/empty.png", "", True, 0.8, False], + [8, f"{ep}/empty.png", f"{ep}/08_style.png", f"{ep}/08_color.jpeg", f"{ep}/empty.png", "", True, 0.8, False], + [9, f"{ep}/empty.png", f"{ep}/09_style.png", f"{ep}/empty.png", f"{ep}/base_image1.jpeg", "", True, 0.8, True], + [10, f"{ep}/10_layout.png", f"{ep}/10_style.png", f"{ep}/empty.png", f"{ep}/base_image2.png", "", True, 0.8, False], + [11, f"{ep}/11_layout.png", f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/base_image4.png", "", False, 0.8, False], + [12, f"{ep}/12_layout.png", f"{ep}/empty.png", f"{ep}/empty.png", f"{ep}/base_image3.png", "", False, 0.8, False], +] + +example_images = [ + [0, f"{ep}/layout_image1.jpeg", None, None, None], + [1, f"{ep}/layout_image1.jpeg", None, None, None], + [2, None, f"{ep}/style_image1.jpeg", None, None], + [3, None, f"{ep}/style_image1.jpeg", None, None], + [4, None, None, f"{ep}/color_image1.jpeg", None], + [5, None, None, f"{ep}/color_image3.jpeg", None], + [6, f"{ep}/layout_image2.jpeg", f"{ep}/style_image2.jpeg", None, None], + [7, f"{ep}/layout_image3.jpeg", f"{ep}/style_image3.jpeg", None, None], + [8, None, f"{ep}/style_image4.jpeg", f"{ep}/color_image2.jpeg", None], + [9, None, f"{ep}/style_image6.jpeg", None, f"{ep}/09_base.png"], + [10, f"{ep}/layout_image5.jpeg", f"{ep}/style_image5.jpeg", None, f"{ep}/10_base.png"], + [11, f"{ep}/layout_image7.jpeg", None, None, f"{ep}/11_base.png"], + [12, f"{ep}/layout_image6.jpeg", None, None, f"{ep}/12_base.png"], +] + +example_masks = [ + [0, None, None, None], + [1, f"{ep}/layout_image1_mask.png", None, None], + [2, None, f"{ep}/style_image1_mask.png", None], + [3, None, f"{ep}/style_image1_mask2.png", None], + [4, None, None, None], + [5, None, None, f"{ep}/color_image3_mask.png"], + [6, None, None, None], + [7, None, None, None], + [8, None, None, None], + [9, None, f"{ep}/style_image6_mask.png", None], + [10, f"{ep}/layout_image5_mask.png", None, None], + [11, None, None, None], + [12, f"{ep}/layout_image6_mask.png", None, None], +] + + +def process_example(example_idx, pil_layout_image, pil_style_image, pil_color_image, pil_base_image_rgba, + prompt, strict_edge, layout_scale, preprocess_base_image): + _, layout_image, style_image, color_image, base_image_rgba = example_images[example_idx] + _, layout_mask, style_mask, color_mask = example_masks[example_idx] + + pil_layout_image = None if layout_image is None else pil_layout_image + pil_style_image = None if style_image is None else pil_style_image + pil_color_image = None if color_image is None else pil_color_image + pil_base_image_rgba = None if base_image_rgba is None else pil_base_image_rgba + + return pil_layout_image, layout_mask, pil_style_image, style_mask, pil_color_image, color_mask, \ + pil_base_image_rgba, prompt, strict_edge, layout_scale, preprocess_base_image + + +def process(pil_base_image_rgba=None, preprocess_base_image=False, + pil_layout_image_dict=None, layout_scale=1.0, edge_consistency=0.5, + strict_edge=False, + pil_color_image_dict=None, color_scale=1.0, + pil_style_image_dict=None, style_scale=1.0, prompt="best quality", negative_prompt="", + pil_layout_mask=None, pil_style_mask=None, pil_color_mask=None): + request_id = time.strftime('%Y%m%d-', time.localtime(time.time())) + str(uuid.uuid4()) + + output_aspect_ratio = 1. + matting_flag = False + + if pil_base_image_rgba is None: + base_image_url = "" + pil_fg_mask = None + else: + if preprocess_base_image: + matting_flag = True + orig_image = np.array(pil_base_image_rgba) + orig_alpha = np.array(pil_base_image_rgba)[..., -1] + matting_alpha = universal_matting(pil_base_image_rgba)[OutputKeys.OUTPUT_IMG][..., -1] + orig_image[..., -1] = ((matting_alpha > 200) * (orig_alpha > 200) * 255.).astype(np.uint8) + pil_base_image_rgba = Image.fromarray(orig_image) + pil_fg_mask = pil_base_image_rgba.split()[-1] + + w, h = pil_base_image_rgba.size + output_aspect_ratio = max(1.0 * w / h, 1.0 * h / w) + if output_aspect_ratio > 2: + raise gr.Error("Input of subject images with aspect ratio exceeding 2 is not supported") + if min(w, h) > 1536: + raise gr.Error("Input of subject images with the shorter side exceeding 1536 pixels is not supported") + base_image_url = upload_np_2_oss(np.array(pil_base_image_rgba), request_id + "_base.png") + + if pil_layout_image_dict is None: + layout_image_url = "" + else: + np_layout_image = np.array(pil_layout_image_dict["image"].convert("RGBA")) + np_layout_image, np_layout_alpha = np_layout_image[..., :3], np_layout_image[..., 3] + np_layout_mask = np.array(pil_layout_image_dict["mask"].convert("L")) + if pil_layout_mask is None: + np_layout_mask = ((np_layout_alpha > 127) * (np_layout_mask < 127) * 255.).astype(np.uint8) + else: + np_layout_mask = ((np_layout_alpha > 127) * (np_layout_mask < 127) * + (np.array(pil_layout_mask) > 127) * 255.).astype(np.uint8) + layout_image_url = upload_np_2_oss( + np.concatenate([np_layout_image, np_layout_mask[..., None]], axis=-1), request_id + "_layout.png" + ) + if pil_base_image_rgba is None: + h, w, c = np_layout_image.shape + output_aspect_ratio = max(1.0 * w / h, 1.0 * h / w) + if output_aspect_ratio > 2: + raise gr.Error("Input of layout images with aspect ratio exceeding 2 is not supported") + if min(w, h) > 1536: + raise gr.Error("Input of layout images with the shorter side exceeding 1536 pixels is not supported") + + if pil_style_image_dict is None: + style_image_url = "" + else: + np_style_image = np.array(pil_style_image_dict["image"].convert("RGBA")) + np_style_image, np_style_alpha = np_style_image[..., :3], np_style_image[..., 3] + np_style_mask = np.array(pil_style_image_dict["mask"].convert("L")) + if pil_style_mask is None: + np_style_mask = ((np_style_alpha > 127) * (np_style_mask < 127) * 255.).astype(np.uint8) + else: + np_style_mask = ((np_style_alpha > 127) * (np_style_mask < 127) * + (np.array(pil_style_mask) > 127) * 255.).astype(np.uint8) + style_image_url = upload_np_2_oss( + np.concatenate([np_style_image, np_style_mask[..., None]], axis=-1), request_id + "_style.png" + ) + + if pil_color_image_dict is None: + color_image_url = "" + else: + np_color_image = np.array(pil_color_image_dict["image"].convert("RGBA")) + np_color_image, np_color_alpha = np_color_image[..., :3], np_color_image[..., 3] + np_color_mask = np.array(pil_color_image_dict["mask"].convert("L")) + if pil_color_mask is None: + np_color_mask = ((np_color_alpha > 127) * (np_color_mask < 127) * 255.).astype(np.uint8) + else: + np_color_mask = ((np_color_alpha > 127) * (np_color_mask < 127) * + (np.array(pil_color_mask) > 127) * 255.).astype(np.uint8) + color_image_url = upload_np_2_oss( + np.concatenate([np_color_image, np_color_mask[..., None]], axis=-1), request_id + "_color.png" + ) + + res = call_generation(base_image_url=base_image_url, layout_image_url=layout_image_url, + color_image_url=color_image_url, style_image_url=style_image_url, + strict_edge=int(strict_edge), layout_scale=int(layout_scale * 10), + edge_consistency=int(edge_consistency * 10), color_scale=int(color_scale * 10), + style_scale=int(style_scale * 10), prompt=prompt, negative_prompt=negative_prompt, + output_aspect_ratio=output_aspect_ratio) + + for idx, r in enumerate(res): + upload_np_2_oss(np.array(r), request_id + f"_{idx}.jpg") + + if matting_flag: + res.append(pil_base_image_rgba) + return res, request_id, True, pil_fg_mask + + +if __name__ == "__main__": + + block = gr.Blocks( + title="TransferAnything", + css="assets/css/style.css", + theme=gr.themes.Soft( + radius_size=gr.themes.sizes.radius_none, + text_size=gr.themes.sizes.text_md + )).queue(concurrency_count=3) + with block: + with gr.Row(): + with gr.Column(): + gr.HTML(f""" +
+

TransferAnything: Enabling Versatile Visual Information Transfer for Creative Image Synthesis

+
+ Project Page +
+
+

TransferAnything supports transferring various visual information from any area of any image to create new compositions, offering higher freedom and flexibility in image synthesis. Currently, it supports the transfer of layout, color, style, and pixel content, with more visual information transfer capabilities under continuous development.

+
+
+ """) + #
如果你认为该项目有所帮助的话,不妨给我们Github点个Star以便获取最新的项目进展.
+ with gr.Tabs(elem_classes=["Tab"]): + with gr.TabItem("Image Gallery"): + gr.Gallery(label="Basic Usage", value=basic_usage, height=320, columns=4, object_fit="scale-down") + gr.Gallery(label="Advanced Combinations", value=showcases, height=800, columns=4, object_fit="scale-down") + with gr.TabItem("Image Creation"): + with gr.Row(): + with gr.Column(scale=1): + ... + with gr.Column(scale=3): + gr.Image(value="assets/banner/banner.png", width=1024, show_label=False, + show_download_button=False) + with gr.Column(scale=1): + ... + with gr.Accordion(label="🧭 Instructions:", open=True, elem_id="accordion"): + with gr.Row(equal_height=True): + # with gr.Row(elem_id="ShowCase"): + # gr.Image(value="assets/banner/ra.gif") + gr.Markdown(""" + - ⭐️ step1: (Optional) Upload or select a set of images from the examples for the "Layout", "Style", and "Color" reference. Mix and match freely, no need to select all. + - ⭐️ step2: (Optional) Use brush to erase areas in the layout, style, and color reference images (if present) that you do not want transferred. + - ⭐️ step3: (Optional) Upload an image with the subject you wish to preserve at the pixel level to the "Subject" component, with a transparent channel required (or upload a regular RGB image and select automatic image matting, which will automatically segment the subject area for you). + - ⭐️ step4: Click "Run" to start the generation process. + - ⭐️ step5: (Optional) Additionally, prompt input is supported, as well as control over advanced parameters such as layout edge consistency and conditional weights. Feel free to try these features. + """) + # with gr.Row(equal_height=True): + # gr.Markdown("""❤️ 温馨提示:上传图片最大边不超过1024,宽高比为1:1,将会生成更快哟""") + with gr.Row(): + with gr.Column(scale=1, min_width=160): + with gr.Tabs(elem_classes=["feedback"]): + with gr.TabItem("Layout (Optional)"): + pil_layout_image_dict = gr.ImageMask(source='upload', type="pil", show_label=False, + image_mode="RGBA") + pil_layout_image = gr.Image(interactive=False, type="pil", visible=False, label="Layout") + pil_layout_mask = gr.Image(interactive=False, type="pil", visible=False, label="Layout Mask", + image_mode="L") + with gr.Box(): + with gr.Accordion(label="Layout Parameters", open=False, elem_id="accordion"): + with gr.TabItem("Layout Edge"): + strict_edge = gr.Checkbox(label="Strict", value=True) + strict_edge_mirror = gr.Checkbox(label="Strict Layout Edge", visible=False) + edge_consistency = gr.Slider(label="Degree of Consistency (If Not Strict)", minimum=0.0, + maximum=1.0, + step=0.1, value=0.8, interactive=True) + with gr.TabItem("Layout Content"): + layout_scale = gr.Slider(label="Scale", minimum=0.0, maximum=1.0, step=0.1, + value=0.8, + interactive=True) + layout_scale_mirror = gr.Slider(label="Layout Content Scale", visible=False) + + with gr.Column(scale=1, min_width=160): + with gr.Tabs(elem_classes=["feedback"]): + with gr.TabItem("Style (Optional)"): + pil_style_image_dict = gr.ImageMask(source='upload', type="pil", show_label=False, + image_mode="RGBA") + pil_style_image = gr.Image(interactive=False, type="pil", visible=False, label="Style") + pil_style_mask = gr.Image(interactive=False, type="pil", visible=False, label="Style Mask", + image_mode="L") + with gr.Box(): + with gr.Accordion(label="Style Parameters", open=False, elem_id="accordion"): + style_scale = gr.Slider(label="Scale", minimum=0.0, maximum=1.0, step=0.1, + value=0.8, interactive=True) + with gr.Column(scale=1, min_width=160): + with gr.Tabs(elem_classes=["feedback"]): + with gr.TabItem("Color (Optional, recommended for use with prompt)"): + pil_color_image_dict = gr.ImageMask(source='upload', type="pil", show_label=False, + image_mode="RGBA") + pil_color_image = gr.Image(interactive=False, type="pil", visible=False, label="Color") + pil_color_mask = gr.Image(interactive=False, type="pil", visible=False, label="Color Mask", + image_mode="L") + with gr.Box(): + with gr.Accordion(label="Color Parameters", open=False, elem_id="accordion"): + color_scale = gr.Slider(label="Scale", minimum=0.0, maximum=1.0, step=0.1, + value=0.8, interactive=True) + with gr.Row(): + with gr.Column(scale=1, min_width=160): + with gr.Tabs(elem_classes=["feedback"]): + with gr.TabItem("Subject (Optional)"): + pil_base_image_rgba = gr.Image(source='upload', + interactive=True, show_label=False, + type="pil", image_mode="RGBA", tool="editor") + pil_base_image_rgba_mirror = gr.Image(label="Subject", image_mode="RGBA", visible=False) + with gr.Box(): + preprocess_base_image = gr.Checkbox(label="Automatic Image Matting") + pil_fg_mask = gr.Image(interactive=False, type="pil", image_mode="L", visible=False) + run_button = gr.Button("Run", elem_id="btn") + with gr.Accordion("", open=True, elem_id="accordion1"): + prompt = gr.Textbox(value="", label='Prompt', lines=1, interactive=True) + prompt_mirror = gr.Textbox(label='Prompt', visible=False) + negative_prompt = gr.Textbox(value="", label='Negative prompt', lines=1, + interactive=True) + with gr.Column(scale=2, min_width=160): + with gr.Tabs(elem_classes=["feedback"]): + with gr.TabItem("Outputs"): + result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", + preview=True) + recommend = gr.Button("Recommend results to Image Gallery", elem_id="recBut") + request_id = gr.State(value="") + gallery_flag = gr.State(value=False) + with gr.Row(): + with gr.Box(): + example_idx = gr.Slider(label="Index", visible=False, value=0) + example = gr.Examples( + label="Input Examples", + examples=image_examples, + inputs=[example_idx, + pil_layout_image, pil_style_image, pil_color_image, pil_base_image_rgba_mirror, + prompt_mirror, strict_edge_mirror, layout_scale_mirror, preprocess_base_image], + outputs=[pil_layout_image_dict, pil_layout_mask, pil_style_image_dict, pil_style_mask, + pil_color_image_dict, pil_color_mask, pil_base_image_rgba, + prompt, strict_edge, layout_scale, preprocess_base_image], + fn=process_example, + run_on_click=True, + examples_per_page=20 + ) + + + def upload_to_img_gallery(pil_base_image_rgba, pil_layout_image_dict, pil_style_image_dict, + pil_color_image_dict, pil_fg_mask, prompt, negative_prompt, res, re_id, flag, + strict_edge, edge_consistency, layout_scale, style_scale, color_scale, + preprocess_base_image): + if flag: + np_out_base_image, np_out_layout_image, np_out_style_image, np_out_color_image = upload_preprocess( + pil_base_image_rgba, pil_layout_image_dict, pil_style_image_dict, pil_color_image_dict, pil_fg_mask) + np_out_images = [np_out_base_image, np_out_layout_image, np_out_style_image, np_out_color_image] + for idx, r in enumerate(res): + if idx < 4: + r = cv2.imread(r['name']) + r = cv2.cvtColor(r, cv2.COLOR_BGR2RGB) + upload_np_2_oss(merge_images(*np_out_images, r, prompt, negative_prompt), + name=re_id + f"_merge_{idx}.jpg", gallery=True) + config = dict( + strict_edge=strict_edge, + edge_consistency=edge_consistency, + layout_scale=layout_scale, + style_scale=style_scale, + color_scale=color_scale, + preprocess_base_image=preprocess_base_image + ) + upload_json_string_2_oss(json.dumps(config), name=re_id + f"_config.txt", gallery=True) + + flag = False + gr.Info("Images have been uploaded and await review.") + else: + gr.Info("No images to recommend, or already suggested once.") + return flag + + + recommend.click( + upload_to_img_gallery, + [pil_base_image_rgba, pil_layout_image_dict, pil_style_image_dict, pil_color_image_dict, pil_fg_mask, + prompt, negative_prompt, result_gallery, request_id, gallery_flag, strict_edge, edge_consistency, + layout_scale, style_scale, color_scale, preprocess_base_image], + [gallery_flag] + ) + + ips = [pil_base_image_rgba, preprocess_base_image, + pil_layout_image_dict, layout_scale, edge_consistency, strict_edge, + pil_color_image_dict, color_scale, + pil_style_image_dict, style_scale, prompt, negative_prompt, + pil_layout_mask, pil_style_mask, pil_color_mask] + run_button.click(fn=process, inputs=ips, outputs=[result_gallery, request_id, gallery_flag, pil_fg_mask]) + + block.launch(server_name='0.0.0.0', share=False, server_port=7688) diff --git a/assets/banner/banner.png b/assets/banner/banner.png new file mode 100644 index 0000000000000000000000000000000000000000..f4d6d162ddfd10a34fcf5798fae9d137c33505d8 --- /dev/null +++ b/assets/banner/banner.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4fd9d7b4d711f9dcc928876cbf3c303fd9c34b6d82123f2ca7078ae797108400 +size 1051123 diff --git a/assets/banner/thumbnail.png b/assets/banner/thumbnail.png new file mode 100644 index 0000000000000000000000000000000000000000..5b0c730a732c0f998a2475badf99ae386e57f229 --- /dev/null +++ b/assets/banner/thumbnail.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03f0515be3f637da63e340f467a28fc98310d04d7e4748d2a597e7e211037a46 +size 3178964 diff --git a/assets/css/style.css b/assets/css/style.css new file mode 100644 index 0000000000000000000000000000000000000000..cbb014dc4d792f94df526411281dc16d31a2985a --- /dev/null +++ b/assets/css/style.css @@ -0,0 +1,71 @@ + +.baselayout { + background: url('https://img.alicdn.com/imgextra/i1/O1CN016hd0V91ilWY5Xr24B_!!6000000004453-2-tps-2882-256.png') no-repeat; +} + +#btn { + background-color: #336699; + color: white; +} + +#recBut { + background-color: #bb5252; + color: white; + width: 30%; + margin: auto; +} + +#btnSEG { + background-color: #D5F3F4; + color: black; +} + +#btnCHAT { + background-color: #B6DBF2; + color: black; +} + +#accordion { + background-color: transparent; +} + +#accordion1 { + background-color: #ecedee; +} + +.feedback button.selected { + background-color: #6699CC; + color: white !important; +} + +.feedback1 button.selected { + background-color: #839ab2; + color: white !important; +} + +.Tab button.selected { + color: red; + font-weight: bold; +} + +#Image { + width: 80%; + margin: auto; +} + +#ShowCase { + width: 30%; + flex: none !important; +} + +#Input { + border-style: solid; + border-width: 1px; + border-color: #000000 +} + +#Seg { + min-width: min(100px, 100%) !important; + width: 100%; + margin: auto; +} diff --git a/assets/examples/00_layout.png b/assets/examples/00_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..9b7eec8e7ef41790417a91bd01f06565ba34ed61 Binary files /dev/null and b/assets/examples/00_layout.png differ diff --git a/assets/examples/01_layout.png b/assets/examples/01_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..de36e4e8bedcbb6448375fda63b9f15e30030169 Binary files /dev/null and b/assets/examples/01_layout.png differ diff --git a/assets/examples/02_style.png b/assets/examples/02_style.png new file mode 100644 index 0000000000000000000000000000000000000000..4b209710ec03e1f51af1547ffce894a592b6a713 Binary files /dev/null and b/assets/examples/02_style.png differ diff --git a/assets/examples/03_style.png b/assets/examples/03_style.png new file mode 100644 index 0000000000000000000000000000000000000000..a84d1fd2997e5a5a15498d01835364ef74beb8e2 Binary files /dev/null and b/assets/examples/03_style.png differ diff --git a/assets/examples/04_color.png b/assets/examples/04_color.png new file mode 100644 index 0000000000000000000000000000000000000000..710945e92801cf70af709c95da432700a2167837 Binary files /dev/null and b/assets/examples/04_color.png differ diff --git a/assets/examples/05_color.png b/assets/examples/05_color.png new file mode 100644 index 0000000000000000000000000000000000000000..e7c62d94cf04a53e27effaa387a1ca76b81f2845 Binary files /dev/null and b/assets/examples/05_color.png differ diff --git a/assets/examples/06_layout.png b/assets/examples/06_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..c171529bcea994b94998f0cad32680922e9f4d76 Binary files /dev/null and b/assets/examples/06_layout.png differ diff --git a/assets/examples/06_style.jpeg b/assets/examples/06_style.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..d40df1aa2d857f01ca49e31b024ad93353cf37ff Binary files /dev/null and b/assets/examples/06_style.jpeg differ diff --git a/assets/examples/07_layout.jpeg b/assets/examples/07_layout.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..af541418880609e7e95996a85652e453171ff9a4 Binary files /dev/null and b/assets/examples/07_layout.jpeg differ diff --git a/assets/examples/07_style.jpeg b/assets/examples/07_style.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..798114bb12059aee052f626440df1805ccb48536 Binary files /dev/null and b/assets/examples/07_style.jpeg differ diff --git a/assets/examples/08_color.jpeg b/assets/examples/08_color.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..9d5d592efae487e193faf522661beed3328a2d21 Binary files /dev/null and b/assets/examples/08_color.jpeg differ diff --git a/assets/examples/08_style.png b/assets/examples/08_style.png new file mode 100644 index 0000000000000000000000000000000000000000..bf7f087c395de99dc3250acc27b6ab7809bc4192 Binary files /dev/null and b/assets/examples/08_style.png differ diff --git a/assets/examples/09_base.png b/assets/examples/09_base.png new file mode 100644 index 0000000000000000000000000000000000000000..1be92d9152ea2883a5877c45904bc181df97b4e3 Binary files /dev/null and b/assets/examples/09_base.png differ diff --git a/assets/examples/09_style.png b/assets/examples/09_style.png new file mode 100644 index 0000000000000000000000000000000000000000..9180e5c3fba4a53f2914cc1b86ea9d40030bc788 Binary files /dev/null and b/assets/examples/09_style.png differ diff --git a/assets/examples/10_base.png b/assets/examples/10_base.png new file mode 100644 index 0000000000000000000000000000000000000000..51467bb839c631c94ddc6dcb29dc1c03cd072238 Binary files /dev/null and b/assets/examples/10_base.png differ diff --git a/assets/examples/10_layout.png b/assets/examples/10_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..d162a841aab73752931204429aa7e4cde5c92d96 Binary files /dev/null and b/assets/examples/10_layout.png differ diff --git a/assets/examples/10_style.png b/assets/examples/10_style.png new file mode 100644 index 0000000000000000000000000000000000000000..af0c382da7a63ea0eb863b1f388ee041cd24cedc Binary files /dev/null and b/assets/examples/10_style.png differ diff --git a/assets/examples/11_base.png b/assets/examples/11_base.png new file mode 100644 index 0000000000000000000000000000000000000000..967231961afdca2bb1f3386cdbfa52eb251ae0ff Binary files /dev/null and b/assets/examples/11_base.png differ diff --git a/assets/examples/11_layout.png b/assets/examples/11_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..3f2619e0e9348d33a91916a0f7a3e10db223eb06 --- /dev/null +++ b/assets/examples/11_layout.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98689f1b6e3bc8a4045496e4b2cf391e477effa434d3f7b4377dcbebcc720598 +size 1018779 diff --git a/assets/examples/12_base.png b/assets/examples/12_base.png new file mode 100644 index 0000000000000000000000000000000000000000..0b4e5cce7149559f82394dd8f14aeadb066a8835 Binary files /dev/null and b/assets/examples/12_base.png differ diff --git a/assets/examples/12_layout.png b/assets/examples/12_layout.png new file mode 100644 index 0000000000000000000000000000000000000000..443fbd18d7d870517ea906fc0c80f5f35f0dc317 Binary files /dev/null and b/assets/examples/12_layout.png differ diff --git a/assets/examples/base_image1.jpeg b/assets/examples/base_image1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c1a80f97ec157a83bf6424d14166bcae7560b6d0 Binary files /dev/null and b/assets/examples/base_image1.jpeg differ diff --git a/assets/examples/base_image2.png b/assets/examples/base_image2.png new file mode 100644 index 0000000000000000000000000000000000000000..14b59004cccf331a6da1c9444601b6da09e95879 Binary files /dev/null and b/assets/examples/base_image2.png differ diff --git a/assets/examples/base_image3.png b/assets/examples/base_image3.png new file mode 100644 index 0000000000000000000000000000000000000000..0b4e5cce7149559f82394dd8f14aeadb066a8835 Binary files /dev/null and b/assets/examples/base_image3.png differ diff --git a/assets/examples/base_image4.png b/assets/examples/base_image4.png new file mode 100644 index 0000000000000000000000000000000000000000..967231961afdca2bb1f3386cdbfa52eb251ae0ff Binary files /dev/null and b/assets/examples/base_image4.png differ diff --git a/assets/examples/color_image1.jpeg b/assets/examples/color_image1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c71c4be680a1588450af21281a16d9ec950a6258 Binary files /dev/null and b/assets/examples/color_image1.jpeg differ diff --git a/assets/examples/color_image2.jpeg b/assets/examples/color_image2.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..9d5d592efae487e193faf522661beed3328a2d21 Binary files /dev/null and b/assets/examples/color_image2.jpeg differ diff --git a/assets/examples/color_image3.jpeg b/assets/examples/color_image3.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..81fd65ea4f210a629d66e1d730c497233c359433 Binary files /dev/null and b/assets/examples/color_image3.jpeg differ diff --git a/assets/examples/color_image3_mask.png b/assets/examples/color_image3_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..54bf8bd9b7ae668b69368952d41df510f98c0ee5 Binary files /dev/null and b/assets/examples/color_image3_mask.png differ diff --git a/assets/examples/empty.png b/assets/examples/empty.png new file mode 100644 index 0000000000000000000000000000000000000000..e30ec31e4e12b52e579dcf606826e8d21cb19a03 Binary files /dev/null and b/assets/examples/empty.png differ diff --git a/assets/examples/layout_image1.jpeg b/assets/examples/layout_image1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..69e69e4f668b6ebe2ea68a80381d142f97d9cf0f Binary files /dev/null and b/assets/examples/layout_image1.jpeg differ diff --git a/assets/examples/layout_image1_mask.png b/assets/examples/layout_image1_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..4cfb70fcb266a15d67effb06da72748e2bc31e59 Binary files /dev/null and b/assets/examples/layout_image1_mask.png differ diff --git a/assets/examples/layout_image2.jpeg b/assets/examples/layout_image2.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..a8b0e6dcc1b7351f08bf12b547ad62f949d1ae78 Binary files /dev/null and b/assets/examples/layout_image2.jpeg differ diff --git a/assets/examples/layout_image3.jpeg b/assets/examples/layout_image3.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..af541418880609e7e95996a85652e453171ff9a4 Binary files /dev/null and b/assets/examples/layout_image3.jpeg differ diff --git a/assets/examples/layout_image5.jpeg b/assets/examples/layout_image5.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..e4da3d1618f8c301adb1a1e8b1efd78be34c4d87 Binary files /dev/null and b/assets/examples/layout_image5.jpeg differ diff --git a/assets/examples/layout_image5_mask.png b/assets/examples/layout_image5_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..475405cea1a756ccfe257b725530c067f1213b30 Binary files /dev/null and b/assets/examples/layout_image5_mask.png differ diff --git a/assets/examples/layout_image6.jpeg b/assets/examples/layout_image6.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..cd2e756e22806c20a7ab759db2d4cbb5beedb177 Binary files /dev/null and b/assets/examples/layout_image6.jpeg differ diff --git a/assets/examples/layout_image6_mask.png b/assets/examples/layout_image6_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..b41b47524f3cd0bc4905df9612d4cd8d6d0322e2 Binary files /dev/null and b/assets/examples/layout_image6_mask.png differ diff --git a/assets/examples/layout_image7.jpeg b/assets/examples/layout_image7.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..e7ca9339a5096e75773a1580236b692ccdca741c Binary files /dev/null and b/assets/examples/layout_image7.jpeg differ diff --git a/assets/examples/style_image1.jpeg b/assets/examples/style_image1.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c76b17b4ce63ee30395730de1b8ff6e158fa1c14 Binary files /dev/null and b/assets/examples/style_image1.jpeg differ diff --git a/assets/examples/style_image1_mask.png b/assets/examples/style_image1_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..4ce5f11cfc35f205f6377a3eee5b93a4c8508b5f Binary files /dev/null and b/assets/examples/style_image1_mask.png differ diff --git a/assets/examples/style_image1_mask2.png b/assets/examples/style_image1_mask2.png new file mode 100644 index 0000000000000000000000000000000000000000..3a587ca73dfcaac09600c044402ff044214e43e9 Binary files /dev/null and b/assets/examples/style_image1_mask2.png differ diff --git a/assets/examples/style_image2.jpeg b/assets/examples/style_image2.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..d40df1aa2d857f01ca49e31b024ad93353cf37ff Binary files /dev/null and b/assets/examples/style_image2.jpeg differ diff --git a/assets/examples/style_image3.jpeg b/assets/examples/style_image3.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..798114bb12059aee052f626440df1805ccb48536 Binary files /dev/null and b/assets/examples/style_image3.jpeg differ diff --git a/assets/examples/style_image4.jpeg b/assets/examples/style_image4.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..09002315425bbc18c94fa170c3186b1c89d688f9 Binary files /dev/null and b/assets/examples/style_image4.jpeg differ diff --git a/assets/examples/style_image5.jpeg b/assets/examples/style_image5.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..d9c7b132195e365f3fec4deb06b792d0c19f46e0 Binary files /dev/null and b/assets/examples/style_image5.jpeg differ diff --git a/assets/examples/style_image6.jpeg b/assets/examples/style_image6.jpeg new file mode 100644 index 0000000000000000000000000000000000000000..c5f2f0001c2801787f35c6a9ff2206e7b9b366d8 Binary files /dev/null and b/assets/examples/style_image6.jpeg differ diff --git a/assets/examples/style_image6_mask.png b/assets/examples/style_image6_mask.png new file mode 100644 index 0000000000000000000000000000000000000000..a03176bdfdcad6d772e5cfccbf1a604659a1fd21 Binary files /dev/null and b/assets/examples/style_image6_mask.png differ diff --git a/assets/image_gallery_en/--000.png b/assets/image_gallery_en/--000.png new file mode 100644 index 0000000000000000000000000000000000000000..28900c885a3489d7e8af282a98aeeaebf67011ec Binary files /dev/null and b/assets/image_gallery_en/--000.png differ diff --git a/assets/image_gallery_en/--001.png b/assets/image_gallery_en/--001.png new file mode 100644 index 0000000000000000000000000000000000000000..44dde03b2dea95cbbc5711c70babc3295e423dfc Binary files /dev/null and b/assets/image_gallery_en/--001.png differ diff --git a/assets/image_gallery_en/--002.png b/assets/image_gallery_en/--002.png new file mode 100644 index 0000000000000000000000000000000000000000..df8a202a26543004c482cc43bcea10fe56a1169e Binary files /dev/null and b/assets/image_gallery_en/--002.png differ diff --git a/assets/image_gallery_en/--003.png b/assets/image_gallery_en/--003.png new file mode 100644 index 0000000000000000000000000000000000000000..32fb540f54a627ee196e64452ab5e05160024829 Binary files /dev/null and b/assets/image_gallery_en/--003.png differ diff --git a/assets/image_gallery_en/-000.jpg b/assets/image_gallery_en/-000.jpg new file mode 100644 index 0000000000000000000000000000000000000000..419f665d718fc7f54fa61b759fe6b4a2b7e4bc70 Binary files /dev/null and b/assets/image_gallery_en/-000.jpg differ diff --git a/assets/image_gallery_en/-001.jpg b/assets/image_gallery_en/-001.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bbdb35e7602fc2773153ebe24493074c994b2af2 Binary files /dev/null and b/assets/image_gallery_en/-001.jpg differ diff --git a/assets/image_gallery_en/-002.jpg b/assets/image_gallery_en/-002.jpg new file mode 100644 index 0000000000000000000000000000000000000000..69c1a25b0007fdd7a6102aae64ce93f2625ff1eb Binary files /dev/null and b/assets/image_gallery_en/-002.jpg differ diff --git a/assets/image_gallery_en/-003.jpg b/assets/image_gallery_en/-003.jpg new file mode 100644 index 0000000000000000000000000000000000000000..50ed254390bebf2bd27c98059b48c32b7ef4b02a Binary files /dev/null and b/assets/image_gallery_en/-003.jpg differ diff --git a/assets/image_gallery_en/-004.jpg b/assets/image_gallery_en/-004.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1d321b7843c930ffeb80d4d25c72a70bd84cf67e Binary files /dev/null and b/assets/image_gallery_en/-004.jpg differ diff --git a/assets/image_gallery_en/-005.jpg b/assets/image_gallery_en/-005.jpg new file mode 100644 index 0000000000000000000000000000000000000000..bdb36744bcc035f315675df13ebbbe6279d970ff Binary files /dev/null and b/assets/image_gallery_en/-005.jpg differ diff --git a/assets/image_gallery_en/-006.jpg b/assets/image_gallery_en/-006.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a3ee6fb4b0b37550045d55d2ef343743ce5ae491 Binary files /dev/null and b/assets/image_gallery_en/-006.jpg differ diff --git a/assets/image_gallery_en/-007.jpg b/assets/image_gallery_en/-007.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0afdddbfd9ae5af8a8b07b57166149d33aac98d3 Binary files /dev/null and b/assets/image_gallery_en/-007.jpg differ diff --git a/assets/image_gallery_en/-008.jpg b/assets/image_gallery_en/-008.jpg new file mode 100644 index 0000000000000000000000000000000000000000..85237ed59a0438385091b01b56fae2eae7070abb Binary files /dev/null and b/assets/image_gallery_en/-008.jpg differ diff --git a/assets/image_gallery_en/-009.jpg b/assets/image_gallery_en/-009.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e7a68426ec51e753c803f5336de8defbe4f3bad8 Binary files /dev/null and b/assets/image_gallery_en/-009.jpg differ diff --git a/assets/image_gallery_en/-010.jpg b/assets/image_gallery_en/-010.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f282ee9e641b6f1401469f3ca24f1a7152e8f911 Binary files /dev/null and b/assets/image_gallery_en/-010.jpg differ diff --git a/assets/image_gallery_en/-011.jpg b/assets/image_gallery_en/-011.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7a1aff069abf126262e8d5652c0f605f4d7fde82 Binary files /dev/null and b/assets/image_gallery_en/-011.jpg differ diff --git a/assets/image_gallery_en/-012.jpg b/assets/image_gallery_en/-012.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1f4522e1744600de310b17b4d4231b73022c861d Binary files /dev/null and b/assets/image_gallery_en/-012.jpg differ diff --git a/assets/image_gallery_en/-013.jpg b/assets/image_gallery_en/-013.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d777583d0747ae50dde508da15a21c83af137367 Binary files /dev/null and b/assets/image_gallery_en/-013.jpg differ diff --git a/assets/image_gallery_en/-014.jpg b/assets/image_gallery_en/-014.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a7a32d0781fefe24365e651b5c3250469a44c37c Binary files /dev/null and b/assets/image_gallery_en/-014.jpg differ diff --git a/assets/image_gallery_en/-015.jpg b/assets/image_gallery_en/-015.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ceb5cd31c04e61ee7beceabee02e6e7874fc9f58 Binary files /dev/null and b/assets/image_gallery_en/-015.jpg differ diff --git a/assets/image_gallery_en/-016.jpg b/assets/image_gallery_en/-016.jpg new file mode 100644 index 0000000000000000000000000000000000000000..97e25c76f614a783d0642e3f3d2b07eda644be5b Binary files /dev/null and b/assets/image_gallery_en/-016.jpg differ diff --git a/assets/image_gallery_en/-017.jpg b/assets/image_gallery_en/-017.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5119ef15354e55b17e0c0d10b62fb8500a6a3e4f --- /dev/null +++ b/assets/image_gallery_en/-017.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:458f29692496982efc18c1c3bd71142dec8c58e820351dff7601ef018c834021 +size 1328428 diff --git a/assets/image_gallery_en/-018.jpg b/assets/image_gallery_en/-018.jpg new file mode 100644 index 0000000000000000000000000000000000000000..7d0dea32c9405e7d70b1da324d993659d061b7d4 Binary files /dev/null and b/assets/image_gallery_en/-018.jpg differ diff --git a/assets/image_gallery_en/-019.jpg b/assets/image_gallery_en/-019.jpg new file mode 100644 index 0000000000000000000000000000000000000000..01d100d82b53ab07a2ade455fb26755db4f53a6d Binary files /dev/null and b/assets/image_gallery_en/-019.jpg differ diff --git a/assets/image_gallery_en/.DS_Store b/assets/image_gallery_en/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..55f2180a5ebf8d968341bf1d6863e2e6053bc550 Binary files /dev/null and b/assets/image_gallery_en/.DS_Store differ diff --git a/assets/image_gallery_en/004.jpg b/assets/image_gallery_en/004.jpg new file mode 100644 index 0000000000000000000000000000000000000000..be2e8f0fdda87ca0b8f086a57f393baad04871a7 Binary files /dev/null and b/assets/image_gallery_en/004.jpg differ diff --git a/assets/image_gallery_en/005.jpg b/assets/image_gallery_en/005.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d02c36e926728e0d8666628483c5d5fa81ff9623 Binary files /dev/null and b/assets/image_gallery_en/005.jpg differ diff --git a/assets/image_gallery_en/006.jpg b/assets/image_gallery_en/006.jpg new file mode 100644 index 0000000000000000000000000000000000000000..10c3a896248ca3d936656e8a3e839fbdc6892b2b Binary files /dev/null and b/assets/image_gallery_en/006.jpg differ diff --git a/assets/image_gallery_en/007.jpg b/assets/image_gallery_en/007.jpg new file mode 100644 index 0000000000000000000000000000000000000000..c608974051f2896be0c10cb9184b270496425a4c Binary files /dev/null and b/assets/image_gallery_en/007.jpg differ diff --git a/assets/image_gallery_en/008.jpg b/assets/image_gallery_en/008.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d5ecf786b45c9d74cc1125a997999c632adeab46 Binary files /dev/null and b/assets/image_gallery_en/008.jpg differ diff --git a/assets/image_gallery_en/009.jpg b/assets/image_gallery_en/009.jpg new file mode 100644 index 0000000000000000000000000000000000000000..69599a25eef4dc52d76b561cfde968d866dfab66 Binary files /dev/null and b/assets/image_gallery_en/009.jpg differ diff --git a/assets/image_gallery_en/010.jpg b/assets/image_gallery_en/010.jpg new file mode 100644 index 0000000000000000000000000000000000000000..aa4a001105422340e33ef321a9e39bac8dd53b16 Binary files /dev/null and b/assets/image_gallery_en/010.jpg differ diff --git a/assets/image_gallery_en/011.jpg b/assets/image_gallery_en/011.jpg new file mode 100644 index 0000000000000000000000000000000000000000..89c0341e74bf726b9c0c06cfe58e1630d8b92ae0 Binary files /dev/null and b/assets/image_gallery_en/011.jpg differ diff --git a/assets/image_gallery_en/012.jpg b/assets/image_gallery_en/012.jpg new file mode 100644 index 0000000000000000000000000000000000000000..be7c3c2525c743735f9a0fad8e883a39a33fe632 Binary files /dev/null and b/assets/image_gallery_en/012.jpg differ diff --git a/assets/image_gallery_en/013.jpg b/assets/image_gallery_en/013.jpg new file mode 100644 index 0000000000000000000000000000000000000000..463cd750bd60b6052de3e7d069822fbc35986be0 Binary files /dev/null and b/assets/image_gallery_en/013.jpg differ diff --git a/assets/image_gallery_en/014.jpg b/assets/image_gallery_en/014.jpg new file mode 100644 index 0000000000000000000000000000000000000000..a6a8eda2dccfd2a177ac82e07943e0b63233e6f4 Binary files /dev/null and b/assets/image_gallery_en/014.jpg differ diff --git a/assets/image_gallery_en/015.jpg b/assets/image_gallery_en/015.jpg new file mode 100644 index 0000000000000000000000000000000000000000..db6fc03b35e18e60f491eaa0a4746ed2ffa3d824 Binary files /dev/null and b/assets/image_gallery_en/015.jpg differ diff --git a/assets/image_gallery_en/016.jpg b/assets/image_gallery_en/016.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e5b1c2b45579572404ca82bc022b8bfc72b08691 Binary files /dev/null and b/assets/image_gallery_en/016.jpg differ diff --git a/assets/image_gallery_en/017.jpg b/assets/image_gallery_en/017.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0cb109bdcfdd4934e4b2b179e9a36bc75681e4f1 Binary files /dev/null and b/assets/image_gallery_en/017.jpg differ diff --git a/assets/image_gallery_en/018.jpg b/assets/image_gallery_en/018.jpg new file mode 100644 index 0000000000000000000000000000000000000000..841fd253f7af12984dd061aa851b632a65152273 Binary files /dev/null and b/assets/image_gallery_en/018.jpg differ diff --git a/assets/image_gallery_en/019.jpg b/assets/image_gallery_en/019.jpg new file mode 100644 index 0000000000000000000000000000000000000000..43c7daedbd4a90c43a36d40ea2d9305e65696e77 Binary files /dev/null and b/assets/image_gallery_en/019.jpg differ diff --git a/assets/image_gallery_en/020.jpg b/assets/image_gallery_en/020.jpg new file mode 100644 index 0000000000000000000000000000000000000000..47ab0d42a6b79147a7e4cfe910dfcadf0c2a6c3a Binary files /dev/null and b/assets/image_gallery_en/020.jpg differ diff --git a/assets/image_gallery_en/021.jpg b/assets/image_gallery_en/021.jpg new file mode 100644 index 0000000000000000000000000000000000000000..40c1d628059932f9ee3a34d9b7181727a2a56f7c Binary files /dev/null and b/assets/image_gallery_en/021.jpg differ diff --git a/assets/image_gallery_en/022.jpg b/assets/image_gallery_en/022.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8cbd3cf47c860476c9b77ec8b9746ff736159920 Binary files /dev/null and b/assets/image_gallery_en/022.jpg differ diff --git a/assets/image_gallery_en/023.jpg b/assets/image_gallery_en/023.jpg new file mode 100644 index 0000000000000000000000000000000000000000..67a834bf59c1398039f9ba740d55c403b8e42c3b Binary files /dev/null and b/assets/image_gallery_en/023.jpg differ diff --git a/assets/image_gallery_en/024.jpg b/assets/image_gallery_en/024.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ed1f63d123da48257322c533662aa89638c19b1d Binary files /dev/null and b/assets/image_gallery_en/024.jpg differ diff --git a/assets/image_gallery_en/025.jpg b/assets/image_gallery_en/025.jpg new file mode 100644 index 0000000000000000000000000000000000000000..5b8babe7a36d10e7cb533f6920b7b927c362fde9 Binary files /dev/null and b/assets/image_gallery_en/025.jpg differ diff --git a/assets/image_gallery_en/026.jpg b/assets/image_gallery_en/026.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1bc82d268aa4d6b85b25a8de0c899f81b416d36f Binary files /dev/null and b/assets/image_gallery_en/026.jpg differ diff --git a/assets/image_gallery_en/027.jpg b/assets/image_gallery_en/027.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3917507fe82971c192d1da2d75d38040ca46309e Binary files /dev/null and b/assets/image_gallery_en/027.jpg differ diff --git a/assets/image_gallery_en/028.jpg b/assets/image_gallery_en/028.jpg new file mode 100644 index 0000000000000000000000000000000000000000..3d46ce3ebd83d076fa20b1e3e2a439b519223297 Binary files /dev/null and b/assets/image_gallery_en/028.jpg differ diff --git a/assets/image_gallery_en/029.jpg b/assets/image_gallery_en/029.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ca65c8a589d377b2d68a67a38a6b3eda4937d28d Binary files /dev/null and b/assets/image_gallery_en/029.jpg differ diff --git a/assets/image_gallery_en/030.jpg b/assets/image_gallery_en/030.jpg new file mode 100644 index 0000000000000000000000000000000000000000..12889b08bff2d42b6932d5548e9ab4c2d8ce2e23 Binary files /dev/null and b/assets/image_gallery_en/030.jpg differ diff --git a/assets/image_gallery_en/031.jpg b/assets/image_gallery_en/031.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cf12e6911a683e6bf72656063bed10765463989d Binary files /dev/null and b/assets/image_gallery_en/031.jpg differ diff --git a/assets/image_gallery_en/032.jpg b/assets/image_gallery_en/032.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9e14e88a87e94d72ebda8fd9a3438bf42319e03d Binary files /dev/null and b/assets/image_gallery_en/032.jpg differ diff --git a/assets/image_gallery_en/033.jpg b/assets/image_gallery_en/033.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b9bb1b205cb5049b51cf04b21177eae1d7d4c4d6 Binary files /dev/null and b/assets/image_gallery_en/033.jpg differ diff --git a/assets/image_gallery_en/034.jpg b/assets/image_gallery_en/034.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ad92357d17d799f3fc2c6a87866598f5352e33f5 Binary files /dev/null and b/assets/image_gallery_en/034.jpg differ diff --git a/assets/image_gallery_en/035.jpg b/assets/image_gallery_en/035.jpg new file mode 100644 index 0000000000000000000000000000000000000000..271c2c2d8efdff1ea4ea117f0d1deec60a6cff3b Binary files /dev/null and b/assets/image_gallery_en/035.jpg differ diff --git a/assets/image_gallery_en/036.jpg b/assets/image_gallery_en/036.jpg new file mode 100644 index 0000000000000000000000000000000000000000..135819ed1c93bd5f7dc08701b86c96e3c0e73d70 Binary files /dev/null and b/assets/image_gallery_en/036.jpg differ diff --git a/assets/image_gallery_en/040.jpg b/assets/image_gallery_en/040.jpg new file mode 100644 index 0000000000000000000000000000000000000000..6fedac4476b9e7815fa5a52bd3f659599b197a7c Binary files /dev/null and b/assets/image_gallery_en/040.jpg differ diff --git a/assets/image_gallery_en/041.jpg b/assets/image_gallery_en/041.jpg new file mode 100644 index 0000000000000000000000000000000000000000..b2b45156a60d1ec82e056bc93cacdf1147474bcb Binary files /dev/null and b/assets/image_gallery_en/041.jpg differ diff --git a/assets/image_gallery_en/042.jpg b/assets/image_gallery_en/042.jpg new file mode 100644 index 0000000000000000000000000000000000000000..1b0c37c48de01838a11a2e5f24f558a054f0cda1 Binary files /dev/null and b/assets/image_gallery_en/042.jpg differ diff --git a/assets/image_gallery_en/044.jpg b/assets/image_gallery_en/044.jpg new file mode 100644 index 0000000000000000000000000000000000000000..20a3051c889c4de8d7d2e759561b7ee150681bb4 Binary files /dev/null and b/assets/image_gallery_en/044.jpg differ diff --git a/assets/image_gallery_en/045.jpg b/assets/image_gallery_en/045.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cc5a5e2c8777f684ded19f8bfe44f64dd4d1895b Binary files /dev/null and b/assets/image_gallery_en/045.jpg differ diff --git a/assets/image_gallery_en/046.jpg b/assets/image_gallery_en/046.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e4ee625f9eca7d80c561987f39e3865d0122f674 Binary files /dev/null and b/assets/image_gallery_en/046.jpg differ diff --git a/assets/image_gallery_en/047.jpg b/assets/image_gallery_en/047.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8301971f13e73c83ff2dc934eda3bd889805f6a6 Binary files /dev/null and b/assets/image_gallery_en/047.jpg differ diff --git a/assets/image_gallery_en/048.jpg b/assets/image_gallery_en/048.jpg new file mode 100644 index 0000000000000000000000000000000000000000..76eaa959754359be4900b321fbc76de8cd255958 Binary files /dev/null and b/assets/image_gallery_en/048.jpg differ diff --git a/assets/image_gallery_en/049.jpg b/assets/image_gallery_en/049.jpg new file mode 100644 index 0000000000000000000000000000000000000000..f3c621852656ba5b5074a384c81cba77134af378 Binary files /dev/null and b/assets/image_gallery_en/049.jpg differ diff --git a/assets/image_gallery_en/050.jpg b/assets/image_gallery_en/050.jpg new file mode 100644 index 0000000000000000000000000000000000000000..68ce2f6601991cabbb1856d9d4dab8c95b40ccff Binary files /dev/null and b/assets/image_gallery_en/050.jpg differ diff --git a/assets/image_gallery_en/051.jpg b/assets/image_gallery_en/051.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2773d08ba5c0799efbdc14ed139c55c95bcc402b Binary files /dev/null and b/assets/image_gallery_en/051.jpg differ diff --git a/assets/image_gallery_en/052.jpg b/assets/image_gallery_en/052.jpg new file mode 100644 index 0000000000000000000000000000000000000000..56814f5941b3894b393cc81782442082713ca04e Binary files /dev/null and b/assets/image_gallery_en/052.jpg differ diff --git a/assets/image_gallery_en/053.jpg b/assets/image_gallery_en/053.jpg new file mode 100644 index 0000000000000000000000000000000000000000..67837605cab4cb6e41fc9bb875434f7852b61d16 Binary files /dev/null and b/assets/image_gallery_en/053.jpg differ diff --git a/assets/image_gallery_en/054.jpg b/assets/image_gallery_en/054.jpg new file mode 100644 index 0000000000000000000000000000000000000000..10788a2b05661e8454f7c372dd0c307c4d55224c Binary files /dev/null and b/assets/image_gallery_en/054.jpg differ diff --git a/assets/image_gallery_en/055.jpg b/assets/image_gallery_en/055.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e8c2ee736d6b063638d71fc5fa913e72b7393d32 Binary files /dev/null and b/assets/image_gallery_en/055.jpg differ diff --git a/assets/image_gallery_en/056.jpg b/assets/image_gallery_en/056.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4569c7ad9132442dfb0fbf456a4f775cdb3f3a50 Binary files /dev/null and b/assets/image_gallery_en/056.jpg differ diff --git a/assets/image_gallery_en/057.jpg b/assets/image_gallery_en/057.jpg new file mode 100644 index 0000000000000000000000000000000000000000..94870dedd1165e92aa3513361a6eed4d4e9fffe1 Binary files /dev/null and b/assets/image_gallery_en/057.jpg differ diff --git a/assets/image_gallery_en/058.jpg b/assets/image_gallery_en/058.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0d07ad94f49231286b56349a75721df703457353 Binary files /dev/null and b/assets/image_gallery_en/058.jpg differ diff --git a/assets/image_gallery_en/059.jpg b/assets/image_gallery_en/059.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2b07e6e8aff4bd4d6fed4644aa7b8d23bfcecf12 Binary files /dev/null and b/assets/image_gallery_en/059.jpg differ diff --git a/assets/image_gallery_en/060.jpg b/assets/image_gallery_en/060.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e80fccd71f2df9ee07bdb2456e30dbc8f933eb56 Binary files /dev/null and b/assets/image_gallery_en/060.jpg differ diff --git a/assets/image_gallery_en/061.jpg b/assets/image_gallery_en/061.jpg new file mode 100644 index 0000000000000000000000000000000000000000..37cde8ac64f64b8a4bf2f0127a79dd53962b5fff Binary files /dev/null and b/assets/image_gallery_en/061.jpg differ diff --git a/assets/image_gallery_en/062.jpg b/assets/image_gallery_en/062.jpg new file mode 100644 index 0000000000000000000000000000000000000000..49a7d009c1967b25db6eb421836214c6b1eb0114 --- /dev/null +++ b/assets/image_gallery_en/062.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4ede8d6be9b34524b951924546615931cfa5ee63601d4143172071bcd72e398 +size 1213175 diff --git a/assets/image_gallery_en/063.jpg b/assets/image_gallery_en/063.jpg new file mode 100644 index 0000000000000000000000000000000000000000..639857b8060a42dd03d0c3261d6b46868696a0cd Binary files /dev/null and b/assets/image_gallery_en/063.jpg differ diff --git a/assets/image_gallery_en/064.jpg b/assets/image_gallery_en/064.jpg new file mode 100644 index 0000000000000000000000000000000000000000..425e01eff7ccaf77c8acdf2478cd043f53e3644d Binary files /dev/null and b/assets/image_gallery_en/064.jpg differ diff --git a/assets/image_gallery_en/065.jpg b/assets/image_gallery_en/065.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4c48497ee11b9d0265eadf349a26dbf833e68b2c Binary files /dev/null and b/assets/image_gallery_en/065.jpg differ diff --git a/assets/image_gallery_en/066.jpg b/assets/image_gallery_en/066.jpg new file mode 100644 index 0000000000000000000000000000000000000000..2308cb72e34ee9d02bb751ec33cad87e06bda47d Binary files /dev/null and b/assets/image_gallery_en/066.jpg differ diff --git a/assets/image_gallery_en/067.jpg b/assets/image_gallery_en/067.jpg new file mode 100644 index 0000000000000000000000000000000000000000..572a245647359e63e701ab823c413780377326d0 Binary files /dev/null and b/assets/image_gallery_en/067.jpg differ diff --git a/assets/image_gallery_en/068.jpg b/assets/image_gallery_en/068.jpg new file mode 100644 index 0000000000000000000000000000000000000000..eb4f6504f64f444bb102516154481324f6bce83b Binary files /dev/null and b/assets/image_gallery_en/068.jpg differ diff --git a/assets/image_gallery_en/073.jpg b/assets/image_gallery_en/073.jpg new file mode 100644 index 0000000000000000000000000000000000000000..8db5e7192d10552a242d5a87ba6556947b348116 Binary files /dev/null and b/assets/image_gallery_en/073.jpg differ diff --git a/assets/image_gallery_en/099.jpg b/assets/image_gallery_en/099.jpg new file mode 100644 index 0000000000000000000000000000000000000000..d5661b195b021b660fbfd616cfe79b3b0719be93 Binary files /dev/null and b/assets/image_gallery_en/099.jpg differ diff --git a/assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf b/assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf new file mode 100644 index 0000000000000000000000000000000000000000..a69c54d70f45c534e5db8e03e3aabc5993115719 --- /dev/null +++ b/assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a22ad467d9d6b4c9a0b2e033927ed41592743c987546a7397215ce96b850743b +size 8449680 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..9d46b3678057352bd2390c2c2882f51a9211b125 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +dashscope +modelscope[cv] -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html +tensorflow-gpu==2.11.0 diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/generation.py b/src/generation.py new file mode 100644 index 0000000000000000000000000000000000000000..3e2e2100bcda8e90c271aec148218deb49c63fa8 --- /dev/null +++ b/src/generation.py @@ -0,0 +1,101 @@ +import json +import os +import time + +import gradio as gr +import requests + +from src.log import logger +from src.util import download_images + + +def call_generation(base_image_url="", layout_image_url="", color_image_url="", style_image_url="", + strict_edge=0, layout_scale=8, edge_consistency=8, color_scale=8, + style_scale=8, prompt="", negative_prompt="", output_aspect_ratio=1.0): + API_KEY = os.getenv("API_KEY_BG_GENERATION") + if output_aspect_ratio >= 1: + BATCH_SIZE = 2 + REPEAT = 2 + else: + BATCH_SIZE = 4 + REPEAT = 1 + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "Authorization": f"Bearer {API_KEY}", + "X-DashScope-Async": "enable", + } + data = { + "model": "wanx-poster-imitation-v1", + "input": { + "base_image_url": base_image_url, + "layout_image_url": layout_image_url, + "color_image_url": color_image_url, + "style_image_url": style_image_url, + "prompt": prompt, + "negative_prompt": negative_prompt, + }, + "parameters": { + "strict_layout": strict_edge, + "layout_scale": layout_scale, + "layout_spatial_consistency": edge_consistency, + "color_scale": color_scale, + "style_scale": style_scale, + "n": BATCH_SIZE + } + } + url_create_task = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/poster-imitation/generation' + + all_res_ = [] + for _ in range(REPEAT): + res_ = requests.post(url_create_task, data=json.dumps(data), headers=headers) + all_res_.append(res_) + + all_image_data = [] + for res_ in all_res_: + respose_code = res_.status_code + if 200 == respose_code: + res = json.loads(res_.content.decode()) + request_id = res['request_id'] + task_id = res['output']['task_id'] + logger.info(f"task_id: {task_id}: Create Poster Imitation request success. Params: {data}") + + # 异步查询 + is_running = True + while is_running: + url_query = f'https://dashscope.aliyuncs.com/api/v1/tasks/{task_id}' + res_ = requests.post(url_query, headers=headers) + respose_code = res_.status_code + if 200 == respose_code: + res = json.loads(res_.content.decode()) + if "SUCCEEDED" == res['output']['task_status']: + logger.info(f"task_id: {task_id}: Generation task query success.") + results = res['output']['results'] + img_urls = [x['url'] for x in results] + logger.info(f"task_id: {task_id}: {res}") + break + elif "FAILED" != res['output']['task_status']: + logger.debug(f"task_id: {task_id}: query result...") + time.sleep(1) + else: + raise gr.Error('Fail to get results from Generation task.') + + else: + logger.error(f'task_id: {task_id}: Fail to query task result: {res_.content}') + raise gr.Error("Fail to query task result.") + + logger.info(f"task_id: {task_id}: download generated images.") + img_data = download_images(img_urls, BATCH_SIZE) + logger.info(f"task_id: {task_id}: Generate done.") + all_image_data += img_data + else: + logger.error(f'Fail to create Generation task: {res_.content}') + raise gr.Error("Fail to create Generation task.") + + if len(all_image_data) != REPEAT * BATCH_SIZE: + raise gr.Error("Fail to Generation.") + return all_image_data + + +if __name__ == "__main__": + call_generation() diff --git a/src/log.py b/src/log.py new file mode 100644 index 0000000000000000000000000000000000000000..044070382a8577aea1ec5f05d3d7681ae94feff1 --- /dev/null +++ b/src/log.py @@ -0,0 +1,18 @@ +import logging +import os +from logging.handlers import RotatingFileHandler + +log_file_name = "workdir/log_transferAnything.log" +os.makedirs(os.path.dirname(log_file_name), exist_ok=True) + +format = '[%(levelname)s] %(asctime)s "%(filename)s", line %(lineno)d, %(message)s' +logging.basicConfig( + format=format, + datefmt="%Y-%m-%d %H:%M:%S", + level=logging.INFO) +logger = logging.getLogger(name="WordArt_Studio") + +fh = RotatingFileHandler(log_file_name, maxBytes=20000000, backupCount=3) +formatter = logging.Formatter(format, datefmt="%Y-%m-%d %H:%M:%S") +fh.setFormatter(formatter) +logger.addHandler(fh) diff --git a/src/util.py b/src/util.py new file mode 100644 index 0000000000000000000000000000000000000000..5b8bb9deea307659f76088e0770c86392b98c6de --- /dev/null +++ b/src/util.py @@ -0,0 +1,251 @@ +import concurrent.futures +import io +import os + +import numpy as np +import oss2 +import requests +from PIL import Image, ImageDraw, ImageFont + +from .log import logger + +# oss +access_key_id = os.getenv("ACCESS_KEY_ID") +access_key_secret = os.getenv("ACCESS_KEY_SECRET") +bucket_name = os.getenv("BUCKET_NAME") +endpoint = os.getenv("ENDPOINT") + +bucket = oss2.Bucket(oss2.Auth(access_key_id, access_key_secret), endpoint, bucket_name) +oss_path = "hejunjie.hjj/TransferAnythingHF" +oss_path_img_gallery = "hejunjie.hjj/TransferAnythingHF_img_gallery" + + +def download_img_pil(index, img_url): + # print(img_url) + r = requests.get(img_url, stream=True) + if r.status_code == 200: + img = Image.open(io.BytesIO(r.content)) + return (index, img) + else: + logger.error(f"Fail to download: {img_url}") + + +def download_images(img_urls, batch_size): + imgs_pil = [None] * batch_size + # worker_results = [] + with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor: + to_do = [] + for i, url in enumerate(img_urls): + future = executor.submit(download_img_pil, i, url) + to_do.append(future) + + for future in concurrent.futures.as_completed(to_do): + ret = future.result() + # worker_results.append(ret) + index, img_pil = ret + imgs_pil[index] = img_pil # 按顺序排列url,后续下载关联的图片或者svg需要使用 + + return imgs_pil + + +def upload_np_2_oss(input_image, name="cache.png", gallery=False): + assert name.lower().endswith((".png", ".jpg")), name + imgByteArr = io.BytesIO() + if name.lower().endswith(".png"): + Image.fromarray(input_image).save(imgByteArr, format="PNG") + else: + Image.fromarray(input_image).save(imgByteArr, format="JPEG", quality=95) + imgByteArr = imgByteArr.getvalue() + + if gallery: + path = oss_path_img_gallery + else: + path = oss_path + + bucket.put_object(path + "/" + name, imgByteArr) # data为数据,可以是图片 + ret = bucket.sign_url('GET', path + "/" + name, 60 * 60 * 24) # 返回值为链接,参数依次为,方法/oss上文件路径/过期时间(s) + del imgByteArr + return ret + + +def upload_json_string_2_oss(jsonStr, name="cache.txt", gallery=False): + if gallery: + path = oss_path_img_gallery + else: + path = oss_path + + bucket.put_object(path + "/" + name, bytes(jsonStr, "utf-8")) # data为数据 + ret = bucket.sign_url('GET', path + "/" + name, 60 * 60 * 24) # 返回值为链接,参数依次为,方法/oss上文件路径/过期时间(s) + return ret + + +def upload_preprocess(pil_base_image_rgba, pil_layout_image_dict, pil_style_image_dict, pil_color_image_dict, + pil_fg_mask): + np_out_base_image = np_out_layout_image = np_out_style_image = np_out_color_image = None + + if pil_base_image_rgba is not None: + np_fg_image = np.array(pil_base_image_rgba)[..., :3] + np_fg_mask = np.expand_dims(np.array(pil_fg_mask).astype(float), axis=-1) / 255. + np_fg_mask = np_fg_mask * 0.5 + 0.5 + np_out_base_image = (np_fg_image * np_fg_mask + (1 - np_fg_mask) * np.array([0, 0, 255])).round().clip(0, + 255).astype( + np.uint8) + + if pil_layout_image_dict is not None: + np_layout_image = np.array(pil_layout_image_dict["image"].convert("RGBA")) + np_layout_image, np_layout_alpha = np_layout_image[..., :3], np_layout_image[..., 3] + np_layout_mask = np.array(pil_layout_image_dict["mask"].convert("L")) + np_layout_mask = ((np_layout_alpha > 127) * (np_layout_mask < 127)).astype(float)[..., None] + np_layout_mask = np_layout_mask * 0.5 + 0.5 + np_out_layout_image = ( + np_layout_image * np_layout_mask + (1 - np_layout_mask) * np.array([0, 0, 255])).round().clip(0, + 255).astype( + np.uint8) + + if pil_style_image_dict is not None: + np_style_image = np.array(pil_style_image_dict["image"].convert("RGBA")) + np_style_image, np_style_alpha = np_style_image[..., :3], np_style_image[..., 3] + np_style_mask = np.array(pil_style_image_dict["mask"].convert("L")) + np_style_mask = ((np_style_alpha > 127) * (np_style_mask < 127)).astype(float)[..., None] + np_style_mask = np_style_mask * 0.5 + 0.5 + np_out_style_image = ( + np_style_image * np_style_mask + (1 - np_style_mask) * np.array([0, 0, 255])).round().clip(0, + 255).astype( + np.uint8) + + if pil_color_image_dict is not None: + np_color_image = np.array(pil_color_image_dict["image"].convert("RGBA")) + np_color_image, np_color_alpha = np_color_image[..., :3], np_color_image[..., 3] + np_color_mask = np.array(pil_color_image_dict["mask"].convert("L")) + np_color_mask = ((np_color_alpha > 127) * (np_color_mask < 127)).astype(float)[..., None] + np_color_mask = np_color_mask * 0.5 + 0.5 + np_out_color_image = ( + np_color_image * np_color_mask + (1 - np_color_mask) * np.array([0, 0, 255])).round().clip(0, + 255).astype( + np.uint8) + + return np_out_base_image, np_out_layout_image, np_out_style_image, np_out_color_image + + +def pad_image(image, target_size): + iw, ih = image.size # 原始图像的尺寸 + w, h = target_size # 目标图像的尺寸 + scale = min(w / iw, h / ih) # 转换的最小比例 + # 保证长或宽,至少一个符合目标图像的尺寸 0.5保证四舍五入 + nw = int(iw * scale + 0.5) + nh = int(ih * scale + 0.5) + image = image.resize((nw, nh), Image.BICUBIC) # 更改图像尺寸,双立法插值效果很好 + new_image = Image.new('RGB', target_size, (255, 255, 255)) # 生成白色图像 + new_image.paste(image, ((w - nw) // 2, (h - nh) // 2)) # 将图像填充为中间图像,两侧为黑色的样式 + return new_image + + +def add_text(image, text): + w, h = image.size + text_image = image.copy() + text_image_draw = ImageDraw.Draw(text_image) + + ttf = ImageFont.truetype("assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf", int(h / 10)) + left, top, right, bottom = ttf.getbbox(text) + text_image_draw.rectangle((0, 0, right + left, bottom + top), fill=(255, 255, 255)) + + image = Image.blend(image, text_image, 0.5) + + image_draw = ImageDraw.Draw(image) + fillColor = (0, 0, 0, 255) # 文字颜色:黑色 + pos = (0, 0) # 文本左上角位置 (离左边界距离, 离上边界距离) + image_draw.text(pos, text, font=ttf, fill=fillColor) + return image.convert("RGB") + + +def compose_image(image_list, text_list, pil_size, nrow, ncol): + w, h = pil_size # 每张小图片大小 + + if len(image_list) > nrow * ncol: + raise ValueError("合成图片的参数和要求的数量不能匹配!") + + assert len(image_list) == len(text_list) + new_image_list = [] + new_text_list = [] + for image, text in zip(image_list, text_list): + if image is not None: + new_image_list.append(image) + new_text_list.append(text) + if len(new_image_list) == 1: + ncol = nrow = 1 + to_image = Image.new('RGB', (ncol * w, nrow * h), (255, 255, 255)) # 创建一个新图 + for y in range(1, nrow + 1): + for x in range(1, ncol + 1): + if ncol * (y - 1) + x - 1 < len(new_image_list): + from_image = new_image_list[ncol * (y - 1) + x - 1].resize((w, h), Image.BICUBIC) + from_text = new_text_list[ncol * (y - 1) + x - 1] + if from_text is not None: + from_image = add_text(from_image, from_text) + to_image.paste(from_image, ((x - 1) * w, (y - 1) * h)) + return to_image + + +def split_text_lines(text, max_w, ttf): + text_split_lines = [] + text_h = 0 + if text != "": + line_start = 0 + while line_start < len(text): + line_count = 0 + _, _, right, bottom = ttf.getbbox(text[line_start: line_start + line_count + 1]) + while right < max_w and line_count < len(text): + line_count += 1 + _, _, right, bottom = ttf.getbbox(text[line_start: line_start + line_count + 1]) + text_split_lines.append(text[line_start:line_start + line_count]) + text_h += bottom + line_start += line_count + return text_split_lines, text_h + + +def add_prompt(image, prompt, negative_prompt): + if prompt == "" and negative_prompt == "": + return image + if prompt != "": + prompt = "Prompt: " + prompt + if negative_prompt != "": + negative_prompt = "Negative prompt: " + negative_prompt + + w, h = image.size + + ttf = ImageFont.truetype("assets/ttf/AlibabaPuHuiTi-2-55-Regular.ttf", int(h / 20)) + + prompt_split_lines, prompt_h = split_text_lines(prompt, w, ttf) + negative_prompt_split_lines, negative_prompt_h = split_text_lines(negative_prompt, w, ttf) + text_h = prompt_h + negative_prompt_h + text = "\n".join(prompt_split_lines + negative_prompt_split_lines) + text_image = Image.new(image.mode, (w, text_h), color=(255, 255, 255)) + text_image_draw = ImageDraw.Draw(text_image) + text_image_draw.text((0, 0), text, font=ttf, fill=(0, 0, 0)) + + out_image = Image.new(image.mode, (w, h + text_h), color=(255, 255, 255)) + out_image.paste(image, (0, 0)) + out_image.paste(text_image, (0, h)) + + return out_image + + +def merge_images(np_fg_image, np_layout_image, np_style_image, np_color_image, np_res_image, prompt, negative_prompt): + pil_res_image = Image.fromarray(np_res_image) + + w, h = pil_res_image.size + pil_fg_image = None if np_fg_image is None else pad_image(Image.fromarray(np_fg_image), (w, h)) + pil_layout_image = None if np_layout_image is None else pad_image(Image.fromarray(np_layout_image), (w, h)) + pil_style_image = None if np_style_image is None else pad_image(Image.fromarray(np_style_image), (w, h)) + pil_color_image = None if np_color_image is None else pad_image(Image.fromarray(np_color_image), (w, h)) + + input_images = [pil_layout_image, pil_style_image, pil_color_image, pil_fg_image] + input_texts = ['Layout', 'Style', 'Color', 'Subject'] + input_compose_image = compose_image(input_images, input_texts, (w, h), nrow=2, ncol=2) + input_compose_image = input_compose_image.resize((w, h), Image.BICUBIC) + output_compose_image = compose_image([input_compose_image, pil_res_image], [None, None], (w, h), nrow=1, + ncol=2) + output_compose_image = add_prompt(output_compose_image, prompt, negative_prompt) + + output_compose_image = np.array(output_compose_image) + + return output_compose_image