saidennis commited on
Commit
becf435
·
verified ·
1 Parent(s): e72c3c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -6
app.py CHANGED
@@ -21,6 +21,32 @@ ASSETS = {
21
  "logo": "logo.png"
22
  }
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def validate_assets():
25
  """Check if all required asset files exist"""
26
  missing = []
@@ -64,7 +90,7 @@ def generate_and_wait_for_image(
64
 
65
  # Prepare all required files
66
  files = {
67
- 'input_image': open(input_image, 'rb'),
68
  'logo_image': open(ASSETS["logo"], 'rb'),
69
  'reference_image': open(ASSETS[garment_type]["reference_image"], 'rb')
70
  }
@@ -208,11 +234,8 @@ with gr.Blocks(title="Virtual Try-On Demo") as demo:
208
  queue=False
209
  )
210
  gr.Markdown("""
211
- # Input image requirements:\n
212
- - Supported formats: jpeg, png, webp
213
- - Minimum Resolution: at least 64 on each side
214
- - Total pixel count: 4,096 to 9,437,184 pixels
215
- - Aspect ratio: 1:2.5 to 2.5:1
216
  """)
217
 
218
  if __name__ == "__main__":
 
21
  "logo": "logo.png"
22
  }
23
 
24
+ def resize_image_to_short_edge(image_path, max_short_edge=1280):
25
+ """Resize image so the short edge is at most max_short_edge pixels"""
26
+ img = Image.open(image_path)
27
+ width, height = img.size
28
+
29
+ # Determine scaling factor
30
+ if width < height:
31
+ if width <= max_short_edge:
32
+ return image_path # No resizing needed
33
+ scaling_factor = max_short_edge / width
34
+ else:
35
+ if height <= max_short_edge:
36
+ return image_path # No resizing needed
37
+ scaling_factor = max_short_edge / height
38
+
39
+ # Calculate new dimensions and resize
40
+ new_width = int(width * scaling_factor)
41
+ new_height = int(height * scaling_factor)
42
+ resized_img = img.resize((new_width, new_height), Image.LANCZOS)
43
+
44
+ # Save to bytes buffer
45
+ buffer = io.BytesIO()
46
+ resized_img.save(buffer, format=img.format)
47
+ buffer.seek(0)
48
+ return buffer
49
+
50
  def validate_assets():
51
  """Check if all required asset files exist"""
52
  missing = []
 
90
 
91
  # Prepare all required files
92
  files = {
93
+ 'input_image': resize_image_to_short_edge(input_image),
94
  'logo_image': open(ASSETS["logo"], 'rb'),
95
  'reference_image': open(ASSETS[garment_type]["reference_image"], 'rb')
96
  }
 
234
  queue=False
235
  )
236
  gr.Markdown("""
237
+ # Note:\n
238
+ The image will be resized to 1280px on the short edge.
 
 
 
239
  """)
240
 
241
  if __name__ == "__main__":