Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,20 +18,27 @@ pipe.load_lora_weights(
|
|
| 18 |
weight_name="visual-identity-design.safetensors"
|
| 19 |
)
|
| 20 |
|
| 21 |
-
def
|
| 22 |
if img.mode in ('RGBA', 'P'):
|
| 23 |
img = img.convert('RGB')
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
crop_size = min(width, height)
|
| 27 |
-
|
|
|
|
| 28 |
left = (width - crop_size) // 2
|
| 29 |
top = (height - crop_size) // 2
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
def duplicate_horizontally(img):
|
| 37 |
# Convert PIL Image to numpy array
|
|
|
|
| 18 |
weight_name="visual-identity-design.safetensors"
|
| 19 |
)
|
| 20 |
|
| 21 |
+
def square_center_crop_numpy(img, target_size=768):
|
| 22 |
if img.mode in ('RGBA', 'P'):
|
| 23 |
img = img.convert('RGB')
|
| 24 |
+
|
| 25 |
+
# Convert PIL image to numpy array
|
| 26 |
+
img_array = np.array(img)
|
| 27 |
+
|
| 28 |
+
# Get dimensions
|
| 29 |
+
height, width = img_array.shape[:2]
|
| 30 |
crop_size = min(width, height)
|
| 31 |
+
|
| 32 |
+
# Calculate crop coordinates
|
| 33 |
left = (width - crop_size) // 2
|
| 34 |
top = (height - crop_size) // 2
|
| 35 |
+
|
| 36 |
+
# Perform the crop on numpy array
|
| 37 |
+
img_cropped = img_array[top:top+crop_size, left:left+crop_size]
|
| 38 |
+
|
| 39 |
+
# Convert back to PIL and resize
|
| 40 |
+
img_pil = Image.fromarray(img_cropped)
|
| 41 |
+
return img_pil.resize((target_size, target_size), Image.Resampling.LANCZOS)
|
| 42 |
|
| 43 |
def duplicate_horizontally(img):
|
| 44 |
# Convert PIL Image to numpy array
|