File size: 2,969 Bytes
6fc683c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from app_utils import *


def create_demo_ip2p(generation_fn):
    with gr.Blocks() as demo:
        with gr.Row():
            with gr.Column(scale=1):
                image = gr.Image(label="Control image")
                prompt = gr.Textbox(label="Prompt", max_lines=1,
                                    placeholder="Use <i> to represent the images in prompt")
                num_input_images = gr.Slider(1, MAX_INPUT_IMAGES, value=DEFAULT_INPUT_IMAGES, step=1,
                                             label="Number of input images:")
                input_images = [
                    gr.Image(label=f'img{i}', type="pil", visible=True if i < DEFAULT_INPUT_IMAGES else False)
                    for i in range(MAX_INPUT_IMAGES)]
                num_input_images.change(variable_images, num_input_images, input_images)

                seed = gr.Slider(label="Seed", minimum=MIN_SEED, maximum=MAX_SEED, step=1, value=0)
                randomize_seed = gr.Checkbox(label='Randomize seed', value=True)
                run_button = gr.Button(label="Run")
                with gr.Accordion("Advanced options", open=False):
                    num_inference_steps = gr.Slider(label="num_inference_steps", minimum=10, maximum=100, value=50,
                                                    step=5)
                    text_guidance_scale = gr.Slider(1, 15, value=6, step=0.5, label="Text Guidance Scale")
                    negative_prompt = gr.Textbox(label="Negative Prompt", max_lines=1,
                                                 value="")
                    num_images_per_prompt = gr.Slider(1, MAX_IMAGES_PER_PROMPT, value=DEFAULT_IMAGES_PER_PROMPT, step=1,
                                                      label="Number of Images")
                    image_resolution = gr.Slider(label='Image resolution', minimum=MIN_IMAGE_RESOLUTION,
                                                 maximum=MAX_IMAGE_RESOLUTION, value=DEFAULT_IMAGE_RESOLUTION, step=256)

            with gr.Column(scale=2):
                result_gallery = gr.Gallery(label='Output', show_label=False, elem_id="gallery", columns=2,
                                            height='100%')
        ips = [prompt, num_inference_steps, text_guidance_scale, negative_prompt, num_images_per_prompt, image,
               image_resolution, *input_images]

        prompt.submit(
            fn=randomize_seed_fn, inputs=[seed, randomize_seed], outputs=seed, queue=False, api_name=False
        ).then(fn=generation_fn, inputs=ips, outputs=result_gallery)

        run_button.click(
            fn=randomize_seed_fn, inputs=[seed, randomize_seed], outputs=seed, queue=False, api_name=False
        ).then(fn=generation_fn, inputs=ips, outputs=result_gallery)
        gr.Examples(
            examples=controlnet_example,
            inputs=[image, prompt, input_images[0], input_images[1]],
            cache_examples=False,
            examples_per_page=100
        )