Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -79,37 +79,38 @@ def img2img( path ,design,x_prompt,alt_prompt,strength,guidance_scale,steps):
|
|
79 |
|
80 |
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
86 |
max_pixels = 1048576
|
87 |
|
88 |
# Open the image and retrieve its width and height
|
89 |
img = Image.open(path)
|
90 |
width, height = img.size
|
91 |
num_pixels = width * height
|
92 |
-
|
93 |
# Check if the number of pixels is within the allowed range
|
94 |
-
if num_pixels
|
95 |
-
#
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
107 |
|
108 |
-
# Resize the image
|
109 |
-
img = img.resize((new_width, new_height), resample=Image.Resampling.BILINEAR)
|
110 |
|
111 |
-
|
112 |
-
|
113 |
|
114 |
########
|
115 |
max_attempts = 5 # maximum number of attempts before giving up
|
|
|
79 |
|
80 |
|
81 |
|
82 |
+
|
83 |
+
|
84 |
+
|
85 |
+
|
86 |
+
|
87 |
+
# Maximum number of pixels allowed in the image
|
88 |
max_pixels = 1048576
|
89 |
|
90 |
# Open the image and retrieve its width and height
|
91 |
img = Image.open(path)
|
92 |
width, height = img.size
|
93 |
num_pixels = width * height
|
|
|
94 |
# Check if the number of pixels is within the allowed range
|
95 |
+
if num_pixels <= max_pixels:
|
96 |
+
# Calculate the new dimensions of the image, making sure that the width and height are within the allowed range
|
97 |
+
# and maintain the aspect ratio of the original image
|
98 |
+
if width > height:
|
99 |
+
new_width = max_width
|
100 |
+
new_height = int(new_width * height / width)
|
101 |
+
else:
|
102 |
+
new_height = max_height
|
103 |
+
new_width = int(new_height * width / height)
|
104 |
|
105 |
+
# Calculate the new size of the image, making sure that the width and height are multiples of 64
|
106 |
+
new_width = ((new_width + 63) // 64) * 64
|
107 |
+
new_height = ((new_height + 63) // 64) * 64
|
108 |
+
|
109 |
+
# Resize the image
|
110 |
+
img = img.resize((new_width, new_height), resample=Image.Resampling.BILINEAR)
|
111 |
+
|
112 |
|
|
|
|
|
113 |
|
|
|
|
|
114 |
|
115 |
########
|
116 |
max_attempts = 5 # maximum number of attempts before giving up
|