秋山翔 commited on
Commit
af3dcd2
1 Parent(s): 8bc4bd8

MAINT: auto-resize

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -9,6 +9,8 @@ import torchvision.transforms as transforms
9
  from torch.autograd import Variable
10
  from network.Transformer import Transformer
11
 
 
 
12
  import logging
13
 
14
  logger = logging.getLogger(__name__)
@@ -67,16 +69,16 @@ def get_model(style):
67
  return shinkai_model
68
 
69
 
70
- def validate_image_size(img):
71
  logger.info(f"Image Height: {img.height}, Image Width: {img.width}")
72
  if img.height > MAX_DIMENSION or img.width > MAX_DIMENSION:
73
- raise RuntimeError(
74
- "Image size is too large. Please use an image less than {MAX_DIMENSION}px on both width and height"
75
- )
76
 
77
 
78
  def inference(img, style):
79
- validate_image_size(img)
80
 
81
  # load image
82
  input_image = img.convert(COLOUR_MODEL)
 
9
  from torch.autograd import Variable
10
  from network.Transformer import Transformer
11
 
12
+ from PIL import Image
13
+
14
  import logging
15
 
16
  logger = logging.getLogger(__name__)
 
69
  return shinkai_model
70
 
71
 
72
+ def adjust_image_for_model(img):
73
  logger.info(f"Image Height: {img.height}, Image Width: {img.width}")
74
  if img.height > MAX_DIMENSION or img.width > MAX_DIMENSION:
75
+ img = img.thumbnail(MAX_DIMENSION, Image.ANTIALIAS)
76
+
77
+ return img
78
 
79
 
80
  def inference(img, style):
81
+ img = adjust_image_for_model(img)
82
 
83
  # load image
84
  input_image = img.convert(COLOUR_MODEL)