Spaces:
Runtime error
Runtime error
Eugene Siow
commited on
Commit
·
3cd9827
1
Parent(s):
30a37ef
Add basic error handling on input.
Browse files
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 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
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',
|