doevent commited on
Commit
70913b7
1 Parent(s): ec720ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -7
app.py CHANGED
@@ -2,8 +2,6 @@ import torch
2
  from PIL import Image
3
  from RealESRGAN import RealESRGAN
4
  import gradio as gr
5
- import gc
6
- import spaces
7
 
8
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
9
  model2 = RealESRGAN(device, scale=2)
@@ -13,12 +11,7 @@ model4.load_weights('weights/RealESRGAN_x4.pth', download=True)
13
  model8 = RealESRGAN(device, scale=8)
14
  model8.load_weights('weights/RealESRGAN_x8.pth', download=True)
15
 
16
- if torch.cuda.is_available():
17
- torch.cuda.empty_cache()
18
- gc.collect()
19
 
20
-
21
- @spaces.GPU
22
  def inference(image, size):
23
  if image is None:
24
  raise gr.Error("Image not uploaded")
@@ -26,6 +19,9 @@ def inference(image, size):
26
  width, height = image.size
27
  if width >= 5000 or height >= 5000:
28
  raise gr.Error("The image is too large.")
 
 
 
29
 
30
  if size == '2x':
31
  result = model2.predict(image.convert('RGB'))
 
2
  from PIL import Image
3
  from RealESRGAN import RealESRGAN
4
  import gradio as gr
 
 
5
 
6
  device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
7
  model2 = RealESRGAN(device, scale=2)
 
11
  model8 = RealESRGAN(device, scale=8)
12
  model8.load_weights('weights/RealESRGAN_x8.pth', download=True)
13
 
 
 
 
14
 
 
 
15
  def inference(image, size):
16
  if image is None:
17
  raise gr.Error("Image not uploaded")
 
19
  width, height = image.size
20
  if width >= 5000 or height >= 5000:
21
  raise gr.Error("The image is too large.")
22
+
23
+ if torch.cuda.is_available():
24
+ torch.cuda.empty_cache()
25
 
26
  if size == '2x':
27
  result = model2.predict(image.convert('RGB'))