"""
Original code by Zenafey
@zenafey
"""
import gradio as gr
from engine import generate_sd, generate_sdxl, transform_sd, controlnet_sd, image_upscale, get_models
from const import CMODELS, CMODULES, SAMPLER_LIST, SDXL_MODEL_LIST
with gr.Blocks() as demo:
gr.Markdown("""
Prodia Studio
powered by Prodia Stable Diffusion API
""")
with gr.Tab("/sdxl/generate [BETA]"):
with gr.Row():
with gr.Column(scale=6, min_width=600):
prompt = gr.Textbox("puppies in a cloud, 4k", placeholder="Prompt", show_label=False, lines=3)
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3)
with gr.Row():
with gr.Column():
sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method",
choices=SAMPLER_LIST)
model = gr.Dropdown(
interactive=True,
value="sd_xl_base_1.0.safetensors [be9edd61]",
show_label=True,
label="Stable Diffusion XL Checkpoint",
choices=SDXL_MODEL_LIST
)
seed = gr.Number(label="Seed", value=-1)
with gr.Column():
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=50, value=25, step=1)
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
text_button = gr.Button("Generate", variant='primary')
with gr.Column(scale=7):
image_output = gr.Image()
text_button.click(generate_sdxl,
inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, seed], outputs=image_output)
with gr.Tab("/sd/generate"):
with gr.Row():
with gr.Column(scale=6, min_width=600):
prompt = gr.Textbox("puppies in a cloud, 4k", placeholder="Prompt", show_label=False, lines=3)
negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3)
with gr.Row():
with gr.Column():
sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method",
choices=SAMPLER_LIST)
model = gr.Dropdown(
interactive=True,
value=get_models()[1],
show_label=True,
label="Stable Diffusion Checkpoint",
choices=get_models()
)
upscale = gr.Checkbox(label="Upscale", value=True)
seed = gr.Number(label="Seed", value=-1)
with gr.Column():
width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=50, value=25, step=1)
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
text_button = gr.Button("Generate", variant='primary')
with gr.Column(scale=7):
image_output = gr.Image()
text_button.click(generate_sd,
inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed,
upscale], outputs=image_output)
with gr.Tab("/sd/transform"):
with gr.Row():
with gr.Row():
with gr.Column(scale=6, min_width=600):
with gr.Row():
with gr.Column():
image_input = gr.Image(type='filepath')
with gr.Column():
prompt = gr.Textbox("puppies in a cloud, 4k", label='Prompt', placeholder="Prompt", lines=3)
negative_prompt = gr.Textbox(placeholder="badly drawn", label='Negative Prompt', lines=3)
with gr.Row():
with gr.Column():
sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method", choices=SAMPLER_LIST)
model = gr.Dropdown(
interactive=True,
value=get_models()[1],
show_label=True,
label="Stable Diffusion Checkpoint",
choices=get_models()
)
upscale = gr.Checkbox(label="Upscale", value=True)
seed = gr.Number(label="Seed", value=-1)
with gr.Column():
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
denoising_strength = gr.Slider(label="Denoising Strength", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
text_button = gr.Button("Generate", variant='primary')
with gr.Column(scale=7):
image_output = gr.Image()
text_button.click(transform_sd,
inputs=[image_input, model, prompt, denoising_strength, negative_prompt, steps, cfg_scale, seed, upscale, sampler
], outputs=image_output)
with gr.Tab("/sd/controlnet"):
with gr.Row():
with gr.Row():
with gr.Column(scale=6, min_width=600):
with gr.Row():
with gr.Column():
image_input = gr.Image(type='filepath')
with gr.Column():
prompt = gr.Textbox("puppies in a cloud, 4k", label='Prompt', placeholder="Prompt", lines=3)
negative_prompt = gr.Textbox(placeholder="badly drawn", label='Negative Prompt', lines=3)
with gr.Row():
with gr.Column():
sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method", choices=SAMPLER_LIST)
model = gr.Dropdown(
interactive=True,
value="control_v11p_sd15_canny [d14c016b]",
show_label=True,
label="ControlNet Model",
choices=CMODELS
)
module = gr.Dropdown(
interactive=True,
value="none",
show_label=True,
label="ControlNet Module",
choices=CMODULES
)
seed = gr.Number(label="Seed", value=-1)
with gr.Column():
width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
resize_mode = gr.Dropdown(label='resize_mode', value="0", choices=["0", "1", "2"])
with gr.Row():
threshold_a = gr.Number(label="threshold_a", value=100)
threshold_b = gr.Number(label="threshold_b", value=200)
text_button = gr.Button("Generate", variant='primary')
with gr.Column(scale=7):
image_output = gr.Image()
text_button.click(controlnet_sd,
inputs=[image_input, model, module, threshold_a, threshold_b, resize_mode, prompt,
negative_prompt, steps, cfg_scale, seed, sampler, width, height],
outputs=image_output)
with gr.Tab("/upscale"):
with gr.Row():
with gr.Column():
image_input = gr.Image(type='filepath')
scale_by = gr.Radio(['2', '4'], label="Scale by")
upscale_btn = gr.Button("Upscale!", variant='primary')
with gr.Column():
image_output = gr.Image()
upscale_btn.click(image_upscale, inputs=[image_input, scale_by], outputs=image_output)
demo.launch(show_api=True)