cocktailpeanut commited on
Commit
c08f91e
·
1 Parent(s): d4ad269
Files changed (1) hide show
  1. app.py +45 -19
app.py CHANGED
@@ -121,24 +121,47 @@ def preprocess_map(map):
121
  return map
122
 
123
 
124
- def inference(image, map, gs, prompt, negative_prompt):
 
 
 
 
 
 
 
125
  validate_inputs(image, map)
126
  image = preprocess_image(image)
127
  map = preprocess_map(map)
128
- base_cuda = base.to(DEVICE)
129
- edited_images = base_cuda(prompt=prompt, original_image=image, image=image, strength=1, guidance_scale=gs,
130
- num_images_per_prompt=1,
131
- negative_prompt=negative_prompt,
132
- map=map,
133
- num_inference_steps=NUM_INFERENCE_STEPS, denoising_end=0.8, output_type="latent").images
134
- base_cuda=None
135
- refiner_cuda = refiner.to(DEVICE)
136
- edited_images = refiner_cuda(prompt=prompt, original_image=image, image=edited_images, strength=1, guidance_scale=7.5,
137
- num_images_per_prompt=1,
138
- negative_prompt=negative_prompt,
139
- map=map,
140
- num_inference_steps=NUM_INFERENCE_STEPS, denoising_start=0.8).images[0]
141
- refiner_cuda=None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  return edited_images
143
 
144
 
@@ -149,11 +172,11 @@ def validate_inputs(image, map):
149
  raise gr.Error("Missing map")
150
 
151
 
152
- def run(image, gs, prompt, neg_prompt):
153
  # first run
154
  [(original_image, colored_depth), name, raw_depth] = depthify(image)
155
  print(f"original_image={original_image} colored_depth={colored_depth}, name={name}, raw_depth={raw_depth}")
156
- return raw_depth, inference(original_image, raw_depth, gs, prompt, neg_prompt)
157
 
158
  with gr.Blocks() as demo:
159
  with gr.Row():
@@ -162,11 +185,14 @@ with gr.Blocks() as demo:
162
  input_image = gr.Image(label="Input Image", type="pil")
163
  # change_map = gr.Image(label="Change Map", type="pil")
164
  gs = gr.Slider(0, 28, value=7.5, label="Guidance Scale")
 
 
 
165
  prompt = gr.Textbox(label="Prompt")
166
  neg_prompt = gr.Textbox(label="Negative Prompt")
167
  with gr.Row():
168
  # clr_btn=gr.ClearButton(components=[input_image, change_map, gs, prompt, neg_prompt])
169
- clr_btn=gr.ClearButton(components=[input_image, gs, prompt, neg_prompt])
170
  run_btn = gr.Button("Run",variant="primary")
171
 
172
  change_map = gr.Image(label="Change Map")
@@ -174,7 +200,7 @@ with gr.Blocks() as demo:
174
  run_btn.click(
175
  run,
176
  #inference,
177
- inputs=[input_image, gs, prompt, neg_prompt],
178
  outputs=[change_map, output]
179
  )
180
  clr_btn.add(output)
 
121
  return map
122
 
123
 
124
+ def inference(
125
+ image,
126
+ map,
127
+ guidance_scale,
128
+ prompt,
129
+ negative_prompt,
130
+ steps
131
+ ):
132
  validate_inputs(image, map)
133
  image = preprocess_image(image)
134
  map = preprocess_map(map)
135
+ base_device = base.to(DEVICE)
136
+ edited_images = base_device(
137
+ prompt=prompt,
138
+ original_image=image,
139
+ image=image,
140
+ strength=1,
141
+ guidance_scale=guidance_scale,
142
+ num_images_per_prompt=1,
143
+ negative_prompt=negative_prompt,
144
+ map=map,
145
+ num_inference_steps=steps,
146
+ denoising_start=denoising_start,
147
+ denoising_end=denoising_end,
148
+ output_type="latent"
149
+ ).images
150
+ base_device=None
151
+ refiner_device = refiner.to(DEVICE)
152
+ edited_images = refiner_cuda(
153
+ prompt=prompt,
154
+ original_image=image,
155
+ image=edited_images,
156
+ strength=1,
157
+ guidance_scale=guidance_scale,
158
+ num_images_per_prompt=1,
159
+ negative_prompt=negative_prompt,
160
+ map=map,
161
+ num_inference_steps=steps,
162
+ denoising_start=denoising_start
163
+ ).images[0]
164
+ refiner_device=None
165
  return edited_images
166
 
167
 
 
172
  raise gr.Error("Missing map")
173
 
174
 
175
+ def run(image, gs, prompt, neg_prompt, steps, denoising_start, denoising_end):
176
  # first run
177
  [(original_image, colored_depth), name, raw_depth] = depthify(image)
178
  print(f"original_image={original_image} colored_depth={colored_depth}, name={name}, raw_depth={raw_depth}")
179
+ return raw_depth, inference(original_image, raw_depth, gs, prompt, neg_prompt, steps, denoising_start, denoising_end)
180
 
181
  with gr.Blocks() as demo:
182
  with gr.Row():
 
185
  input_image = gr.Image(label="Input Image", type="pil")
186
  # change_map = gr.Image(label="Change Map", type="pil")
187
  gs = gr.Slider(0, 28, value=7.5, label="Guidance Scale")
188
+ steps = gr.Number(value=50, label="Steps")
189
+ denoising_start = gr.Slider(0, 1, value=0.8, label="Denoising Start")
190
+ denoising_end = gr.Slider(0, 1, value=0.8, label="Denoising End")
191
  prompt = gr.Textbox(label="Prompt")
192
  neg_prompt = gr.Textbox(label="Negative Prompt")
193
  with gr.Row():
194
  # clr_btn=gr.ClearButton(components=[input_image, change_map, gs, prompt, neg_prompt])
195
+ clr_btn=gr.ClearButton(components=[input_image, gs, prompt, neg_prompt, steps, denoising_start, denoising_end])
196
  run_btn = gr.Button("Run",variant="primary")
197
 
198
  change_map = gr.Image(label="Change Map")
 
200
  run_btn.click(
201
  run,
202
  #inference,
203
+ inputs=[input_image, gs, prompt, neg_prompt, steps, denoising_start, denoising_end],
204
  outputs=[change_map, output]
205
  )
206
  clr_btn.add(output)