Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -65,17 +65,31 @@ def process_image_check(path_input):
|
|
65 |
)
|
66 |
|
67 |
def resize_image(input_image, resolution):
|
68 |
-
input_image
|
69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
H = float(H)
|
71 |
W = float(W)
|
|
|
|
|
72 |
k = float(resolution) / min(H, W)
|
|
|
|
|
73 |
H *= k
|
74 |
W *= k
|
75 |
H = int(np.round(H / 64.0)) * 64
|
76 |
W = int(np.round(W / 64.0)) * 64
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
79 |
|
80 |
def process_image(
|
81 |
pipe,
|
|
|
65 |
)
|
66 |
|
67 |
def resize_image(input_image, resolution):
|
68 |
+
# Ensure input_image is a PIL Image object
|
69 |
+
if not isinstance(input_image, Image.Image):
|
70 |
+
raise ValueError("input_image should be a PIL Image object")
|
71 |
+
|
72 |
+
# Convert image to numpy array
|
73 |
+
input_image_np = np.asarray(input_image)
|
74 |
+
|
75 |
+
# Get image dimensions
|
76 |
+
H, W, C = input_image_np.shape
|
77 |
H = float(H)
|
78 |
W = float(W)
|
79 |
+
|
80 |
+
# Calculate the scaling factor
|
81 |
k = float(resolution) / min(H, W)
|
82 |
+
|
83 |
+
# Determine new dimensions
|
84 |
H *= k
|
85 |
W *= k
|
86 |
H = int(np.round(H / 64.0)) * 64
|
87 |
W = int(np.round(W / 64.0)) * 64
|
88 |
+
|
89 |
+
# Resize the image using PIL's resize method
|
90 |
+
img = input_image.resize((W, H), Image.LANCZOS if k > 1 else Image.ANTIALIAS)
|
91 |
+
|
92 |
+
return img
|
93 |
|
94 |
def process_image(
|
95 |
pipe,
|