File size: 5,139 Bytes
ef20d79
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import gradio as gr
from state import get_settings

app_settings = get_settings()


def on_change_inference_steps(steps):
    app_settings.settings.lcm_diffusion_setting.inference_steps = steps


def on_change_image_width(img_width):
    app_settings.settings.lcm_diffusion_setting.image_width = img_width


def on_change_image_height(img_height):
    app_settings.settings.lcm_diffusion_setting.image_height = img_height


def on_change_num_images(num_images):
    app_settings.settings.lcm_diffusion_setting.number_of_images = num_images


def on_change_guidance_scale(guidance_scale):
    app_settings.settings.lcm_diffusion_setting.guidance_scale = guidance_scale


def on_change_seed_value(seed):
    app_settings.settings.lcm_diffusion_setting.seed = seed


def on_change_seed_checkbox(seed_checkbox):
    app_settings.settings.lcm_diffusion_setting.use_seed = seed_checkbox


def on_change_safety_checker_checkbox(safety_checker_checkbox):
    app_settings.settings.lcm_diffusion_setting.use_safety_checker = (
        safety_checker_checkbox
    )


def on_change_tiny_auto_encoder_checkbox(tiny_auto_encoder_checkbox):
    app_settings.settings.lcm_diffusion_setting.use_tiny_auto_encoder = (
        tiny_auto_encoder_checkbox
    )


def on_offline_checkbox(offline_checkbox):
    app_settings.settings.lcm_diffusion_setting.use_offline_model = offline_checkbox


def get_generation_settings_ui() -> None:
    with gr.Blocks():
        with gr.Row():
            with gr.Column():
                num_inference_steps = gr.Slider(
                    1,
                    25,
                    value=app_settings.settings.lcm_diffusion_setting.inference_steps,
                    step=1,
                    label="Inference Steps",
                    interactive=True,
                )

                image_height = gr.Slider(
                    256,
                    1024,
                    value=app_settings.settings.lcm_diffusion_setting.image_height,
                    step=256,
                    label="Image Height",
                    interactive=True,
                )
                image_width = gr.Slider(
                    256,
                    1024,
                    value=app_settings.settings.lcm_diffusion_setting.image_width,
                    step=256,
                    label="Image Width",
                    interactive=True,
                )
                num_images = gr.Slider(
                    1,
                    50,
                    value=app_settings.settings.lcm_diffusion_setting.number_of_images,
                    step=1,
                    label="Number of images to generate",
                    interactive=True,
                )
                guidance_scale = gr.Slider(
                    1.0,
                    2.0,
                    value=app_settings.settings.lcm_diffusion_setting.guidance_scale,
                    step=0.1,
                    label="Guidance Scale",
                    interactive=True,
                )

                seed = gr.Slider(
                    value=app_settings.settings.lcm_diffusion_setting.seed,
                    minimum=0,
                    maximum=999999999,
                    label="Seed",
                    step=1,
                    interactive=True,
                )
                seed_checkbox = gr.Checkbox(
                    label="Use seed",
                    value=app_settings.settings.lcm_diffusion_setting.use_seed,
                    interactive=True,
                )

                safety_checker_checkbox = gr.Checkbox(
                    label="Use Safety Checker",
                    value=app_settings.settings.lcm_diffusion_setting.use_safety_checker,
                    interactive=True,
                )
                tiny_auto_encoder_checkbox = gr.Checkbox(
                    label="Use tiny auto encoder for SD",
                    value=app_settings.settings.lcm_diffusion_setting.use_tiny_auto_encoder,
                    interactive=True,
                )
                offline_checkbox = gr.Checkbox(
                    label="Use locally cached model or downloaded model folder(offline)",
                    value=app_settings.settings.lcm_diffusion_setting.use_offline_model,
                    interactive=True,
                )

        num_inference_steps.change(on_change_inference_steps, num_inference_steps)
        image_height.change(on_change_image_height, image_height)
        image_width.change(on_change_image_width, image_width)
        num_images.change(on_change_num_images, num_images)
        guidance_scale.change(on_change_guidance_scale, guidance_scale)
        seed.change(on_change_seed_value, seed)
        seed_checkbox.change(on_change_seed_checkbox, seed_checkbox)
        safety_checker_checkbox.change(
            on_change_safety_checker_checkbox, safety_checker_checkbox
        )
        tiny_auto_encoder_checkbox.change(
            on_change_tiny_auto_encoder_checkbox, tiny_auto_encoder_checkbox
        )
        offline_checkbox.change(on_offline_checkbox, offline_checkbox)