Fabrice-TIERCELIN commited on
Commit
d68eb2f
1 Parent(s): a2df72c
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -32,6 +32,18 @@ def predict(source_img, enlarge_top, enlarge_right, enlarge_bottom, enlarge_left
32
  if negative_prompt is None or negative_prompt == "":
33
  raise gr.Error("Please provide a negative prompt input.")
34
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  if enlarge_top < 0 or enlarge_right < 0 or enlarge_bottom < 0 or enlarge_left < 0:
36
  raise gr.Error("Please only provide positive margins.")
37
 
@@ -63,7 +75,7 @@ def predict(source_img, enlarge_top, enlarge_right, enlarge_bottom, enlarge_left
63
  enlarged_image = Image.new(mode = input_image.mode, size = (original_height, original_width), color = "black")
64
  enlarged_image.paste(input_image, (0, 0))
65
  enlarged_image = enlarged_image.resize((output_width, output_height))
66
- enlarged_image = enlarged_image.filter(ImageFilter.BoxBlur(25))
67
 
68
  enlarged_image.paste(input_image, (enlarge_left, enlarge_top))
69
 
@@ -81,7 +93,7 @@ def predict(source_img, enlarge_top, enlarge_right, enlarge_bottom, enlarge_left
81
  enlarged_image.paste(returned_input_image, (enlarge_left + original_width, enlarge_top - (original_height * 2)))
82
  enlarged_image.paste(returned_input_image, (enlarge_left + original_width, enlarge_top + original_height))
83
 
84
- enlarged_image = enlarged_image.filter(ImageFilter.BoxBlur(25))
85
 
86
  # Noise image
87
  noise_image = Image.new(mode = input_image.mode, size = (output_width, output_height), color = "black")
@@ -90,7 +102,7 @@ def predict(source_img, enlarge_top, enlarge_right, enlarge_bottom, enlarge_left
90
  for i in range(output_width):
91
  for j in range(output_height):
92
  enlarged_pixel = enlarged_pixels[i, j]
93
- noise = min(abs(enlarge_left - i), abs(enlarge_left + original_width - i), abs(enlarge_top - j), abs(enlarge_top + original_height - j), 255)
94
  noise_image.putpixel((i, j), (noise_color(enlarged_pixel[0], noise), noise_color(enlarged_pixel[1], noise), noise_color(enlarged_pixel[2], noise), 255))
95
 
96
  enlarged_image.paste(noise_image, (0, 0))
 
32
  if negative_prompt is None or negative_prompt == "":
33
  raise gr.Error("Please provide a negative prompt input.")
34
 
35
+ if enlarge_top is None or enlarge_top == "":
36
+ raise gr.Error("Please provide a top input.")
37
+
38
+ if enlarge_right is None or enlarge_right == "":
39
+ raise gr.Error("Please provide a right input.")
40
+
41
+ if enlarge_bottom is None or enlarge_bottom == "":
42
+ raise gr.Error("Please provide a bottom input.")
43
+
44
+ if enlarge_left is None or enlarge_left == "":
45
+ raise gr.Error("Please provide a left input.")
46
+
47
  if enlarge_top < 0 or enlarge_right < 0 or enlarge_bottom < 0 or enlarge_left < 0:
48
  raise gr.Error("Please only provide positive margins.")
49
 
 
75
  enlarged_image = Image.new(mode = input_image.mode, size = (original_height, original_width), color = "black")
76
  enlarged_image.paste(input_image, (0, 0))
77
  enlarged_image = enlarged_image.resize((output_width, output_height))
78
+ enlarged_image = enlarged_image.filter(ImageFilter.BoxBlur(20))
79
 
80
  enlarged_image.paste(input_image, (enlarge_left, enlarge_top))
81
 
 
93
  enlarged_image.paste(returned_input_image, (enlarge_left + original_width, enlarge_top - (original_height * 2)))
94
  enlarged_image.paste(returned_input_image, (enlarge_left + original_width, enlarge_top + original_height))
95
 
96
+ enlarged_image = enlarged_image.filter(ImageFilter.BoxBlur(20))
97
 
98
  # Noise image
99
  noise_image = Image.new(mode = input_image.mode, size = (output_width, output_height), color = "black")
 
102
  for i in range(output_width):
103
  for j in range(output_height):
104
  enlarged_pixel = enlarged_pixels[i, j]
105
+ noise = min(max(enlarge_left - i, i - (enlarge_left + original_width), enlarge_top - j, j - (enlarge_top + original_height), 0), 255)
106
  noise_image.putpixel((i, j), (noise_color(enlarged_pixel[0], noise), noise_color(enlarged_pixel[1], noise), noise_color(enlarged_pixel[2], noise), 255))
107
 
108
  enlarged_image.paste(noise_image, (0, 0))