doevent commited on
Commit
a64a9ce
1 Parent(s): df80b79

Update app.py

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