File size: 4,495 Bytes
5b29993
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from core.settings import MODEL_MAP_CHECKPOINT
from .ui_components import (
    create_base_parameter_ui, create_lora_settings_ui,
    create_controlnet_ui, create_ipadapter_ui, create_embedding_ui,
    create_conditioning_ui, create_vae_override_ui, create_api_key_ui
)

def create_ui():
    prefix = "inpaint"
    components = {}
    
    with gr.Column():
        with gr.Row() as model_and_run_row:
            components[f'base_model_{prefix}'] = gr.Dropdown(
                label="Base Model", 
                choices=list(MODEL_MAP_CHECKPOINT.keys()), 
                value=list(MODEL_MAP_CHECKPOINT.keys())[0], 
                scale=3
            )
            with gr.Column(scale=1): 
                components[f'run_{prefix}'] = gr.Button("Run Inpaint", variant="primary")
        
        components[f'model_and_run_row_{prefix}'] = model_and_run_row

        with gr.Row() as main_content_row:
            with gr.Column(scale=1) as editor_column:
                components[f'view_mode_{prefix}'] = gr.Radio(
                    ["Normal View", "Fullscreen View"], 
                    label="Editor View", 
                    value="Normal View", 
                    interactive=True
                )
                components[f'input_image_dict_{prefix}'] = gr.ImageEditor(
                    type="pil", 
                    label="Image & Mask", 
                    height=272
                )
            components[f'editor_column_{prefix}'] = editor_column

            with gr.Column(scale=2) as prompts_column:
                components[f'prompt_{prefix}'] = gr.Text(label="Prompt", lines=6, placeholder="Describe what to fill in the mask...")
                components[f'neg_prompt_{prefix}'] = gr.Text(label="Negative prompt", lines=6, value="monochrome, (low quality, worst quality:1.2), 3d, watermark, signature, ugly, poorly drawn,")
            components[f'prompts_column_{prefix}'] = prompts_column

        with gr.Row() as params_and_gallery_row:
            with gr.Column(scale=1):
                param_defaults = {'w': 1024, 'h': 1024, 'cs_vis': False, 'cs_val': 1}
                from comfy_integration.nodes import SAMPLER_CHOICES, SCHEDULER_CHOICES
                with gr.Row():
                    components[f'sampler_{prefix}'] = gr.Dropdown(label="Sampler", choices=SAMPLER_CHOICES, value=SAMPLER_CHOICES[0])
                    components[f'scheduler_{prefix}'] = gr.Dropdown(label="Scheduler", choices=SCHEDULER_CHOICES, value='normal' if 'normal' in SCHEDULER_CHOICES else SCHEDULER_CHOICES[0])
                with gr.Row():
                    components[f'steps_{prefix}'] = gr.Slider(label="Steps", minimum=1, maximum=100, step=1, value=28)
                    components[f'cfg_{prefix}'] = gr.Slider(label="CFG Scale", minimum=1.0, maximum=20.0, step=0.1, value=7.5)
                with gr.Row():
                    components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
                    components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
                with gr.Row():
                    components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")

                components[f'clip_skip_{prefix}'] = gr.State(value=1)
                components[f'width_{prefix}'] = gr.State(value=512)
                components[f'height_{prefix}'] = gr.State(value=512)

            with gr.Column(scale=1):
                components[f'result_{prefix}'] = gr.Gallery(label="Result", show_label=False, columns=1, object_fit="contain", height=414)
        
        components[f'params_and_gallery_row_{prefix}'] = params_and_gallery_row
            
        with gr.Column() as accordion_wrapper:
            components.update(create_api_key_ui(prefix))
            components.update(create_lora_settings_ui(prefix))
            components.update(create_controlnet_ui(prefix))
            components.update(create_ipadapter_ui(prefix))
            components.update(create_embedding_ui(prefix))
            components.update(create_conditioning_ui(prefix))
            components.update(create_vae_override_ui(prefix))
        components[f'accordion_wrapper_{prefix}'] = accordion_wrapper
            
    return components