Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
index.py
CHANGED
@@ -17,31 +17,35 @@ load_dotenv(dotenv_path)
|
|
17 |
REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
|
18 |
|
19 |
def generate_pattern(image, prompt):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
#
|
26 |
-
if starter_image_pil.size[0] > starter_image_pil.size[1]:
|
27 |
-
#
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
45 |
|
46 |
|
47 |
# Create a new image with black background and white cross
|
|
|
17 |
REPLICATE_API_TOKEN = os.getenv('REPLICATE_API_TOKEN')
|
18 |
|
19 |
def generate_pattern(image, prompt):
|
20 |
+
|
21 |
+
if image is not None:
|
22 |
+
# Convert the numpy array to a PIL image
|
23 |
+
starter_image_pil = Image.fromarray(image.astype('uint8'))
|
24 |
+
|
25 |
+
# Resize the starter image if either dimension is larger than 768 pixels
|
26 |
+
if starter_image_pil.size[0] > 768 or starter_image_pil.size[1] > 768:
|
27 |
+
# Calculate the new size while maintaining the aspect ratio
|
28 |
+
if starter_image_pil.size[0] > starter_image_pil.size[1]:
|
29 |
+
# Width is larger than height
|
30 |
+
new_width = 768
|
31 |
+
new_height = int((768 / starter_image_pil.size[0]) * starter_image_pil.size[1])
|
32 |
+
else:
|
33 |
+
# Height is larger than width
|
34 |
+
new_height = 768
|
35 |
+
new_width = int((768 / starter_image_pil.size[1]) * starter_image_pil.size[0])
|
36 |
+
|
37 |
+
# Resize the image
|
38 |
+
starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
|
39 |
+
|
40 |
+
|
41 |
+
# Move the image horizontally and vertically by 50%
|
42 |
+
width, height = starter_image_pil.size
|
43 |
+
horizontal_shift = width // 2
|
44 |
+
vertical_shift = height // 2
|
45 |
+
|
46 |
+
transformed_image_pil = ImageChops.offset(starter_image_pil, horizontal_shift, vertical_shift)
|
47 |
+
else:
|
48 |
+
raise gr.Error(f"Please upload an image")
|
49 |
|
50 |
|
51 |
# Create a new image with black background and white cross
|