Eugene Siow commited on
Commit
3cd9827
·
1 Parent(s): 30a37ef

Add basic error handling on input.

Browse files
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -46,11 +46,15 @@ def inference(img, scale_str, model_name):
46
  if width > 2048 or height > 2048:
47
  img = img.thumbnail((2048, 2048), Image.ANTIALIAS)
48
  model = get_model(model_name, scale)
49
- inputs = ImageLoader.load_image(img)
50
- preds = model(inputs)
51
- preds = preds.data.cpu().numpy()
52
- pred = preds[0].transpose((1, 2, 0)) * 255.0
53
- return Image.fromarray(pred.astype('uint8'), 'RGB')
 
 
 
 
54
 
55
 
56
  torch.hub.download_url_to_file('http://people.rennes.inria.fr/Aline.Roumy/results/images_SR_BMVC12/input_groundtruth/baby_mini_d3_gaussian.bmp',
 
46
  if width > 2048 or height > 2048:
47
  img = img.thumbnail((2048, 2048), Image.ANTIALIAS)
48
  model = get_model(model_name, scale)
49
+ try:
50
+ inputs = ImageLoader.load_image(img)
51
+ preds = model(inputs)
52
+ preds = preds.data.cpu().numpy()
53
+ pred = preds[0].transpose((1, 2, 0)) * 255.0
54
+ return Image.fromarray(pred.astype('uint8'), 'RGB')
55
+ except Exception as e:
56
+ print(e)
57
+ return None
58
 
59
 
60
  torch.hub.download_url_to_file('http://people.rennes.inria.fr/Aline.Roumy/results/images_SR_BMVC12/input_groundtruth/baby_mini_d3_gaussian.bmp',