simonhermansson commited on
Commit
4a83a0f
·
1 Parent(s): 2570c16

Center crop images and resize

Browse files
Files changed (1) hide show
  1. app.py +7 -0
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
8
  import pandas as pd
9
  from PIL import Image
10
  from braceexpand import braceexpand
 
11
 
12
 
13
  # Load model
@@ -165,6 +166,12 @@ def retrieve(query):
165
  with tarfile.open("files/combined.tar", "r") as tar_file:
166
  image = tar_file.extractfile(f"{image_name}.jpg")
167
  image = Image.open(image).copy()
 
 
 
 
 
 
168
  images.append(image)
169
  return images
170
 
 
8
  import pandas as pd
9
  from PIL import Image
10
  from braceexpand import braceexpand
11
+ from torchvision import transforms
12
 
13
 
14
  # Load model
 
166
  with tarfile.open("files/combined.tar", "r") as tar_file:
167
  image = tar_file.extractfile(f"{image_name}.jpg")
168
  image = Image.open(image).copy()
169
+ # Center crop the image
170
+ width, height = image.size
171
+ new_size = min(width, height)
172
+ image = transforms.CenterCrop(new_size)(image)
173
+ # Resize the image
174
+ image = transforms.Resize((600, 600))(image)
175
  images.append(image)
176
  return images
177