File size: 9,146 Bytes
19ab7b2
 
 
 
 
 
b37664d
19ab7b2
 
 
5bc91ce
19ab7b2
92e5939
19ab7b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05bd79c
19ab7b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
05bd79c
19ab7b2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e3d2f9e
 
 
 
 
 
 
 
 
b37664d
f84294b
19ab7b2
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
"""
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("""
<h1><center>Prodia Studio</center></h>
<h2><center>powered by Prodia Stable Diffusion API</center></h2>""")
    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.Slider(label="Scale by", minimum=2, maximum=4, step=2)
                upscale_btn = gr.Button("Upscale!")
            with gr.Column():
                image_output = gr.Image()

        upscale_btn.click(image_upscale, inputs=[image_input, scale_by], outputs=image_output)

demo.launch(show_api=False)