Ahsen Khaliq commited on
Commit
04cc780
1 Parent(s): cf58652

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -7,6 +7,7 @@ from random import randint
7
  import sys
8
  from subprocess import call
9
 
 
10
 
11
 
12
  torch.hub.download_url_to_file('http://people.csail.mit.edu/billf/project%20pages/sresCode/Markov%20Random%20Fields%20for%20Super-Resolution_files/100075_lowres.jpg', 'bear.jpg')
@@ -42,6 +43,20 @@ def inference(img):
42
  run_cmd("python inference_realesrgan.py --model_path RealESRGAN_x4plus.pth --input "+ INPUT_DIR + " --output " + OUTPUT_DIR + " --netscale 4 --outscale 3.5")
43
  return os.path.join(OUTPUT_DIR, "1_out.jpg")
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
 
47
  title = "Real-ESRGAN"
@@ -49,7 +64,7 @@ description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image,
49
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
50
 
51
  gr.Interface(
52
- inference,
53
  [gr.inputs.Image(type="pil", label="Input")],
54
  gr.outputs.Image(type="file", label="Output"),
55
  title=title,
 
7
  import sys
8
  from subprocess import call
9
 
10
+ torch.hub.download_url_to_file('https://i.imgur.com/tXrot31.jpg', 'cpu.jpg')
11
 
12
 
13
  torch.hub.download_url_to_file('http://people.csail.mit.edu/billf/project%20pages/sresCode/Markov%20Random%20Fields%20for%20Super-Resolution_files/100075_lowres.jpg', 'bear.jpg')
 
43
  run_cmd("python inference_realesrgan.py --model_path RealESRGAN_x4plus.pth --input "+ INPUT_DIR + " --output " + OUTPUT_DIR + " --netscale 4 --outscale 3.5")
44
  return os.path.join(OUTPUT_DIR, "1_out.jpg")
45
 
46
+ inferences_running = 0
47
+ def throttled_inference(image):
48
+ global inferences_running
49
+ current = inferences_running
50
+ if current >= 5:
51
+ print(f"Rejected inference when we already had {current} running")
52
+ return "cpu.jpg"
53
+ print(f"Inference starting when we already had {current} running")
54
+ inferences_running += 1
55
+ try:
56
+ return gradio_inference(image)
57
+ finally:
58
+ print("Inference finished")
59
+ inferences_running -= 1
60
 
61
 
62
  title = "Real-ESRGAN"
 
64
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2107.10833'>Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data</a> | <a href='https://github.com/xinntao/Real-ESRGAN'>Github Repo</a></p>"
65
 
66
  gr.Interface(
67
+ throttled_inference,
68
  [gr.inputs.Image(type="pil", label="Input")],
69
  gr.outputs.Image(type="file", label="Output"),
70
  title=title,