Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -22,10 +22,11 @@ if not os.path.exists(MODEL_PATH):
|
|
22 |
# Define the Real-ESRGAN class
|
23 |
class RealESRGAN:
|
24 |
def __init__(self, model_path, device):
|
25 |
-
#
|
26 |
-
self.model = torch.hub.load('xinntao/Real-ESRGAN', 'real_esrgan',
|
27 |
-
self.model.eval()
|
28 |
-
|
|
|
29 |
def upscale(self, image_tensor):
|
30 |
with torch.no_grad():
|
31 |
sr_image_tensor = self.model(image_tensor).clamp(0, 1)
|
@@ -39,7 +40,7 @@ def upscale_image(image):
|
|
39 |
# Pre-process the input image
|
40 |
image = image.convert("RGB")
|
41 |
transform = transforms.ToTensor()
|
42 |
-
image_tensor = transform(image).unsqueeze(0) # Add batch dimension
|
43 |
|
44 |
# Perform upscaling
|
45 |
sr_image_tensor = model.upscale(image_tensor)
|
|
|
22 |
# Define the Real-ESRGAN class
|
23 |
class RealESRGAN:
|
24 |
def __init__(self, model_path, device):
|
25 |
+
# Correctly load the model
|
26 |
+
self.model = torch.hub.load('xinntao/Real-ESRGAN', 'real_esrgan', model_path, device=device)
|
27 |
+
self.model.eval() # Set the model to eval mode
|
28 |
+
self.device = device # Store the device
|
29 |
+
|
30 |
def upscale(self, image_tensor):
|
31 |
with torch.no_grad():
|
32 |
sr_image_tensor = self.model(image_tensor).clamp(0, 1)
|
|
|
40 |
# Pre-process the input image
|
41 |
image = image.convert("RGB")
|
42 |
transform = transforms.ToTensor()
|
43 |
+
image_tensor = transform(image).unsqueeze(0).to(device) # Add batch dimension and move to device
|
44 |
|
45 |
# Perform upscaling
|
46 |
sr_image_tensor = model.upscale(image_tensor)
|