TRaw commited on
Commit
c8ca498
Β·
1 Parent(s): bc98cfe

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +168 -0
app.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ from engine import generate_sd, generate_sdxl, transform_sd, controlnet_sd, image_upscale, get_models
4
+ from const import CMODELS, CMODULES, SAMPLER_LIST, SDXL_MODEL_LIST
5
+
6
+ theme='rottenlittlecreature/Moon_Goblin'
7
+
8
+ with gr.Blocks(theme=theme) as demo:
9
+ gr.Markdown("""
10
+ <h1><center>Prodia Studio</center></h>
11
+ <h2><center>powered by Prodia Stable Diffusion API</center></h2>""")
12
+ with gr.Tab("/sdxl/generate [BETA]"):
13
+ with gr.Row():
14
+ with gr.Column(scale=6, min_width=600):
15
+ prompt = gr.Textbox("puppies in a cloud, 4k", placeholder="Prompt", show_label=False, lines=3)
16
+ negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3)
17
+ with gr.Row():
18
+ with gr.Column():
19
+ sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method",
20
+ choices=SAMPLER_LIST)
21
+ model = gr.Dropdown(
22
+ interactive=True,
23
+ value="sd_xl_base_1.0.safetensors [be9edd61]",
24
+ show_label=True,
25
+ label="Stable Diffusion XL Checkpoint",
26
+ choices=SDXL_MODEL_LIST
27
+ )
28
+ seed = gr.Number(label="Seed", value=-1)
29
+ with gr.Column():
30
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=50, value=25, step=1)
31
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
32
+
33
+ text_button = gr.Button("Generate", variant='primary')
34
+
35
+ with gr.Column(scale=7):
36
+ image_output = gr.Image()
37
+
38
+ text_button.click(generate_sdxl,
39
+ inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, seed], outputs=image_output)
40
+ with gr.Tab("/sd/generate"):
41
+ with gr.Row():
42
+ with gr.Column(scale=6, min_width=600):
43
+ prompt = gr.Textbox("puppies in a cloud, 4k", placeholder="Prompt", show_label=False, lines=3)
44
+ negative_prompt = gr.Textbox(placeholder="Negative Prompt", show_label=False, lines=3)
45
+ with gr.Row():
46
+ with gr.Column():
47
+ sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method",
48
+ choices=SAMPLER_LIST)
49
+ model = gr.Dropdown(
50
+ interactive=True,
51
+ value=get_models()[1],
52
+ show_label=True,
53
+ label="Stable Diffusion Checkpoint",
54
+ choices=get_models()
55
+ )
56
+ upscale = gr.Checkbox(label="Upscale", value=True)
57
+ seed = gr.Number(label="Seed", value=-1)
58
+ with gr.Column():
59
+ width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
60
+ height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
61
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=50, value=25, step=1)
62
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
63
+
64
+ text_button = gr.Button("Generate", variant='primary')
65
+
66
+ with gr.Column(scale=7):
67
+ image_output = gr.Image()
68
+
69
+ text_button.click(generate_sd,
70
+ inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed,
71
+ upscale], outputs=image_output)
72
+
73
+ with gr.Tab("/sd/transform"):
74
+ with gr.Row():
75
+ with gr.Row():
76
+ with gr.Column(scale=6, min_width=600):
77
+ with gr.Row():
78
+ with gr.Column():
79
+ image_input = gr.Image(type='filepath')
80
+ with gr.Column():
81
+ prompt = gr.Textbox("puppies in a cloud, 4k", label='Prompt', placeholder="Prompt", lines=3)
82
+ negative_prompt = gr.Textbox(placeholder="badly drawn", label='Negative Prompt', lines=3)
83
+ with gr.Row():
84
+ with gr.Column():
85
+ sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method", choices=SAMPLER_LIST)
86
+ model = gr.Dropdown(
87
+ interactive=True,
88
+ value=get_models()[1],
89
+ show_label=True,
90
+ label="Stable Diffusion Checkpoint",
91
+ choices=get_models()
92
+ )
93
+ upscale = gr.Checkbox(label="Upscale", value=True)
94
+ seed = gr.Number(label="Seed", value=-1)
95
+ with gr.Column():
96
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
97
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
98
+ denoising_strength = gr.Slider(label="Denoising Strength", minimum=0.1, maximum=1.0, value=0.7, step=0.1)
99
+
100
+ text_button = gr.Button("Generate", variant='primary')
101
+
102
+ with gr.Column(scale=7):
103
+ image_output = gr.Image()
104
+
105
+ text_button.click(transform_sd,
106
+ inputs=[image_input, model, prompt, denoising_strength, negative_prompt, steps, cfg_scale, seed, upscale, sampler
107
+ ], outputs=image_output)
108
+
109
+ with gr.Tab("/sd/controlnet"):
110
+ with gr.Row():
111
+ with gr.Row():
112
+ with gr.Column(scale=6, min_width=600):
113
+ with gr.Row():
114
+ with gr.Column():
115
+ image_input = gr.Image(type='filepath')
116
+ with gr.Column():
117
+ prompt = gr.Textbox("puppies in a cloud, 4k", label='Prompt', placeholder="Prompt", lines=3)
118
+ negative_prompt = gr.Textbox(placeholder="badly drawn", label='Negative Prompt', lines=3)
119
+ with gr.Row():
120
+ with gr.Column():
121
+ sampler = gr.Dropdown(value="Euler a", show_label=True, label="Sampling Method", choices=SAMPLER_LIST)
122
+ model = gr.Dropdown(
123
+ interactive=True,
124
+ value="control_v11p_sd15_canny [d14c016b]",
125
+ show_label=True,
126
+ label="ControlNet Model",
127
+ choices=CMODELS
128
+ )
129
+ module = gr.Dropdown(
130
+ interactive=True,
131
+ value="none",
132
+ show_label=True,
133
+ label="ControlNet Module",
134
+ choices=CMODULES
135
+ )
136
+ seed = gr.Number(label="Seed", value=-1)
137
+ with gr.Column():
138
+ width = gr.Slider(label="Width", maximum=1024, value=512, step=8)
139
+ height = gr.Slider(label="Height", maximum=1024, value=512, step=8)
140
+ steps = gr.Slider(label="Sampling Steps", minimum=1, maximum=30, value=25, step=1)
141
+ cfg_scale = gr.Slider(label="CFG Scale", minimum=1, maximum=20, value=7, step=1)
142
+ resize_mode = gr.Dropdown(label='resize_mode', value="0", choices=["0", "1", "2"])
143
+ with gr.Row():
144
+ threshold_a = gr.Number(label="threshold_a", value=100)
145
+ threshold_b = gr.Number(label="threshold_b", value=200)
146
+
147
+ text_button = gr.Button("Generate", variant='primary')
148
+
149
+ with gr.Column(scale=7):
150
+ image_output = gr.Image()
151
+
152
+ text_button.click(controlnet_sd,
153
+ inputs=[image_input, model, module, threshold_a, threshold_b, resize_mode, prompt,
154
+ negative_prompt, steps, cfg_scale, seed, sampler, width, height],
155
+ outputs=image_output)
156
+
157
+ with gr.Tab("/upscale"):
158
+ with gr.Row():
159
+ with gr.Column():
160
+ image_input = gr.Image(type='filepath')
161
+ scale_by = gr.Radio(['2', '4'], label="Scale by")
162
+ upscale_btn = gr.Button("Upscale!", variant='primary')
163
+ with gr.Column():
164
+ image_output = gr.Image()
165
+
166
+ upscale_btn.click(image_upscale, inputs=[image_input, scale_by], outputs=image_output)
167
+
168
+ demo.launch(show_api=False)