Spaces:
Runtime error
Runtime error
File size: 6,753 Bytes
87c5489 |
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
import gradio as gr
from state import get_settings
from backend.models.gen_images import ImageFormat
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_clip_skip(clip_skip):
app_settings.settings.lcm_diffusion_setting.clip_skip = clip_skip
def on_change_token_merging(token_merging):
app_settings.settings.lcm_diffusion_setting.token_merging = token_merging
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 on_change_image_format(image_format):
if image_format == "PNG":
app_settings.settings.generated_images.format = ImageFormat.PNG.value.upper()
else:
app_settings.settings.generated_images.format = ImageFormat.JPEG.value.upper()
app_settings.save()
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,
10.0,
value=app_settings.settings.lcm_diffusion_setting.guidance_scale,
step=0.1,
label="Guidance Scale",
interactive=True,
)
clip_skip = gr.Slider(
1,
12,
value=app_settings.settings.lcm_diffusion_setting.clip_skip,
step=1,
label="CLIP Skip",
interactive=True,
)
token_merging = gr.Slider(
0.0,
1.0,
value=app_settings.settings.lcm_diffusion_setting.token_merging,
step=0.01,
label="Token Merging",
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,
)
img_format = gr.Radio(
label="Output image format",
choices=["PNG", "JPEG"],
value=app_settings.settings.generated_images.format,
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)
clip_skip.change(on_change_clip_skip, clip_skip)
token_merging.change(on_change_token_merging, token_merging)
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)
img_format.change(on_change_image_format, img_format)
|