Leeps commited on
Commit
0a943dd
·
verified ·
1 Parent(s): 78b6602

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. index.py +29 -25
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
- # Convert the numpy array to a PIL image
21
- starter_image_pil = Image.fromarray(image.astype('uint8'))
22
-
23
- # Resize the starter image if either dimension is larger than 768 pixels
24
- if starter_image_pil.size[0] > 768 or starter_image_pil.size[1] > 768:
25
- # Calculate the new size while maintaining the aspect ratio
26
- if starter_image_pil.size[0] > starter_image_pil.size[1]:
27
- # Width is larger than height
28
- new_width = 768
29
- new_height = int((768 / starter_image_pil.size[0]) * starter_image_pil.size[1])
30
- else:
31
- # Height is larger than width
32
- new_height = 768
33
- new_width = int((768 / starter_image_pil.size[1]) * starter_image_pil.size[0])
34
-
35
- # Resize the image
36
- starter_image_pil = starter_image_pil.resize((new_width, new_height), Image.LANCZOS)
37
-
38
-
39
- # Move the image horizontally and vertically by 50%
40
- width, height = starter_image_pil.size
41
- horizontal_shift = width // 2
42
- vertical_shift = height // 2
43
-
44
- transformed_image_pil = ImageChops.offset(starter_image_pil, horizontal_shift, vertical_shift)
 
 
 
 
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