File size: 3,943 Bytes
0ddf7c8
 
 
9891e0d
592e9ac
 
9891e0d
0ddf7c8
7ac53f8
0ddf7c8
 
 
 
 
 
22f3e80
f2b143d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ddf7c8
 
 
4f53bad
0ddf7c8
 
 
 
 
 
 
 
 
 
 
694c4dd
57b3d15
694c4dd
 
 
 
 
 
 
 
 
 
57b3d15
694c4dd
 
 
 
 
 
 
 
 
 
0ddf7c8
 
 
 
 
 
 
f2b143d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ddf7c8
 
f2b143d
0ddf7c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import gradio as gr
from diffusers.utils import load_image
import spaces
from panna.pipeline import PipelineLEditsPP


model = PipelineLEditsPP()
title = ("# [LEdits ++](https://huggingface.co/spaces/editing-images/leditsplusplus) with [Stable Diffusion XL](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0)\n"
         "The demo is part of [panna](https://github.com/asahi417/panna) project.")
example_files = []
for n in range(1, 10):
    load_image(f"https://huggingface.co/spaces/depth-anything/Depth-Anything-V2/resolve/main/assets/examples/demo{n:0>2}.jpg").save(f"demo{n:0>2}.jpg")
    example_files.append(f"demo{n:0>2}.jpg")


@spaces.GPU
def infer(init_image,
          add_prompt_1,
          add_prompt_2,
          add_prompt_3,
          remove_prompt_1,
          remove_prompt_2,
          remove_prompt_3,
          add_style_1,
          add_style_2,
          add_style_3,
          remove_style_1,
          remove_style_2,
          remove_style_3):
    edit_prompt = [add_prompt_1, add_prompt_2, add_prompt_3, remove_prompt_1, remove_prompt_2, remove_prompt_3]
    edit_style = [add_style_1, add_style_2, add_style_3, remove_style_1, remove_style_2, remove_style_3]
    reverse_editing_direction = [False, False, False, True, True, True]
    reverse_editing_direction = [x for x, y in zip(reverse_editing_direction, edit_prompt) if y]
    edit_style = [x for x, y in zip(edit_style, edit_prompt) if y]
    edit_prompt = [x for x in edit_prompt if x]
    print(edit_prompt)
    return model(
        init_image,
        edit_prompt=edit_prompt,
        reverse_editing_direction=reverse_editing_direction,
        edit_style=edit_style,
        seed=42
    )


with gr.Blocks() as demo:
    gr.Markdown(title)
    with gr.Column():
        gr.Markdown("<b>Add Concepts</b>")
        with gr.Row():
            with gr.Column():
                add_prompt_1 = gr.Text(label="Add concept")
                add_style_1 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
            with gr.Column():
                add_prompt_2 = gr.Text(label="Add concept")
                add_style_2 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
            with gr.Column():
                add_prompt_3 = gr.Text(label="Add concept")
                add_style_3 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
        gr.Markdown("<b>Remove Concepts</b>")
        with gr.Row():
            with gr.Column():
                remove_prompt_1 = gr.Text(label="Remove concept")
                remove_style_1 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
            with gr.Column():
                remove_prompt_2 = gr.Text(label="Remove concept")
                remove_style_2 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
            with gr.Column():
                remove_prompt_3 = gr.Text(label="Remove concept")
                remove_style_3 = gr.Dropdown(["default", "face", "style", "object"], value="default", label="Concept Style")
        run_button = gr.Button("Run")
    with gr.Row():
        init_image = gr.Image(label="Input Image", type='pil')
        result = gr.Image(label="Result")
    gr.on(
        triggers=[run_button.click],
        fn=infer,
        inputs=[
            init_image,
            add_prompt_1,
            add_prompt_2,
            add_prompt_3,
            remove_prompt_1,
            remove_prompt_2,
            remove_prompt_3,
            add_style_1,
            add_style_2,
            add_style_3,
            remove_style_1,
            remove_style_2,
            remove_style_3
        ],
        outputs=[result]
    )
    examples = gr.Examples(examples=example_files, inputs=[init_image])
demo.launch(server_name="0.0.0.0")