kbora commited on
Commit
907fc9a
·
1 Parent(s): 92b508a

Update blocks/inpainting.py

Browse files
Files changed (1) hide show
  1. blocks/inpainting.py +71 -60
blocks/inpainting.py CHANGED
@@ -24,7 +24,7 @@ class StableDiffusionInpaintGenerator:
24
  device = get_device()
25
  self.pipe = get_scheduler_list(pipe=self.pipe, scheduler=scheduler)
26
  self.pipe.to(device)
27
- #self.pipe.enable_attention_slicing()
28
  return self.pipe
29
 
30
  def generate_image(
@@ -33,7 +33,6 @@ class StableDiffusionInpaintGenerator:
33
  model_path: str,
34
  prompt: str,
35
  negative_prompt: str,
36
- num_images_per_prompt: int,
37
  scheduler: str,
38
  guidance_scale: int,
39
  num_inference_step: int,
@@ -58,7 +57,7 @@ class StableDiffusionInpaintGenerator:
58
  image=image,
59
  mask_image=mask_image,
60
  negative_prompt=negative_prompt,
61
- num_images_per_prompt=num_images_per_prompt,
62
  num_inference_steps=num_inference_step,
63
  guidance_scale=guidance_scale,
64
  generator=generator,
@@ -83,7 +82,7 @@ class StableDiffusionInpaintGenerator:
83
 
84
  stable_diffusion_inpaint_prompt = gr.Textbox(
85
  lines=1,
86
- placeholder="Prompt",
87
  show_label=False,
88
  elem_id="prompt-text-input-inpainting",
89
  value=''
@@ -91,7 +90,7 @@ class StableDiffusionInpaintGenerator:
91
 
92
  stable_diffusion_inpaint_negative_prompt = gr.Textbox(
93
  lines=1,
94
- placeholder="Negative Prompt",
95
  show_label=False,
96
  elem_id = "negative-prompt-text-input-inpainting",
97
  value=''
@@ -109,6 +108,8 @@ class StableDiffusionInpaintGenerator:
109
  lines=1,
110
  placeholder="Generated Prompt",
111
  show_label=False,
 
 
112
  )
113
 
114
  stable_diffusion_inpaint_model_id = gr.Dropdown(
@@ -116,63 +117,62 @@ class StableDiffusionInpaintGenerator:
116
  value=list(INPAINT_MODEL_LIST.keys())[0],
117
  label="Inpaint Model Selection",
118
  elem_id="model-dropdown-inpainting",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  )
120
- with gr.Row():
121
- with gr.Column():
122
- stable_diffusion_inpaint_guidance_scale = gr.Slider(
123
- minimum=0.1,
124
- maximum=15,
125
- step=0.1,
126
- value=7.5,
127
- label="Guidance Scale",
128
- elem_id = "guidance-scale-slider-inpainting"
129
- )
130
-
131
- stable_diffusion_inpaint_num_inference_step = gr.Slider(
132
- minimum=1,
133
- maximum=100,
134
- step=1,
135
- value=50,
136
- label="Num Inference Step",
137
- elem_id = "num-inference-step-slider-inpainting"
138
- )
139
-
140
- stable_diffusion_inpiant_num_images_per_prompt = gr.Slider(
141
- minimum=1,
142
- maximum=10,
143
- step=1,
144
- value=1,
145
- label="Number Of Images",
146
- )
147
-
148
- with gr.Row():
149
- with gr.Column():
150
- stable_diffusion_inpaint_scheduler = gr.Dropdown(
151
- choices=SCHEDULER_LIST,
152
- value=SCHEDULER_LIST[0],
153
- label="Scheduler",
154
- elem_id="scheduler-dropdown-inpainting",
155
- )
156
-
157
- stable_diffusion_inpaint_size = gr.Slider(
158
- minimum=128,
159
- maximum=1280,
160
- step=32,
161
- value=512,
162
- label="Image Size",
163
- elem_id="image-size-slider-inpainting",
164
- )
165
-
166
- stable_diffusion_inpaint_seed_generator = gr.Slider(
167
- label="Seed(0 for random)",
168
- minimum=0,
169
- maximum=1000000,
170
- value=0,
171
- elem_id="seed-slider-inpainting",
172
- )
173
 
174
  stable_diffusion_inpaint_predict = gr.Button(
175
- value="Generator"
176
  )
177
 
178
  with gr.Column():
@@ -189,6 +189,18 @@ class StableDiffusionInpaintGenerator:
189
  loading_icon = gr.HTML(loading_icon_html)
190
  share_button = gr.Button("Save artwork", elem_id="share-btn-inpainting")
191
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  stable_diffusion_inpaint_predict.click(
193
  fn=StableDiffusionInpaintGenerator().generate_image,
194
  inputs=[
@@ -196,7 +208,6 @@ class StableDiffusionInpaintGenerator:
196
  stable_diffusion_inpaint_model_id,
197
  stable_diffusion_inpaint_prompt,
198
  stable_diffusion_inpaint_negative_prompt,
199
- stable_diffusion_inpiant_num_images_per_prompt,
200
  stable_diffusion_inpaint_scheduler,
201
  stable_diffusion_inpaint_guidance_scale,
202
  stable_diffusion_inpaint_num_inference_step,
 
24
  device = get_device()
25
  self.pipe = get_scheduler_list(pipe=self.pipe, scheduler=scheduler)
26
  self.pipe.to(device)
27
+ self.pipe.enable_attention_slicing()
28
  return self.pipe
29
 
30
  def generate_image(
 
33
  model_path: str,
34
  prompt: str,
35
  negative_prompt: str,
 
36
  scheduler: str,
37
  guidance_scale: int,
38
  num_inference_step: int,
 
57
  image=image,
58
  mask_image=mask_image,
59
  negative_prompt=negative_prompt,
60
+ num_images_per_prompt=1,
61
  num_inference_steps=num_inference_step,
62
  guidance_scale=guidance_scale,
63
  generator=generator,
 
82
 
83
  stable_diffusion_inpaint_prompt = gr.Textbox(
84
  lines=1,
85
+ placeholder="Prompt, keywords that explains how you want to modify the image.",
86
  show_label=False,
87
  elem_id="prompt-text-input-inpainting",
88
  value=''
 
90
 
91
  stable_diffusion_inpaint_negative_prompt = gr.Textbox(
92
  lines=1,
93
+ placeholder="Negative Prompt, keywords that describe what you don't want in your image",
94
  show_label=False,
95
  elem_id = "negative-prompt-text-input-inpainting",
96
  value=''
 
108
  lines=1,
109
  placeholder="Generated Prompt",
110
  show_label=False,
111
+ info="Auto generated prompts for inspiration.",
112
+
113
  )
114
 
115
  stable_diffusion_inpaint_model_id = gr.Dropdown(
 
117
  value=list(INPAINT_MODEL_LIST.keys())[0],
118
  label="Inpaint Model Selection",
119
  elem_id="model-dropdown-inpainting",
120
+ info="Select the model you want to use for inpainting."
121
+ )
122
+
123
+ stable_diffusion_inpaint_scheduler = gr.Dropdown(
124
+ choices=SCHEDULER_LIST,
125
+ value=SCHEDULER_LIST[0],
126
+ label="Scheduler",
127
+ elem_id="scheduler-dropdown-inpainting",
128
+ info="Scheduler list for models. Different schdulers result in different outputs."
129
+ )
130
+
131
+
132
+ stable_diffusion_inpaint_guidance_scale = gr.Slider(
133
+ minimum=0.1,
134
+ maximum=15,
135
+ step=0.1,
136
+ value=7.5,
137
+ label="Guidance Scale",
138
+ elem_id = "guidance-scale-slider-inpainting",
139
+ info = "Guidance scale determines how much the prompt will affect the image. Higher the value, more the effect."
140
+
141
+ )
142
+
143
+ stable_diffusion_inpaint_num_inference_step = gr.Slider(
144
+ minimum=1,
145
+ maximum=100,
146
+ step=1,
147
+ value=50,
148
+ label="Num Inference Step",
149
+ elem_id = "num-inference-step-slider-inpainting",
150
+ info = "Number of inference step determines the quality of the image. Higher the number, better the quality."
151
+
152
+ )
153
+
154
+ stable_diffusion_inpaint_size = gr.Slider(
155
+ minimum=128,
156
+ maximum=1280,
157
+ step=32,
158
+ value=512,
159
+ label="Image Size",
160
+ elem_id="image-size-slider-inpainting",
161
+ info = "Image size determines the height and width of the generated image. Higher the value, better the quality however slower the computation."
162
+
163
+ )
164
+
165
+ stable_diffusion_inpaint_seed_generator = gr.Slider(
166
+ label="Seed(0 for random)",
167
+ minimum=0,
168
+ maximum=1000000,
169
+ value=0,
170
+ elem_id="seed-slider-inpainting",
171
+ info="Set the seed to a specific value to reproduce the results."
172
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
  stable_diffusion_inpaint_predict = gr.Button(
175
+ value="Generate image"
176
  )
177
 
178
  with gr.Column():
 
189
  loading_icon = gr.HTML(loading_icon_html)
190
  share_button = gr.Button("Save artwork", elem_id="share-btn-inpainting")
191
 
192
+ gr.HTML(
193
+ """
194
+ <div id="model-description-img2img">
195
+ <h3>Inpainting Models</h3>
196
+ <p>Inpainting models will take a masked image and modify the masked image with the given prompt.</p>
197
+ <p>Prompt should describe how you want to modify the image. For example, if you want to modify the image to have a blue sky, you can use the prompt "sky is blue".</p>
198
+ <p>Negative prompt should describe what you don't want in your image. For example, if you don't want the image to have a red sky, you can use the negative prompt "sky is red".</p>
199
+ <hr>
200
+ <p>Stable Diffusion 1 & 2: Default model for many tasks. </p>
201
+ </div>
202
+ """
203
+ )
204
  stable_diffusion_inpaint_predict.click(
205
  fn=StableDiffusionInpaintGenerator().generate_image,
206
  inputs=[
 
208
  stable_diffusion_inpaint_model_id,
209
  stable_diffusion_inpaint_prompt,
210
  stable_diffusion_inpaint_negative_prompt,
 
211
  stable_diffusion_inpaint_scheduler,
212
  stable_diffusion_inpaint_guidance_scale,
213
  stable_diffusion_inpaint_num_inference_step,