LPX55 commited on
Commit
21a2120
·
verified ·
1 Parent(s): 36be43a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -12
app.py CHANGED
@@ -106,7 +106,7 @@ def can_expand(source_width, source_height, target_width, target_height, alignme
106
  return False
107
  return True
108
 
109
- def prepare_image_and_mask(image, width, height, overlap_percentage, resize_option, custom_resize_percentage, alignment, overlap_left, overlap_right, overlap_top, overlap_bottom, x_offset, y_offset):
110
  target_size = (width, height)
111
  scale_factor = min(target_size[0] / image.width, target_size[1] / image.height)
112
  new_width = int(image.width * scale_factor)
@@ -155,6 +155,10 @@ def prepare_image_and_mask(image, width, height, overlap_percentage, resize_opti
155
  margin_x = (target_size[0] - new_width) // 2
156
  margin_y = target_size[1] - new_height
157
 
 
 
 
 
158
  margin_x = max(0, min(margin_x + x_offset, target_size[0] - new_width))
159
  margin_y = max(0, min(margin_y + y_offset, target_size[1] - new_height))
160
 
@@ -176,6 +180,7 @@ def prepare_image_and_mask(image, width, height, overlap_percentage, resize_opti
176
  ], fill=0)
177
 
178
  return background, mask
 
179
  def preview_image_and_mask(image, width, height, overlap_percentage, resize_option, custom_resize_percentage, alignment, overlap_left, overlap_right, overlap_top, overlap_bottom, x_offset, y_offset):
180
  background, mask = prepare_image_and_mask(
181
  image,
@@ -591,15 +596,29 @@ with gr.Blocks(css=css, fill_height=True) as demo:
591
  outputs=[input_image_outpaint]
592
  )
593
  runout_button.click(
594
- fn=clear_result,
595
- inputs=None,
596
- outputs=result_outpaint,
597
  ).then(
598
- fn=infer,
599
- inputs=[input_image_outpaint, width_slider, height_slider, overlap_percentage, num_inference_steps,
600
- resize_option, custom_resize_percentage, prompt_input, alignment_dropdown,
601
- overlap_left, overlap_right, overlap_top, overlap_bottom],
602
- outputs=[result_outpaint],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
603
  ).then(
604
  fn=lambda x, history: update_history(x[1], history),
605
  inputs=[result_outpaint, history_gallery],
@@ -609,15 +628,30 @@ with gr.Blocks(css=css, fill_height=True) as demo:
609
  inputs=None,
610
  outputs=[use_as_input_button_outpaint],
611
  )
 
612
  prompt_input.submit(
613
  fn=clear_result,
614
  inputs=None,
615
  outputs=result_outpaint,
616
  ).then(
617
  fn=infer,
618
- inputs=[input_image_outpaint, width_slider, height_slider, overlap_percentage, num_inference_steps,
619
- resize_option, custom_resize_percentage, prompt_input, alignment_dropdown,
620
- overlap_left, overlap_right, overlap_top, overlap_bottom, x_offset_slider, y_offset_slider],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
621
  outputs=[result_outpaint],
622
  ).then(
623
  fn=lambda x, history: update_history(x[1], history),
 
106
  return False
107
  return True
108
 
109
+ def prepare_image_and_mask(image, width, height, overlap_percentage, resize_option, custom_resize_percentage, alignment, overlap_left, overlap_right, overlap_top, overlap_bottom, x_offset=None, y_offset=None):
110
  target_size = (width, height)
111
  scale_factor = min(target_size[0] / image.width, target_size[1] / image.height)
112
  new_width = int(image.width * scale_factor)
 
155
  margin_x = (target_size[0] - new_width) // 2
156
  margin_y = target_size[1] - new_height
157
 
158
+ # Ensure x_offset and y_offset are not None
159
+ x_offset = x_offset if x_offset is not None else 0
160
+ y_offset = y_offset if y_offset is not None else 0
161
+
162
  margin_x = max(0, min(margin_x + x_offset, target_size[0] - new_width))
163
  margin_y = max(0, min(margin_y + y_offset, target_size[1] - new_height))
164
 
 
180
  ], fill=0)
181
 
182
  return background, mask
183
+
184
  def preview_image_and_mask(image, width, height, overlap_percentage, resize_option, custom_resize_percentage, alignment, overlap_left, overlap_right, overlap_top, overlap_bottom, x_offset, y_offset):
185
  background, mask = prepare_image_and_mask(
186
  image,
 
596
  outputs=[input_image_outpaint]
597
  )
598
  runout_button.click(
599
+ fn=clear_result,
600
+ inputs=None,
601
+ outputs=result_outpaint,
602
  ).then(
603
+ fn=infer,
604
+ inputs=[
605
+ input_image_outpaint,
606
+ width_slider,
607
+ height_slider,
608
+ overlap_percentage,
609
+ num_inference_steps,
610
+ resize_option,
611
+ custom_resize_percentage,
612
+ prompt_input,
613
+ alignment_dropdown,
614
+ overlap_left,
615
+ overlap_right,
616
+ overlap_top,
617
+ overlap_bottom,
618
+ x_offset_slider,
619
+ y_offset_slider
620
+ ],
621
+ outputs=[result_outpaint],
622
  ).then(
623
  fn=lambda x, history: update_history(x[1], history),
624
  inputs=[result_outpaint, history_gallery],
 
628
  inputs=None,
629
  outputs=[use_as_input_button_outpaint],
630
  )
631
+
632
  prompt_input.submit(
633
  fn=clear_result,
634
  inputs=None,
635
  outputs=result_outpaint,
636
  ).then(
637
  fn=infer,
638
+ inputs=[
639
+ input_image_outpaint,
640
+ width_slider,
641
+ height_slider,
642
+ overlap_percentage,
643
+ num_inference_steps,
644
+ resize_option,
645
+ custom_resize_percentage,
646
+ prompt_input,
647
+ alignment_dropdown,
648
+ overlap_left,
649
+ overlap_right,
650
+ overlap_top,
651
+ overlap_bottom,
652
+ x_offset_slider,
653
+ y_offset_slider
654
+ ],
655
  outputs=[result_outpaint],
656
  ).then(
657
  fn=lambda x, history: update_history(x[1], history),