Spaces:
Running
on
Zero
Running
on
Zero
Update infer.py
Browse files
infer.py
CHANGED
@@ -6,10 +6,12 @@ import tempfile
|
|
6 |
import numpy as np
|
7 |
import tqdm
|
8 |
import ffmpeg
|
|
|
9 |
|
10 |
|
11 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
12 |
|
|
|
13 |
def infer_image(img: Image.Image, size_modifier: int ) -> Image.Image:
|
14 |
if img is None:
|
15 |
raise Exception("Image not uploaded")
|
@@ -26,6 +28,7 @@ def infer_image(img: Image.Image, size_modifier: int ) -> Image.Image:
|
|
26 |
print(f"Image size ({device}): {size_modifier} ... OK")
|
27 |
return result
|
28 |
|
|
|
29 |
def infer_video(video_filepath: str, size_modifier: int) -> str:
|
30 |
model = RealESRGAN(device, scale=size_modifier)
|
31 |
model.load_weights(f'weights/RealESRGAN_x{size_modifier}.pth', download=False)
|
|
|
6 |
import numpy as np
|
7 |
import tqdm
|
8 |
import ffmpeg
|
9 |
+
import spaces
|
10 |
|
11 |
|
12 |
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
13 |
|
14 |
+
@spaces.GPU(duration=60 * 2)
|
15 |
def infer_image(img: Image.Image, size_modifier: int ) -> Image.Image:
|
16 |
if img is None:
|
17 |
raise Exception("Image not uploaded")
|
|
|
28 |
print(f"Image size ({device}): {size_modifier} ... OK")
|
29 |
return result
|
30 |
|
31 |
+
@spaces.GPU(duration=60 * 5)
|
32 |
def infer_video(video_filepath: str, size_modifier: int) -> str:
|
33 |
model = RealESRGAN(device, scale=size_modifier)
|
34 |
model.load_weights(f'weights/RealESRGAN_x{size_modifier}.pth', download=False)
|