zenafey commited on
Commit
19ab7b2
1 Parent(s): 1f746c3

Create app.py

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