Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -77,22 +77,22 @@ def img2img( path ,design,x_prompt,alt_prompt,strength,guidance_scale,steps):
|
|
77 |
|
78 |
#####
|
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
|
|
|
|
|
|
|
|
|
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:
|
@@ -101,15 +101,23 @@ def img2img( path ,design,x_prompt,alt_prompt,strength,guidance_scale,steps):
|
|
101 |
else:
|
102 |
new_height = max_height
|
103 |
new_width = int(new_height * width / height)
|
|
|
|
|
|
|
|
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
# Resize the image
|
110 |
-
img = img.resize((new_width, new_height), resample=Image.Resampling.BILINEAR)
|
111 |
-
|
112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
|
115 |
########
|
|
|
77 |
|
78 |
#####
|
79 |
|
|
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
max_pixels = 1048576
|
82 |
|
83 |
# Open the image and retrieve its width and height
|
84 |
img = Image.open(path)
|
85 |
width, height = img.size
|
86 |
+
|
87 |
+
# Calculate the number of pixels in the image
|
88 |
num_pixels = width * height
|
89 |
+
|
90 |
# Check if the number of pixels is within the allowed range
|
91 |
+
if num_pixels > max_pixels:
|
92 |
+
# Calculate the maximum width and height based on the number of pixels in the original image
|
93 |
+
max_width = int(math.sqrt(max_pixels * width / height))
|
94 |
+
max_height = int(math.sqrt(max_pixels * height / width))
|
95 |
+
|
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:
|
|
|
101 |
else:
|
102 |
new_height = max_height
|
103 |
new_width = int(new_height * width / height)
|
104 |
+
else:
|
105 |
+
# Set the new dimensions to the original dimensions of the image
|
106 |
+
new_width = width
|
107 |
+
new_height = height
|
108 |
|
109 |
+
# Calculate the new size of the image, making sure that the width and height are multiples of 64
|
110 |
+
new_width = ((new_width + 63) // 64) * 64
|
111 |
+
new_height = ((new_height + 63) // 64) * 64
|
|
|
|
|
|
|
|
|
112 |
|
113 |
+
# Resize the image
|
114 |
+
img = img.resize((new_width, new_height), resample=Image.Resampling.BILINEAR)
|
115 |
+
|
116 |
+
|
117 |
+
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
|
122 |
|
123 |
########
|