Spaces:
Runtime error
Runtime error
PelosiFilippo
commited on
Commit
•
1fed0d2
1
Parent(s):
ea1509a
Fix 'super_res_model is not defined' error
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from PIL import Image
|
3 |
|
4 |
import _thread
|
5 |
-
import time
|
6 |
import torch
|
7 |
import numpy as np
|
8 |
from models.network_swinir import SwinIR as net
|
@@ -23,13 +22,14 @@ def load_model():
|
|
23 |
super_res_model.load_state_dict(super_res_pretrained_model[param_key_g] if param_key_g in super_res_pretrained_model.keys() else super_res_pretrained_model, strict=True)
|
24 |
super_res_model.eval()
|
25 |
|
|
|
26 |
_thread.start_new_thread(load_model, tuple())
|
27 |
|
28 |
def predict(input_img):
|
29 |
out = None
|
30 |
|
31 |
# preprocess input
|
32 |
-
if(input_img is not None):
|
33 |
# model predict
|
34 |
img_lq = input_img.astype(np.float32) / 255
|
35 |
img_lq = np.transpose(img_lq if img_lq.shape[2] == 1 else img_lq[:, :, [2, 1, 0]], (2, 0, 1)) # HCW-BGR to CHW-RGB
|
|
|
2 |
from PIL import Image
|
3 |
|
4 |
import _thread
|
|
|
5 |
import torch
|
6 |
import numpy as np
|
7 |
from models.network_swinir import SwinIR as net
|
|
|
22 |
super_res_model.load_state_dict(super_res_pretrained_model[param_key_g] if param_key_g in super_res_pretrained_model.keys() else super_res_pretrained_model, strict=True)
|
23 |
super_res_model.eval()
|
24 |
|
25 |
+
super_res_model=None
|
26 |
_thread.start_new_thread(load_model, tuple())
|
27 |
|
28 |
def predict(input_img):
|
29 |
out = None
|
30 |
|
31 |
# preprocess input
|
32 |
+
if(input_img is not None and super_res_model is not None):
|
33 |
# model predict
|
34 |
img_lq = input_img.astype(np.float32) / 255
|
35 |
img_lq = np.transpose(img_lq if img_lq.shape[2] == 1 else img_lq[:, :, [2, 1, 0]], (2, 0, 1)) # HCW-BGR to CHW-RGB
|