Ahsen Khaliq commited on
Commit
d408b90
1 Parent(s): 0956b85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -3
app.py CHANGED
@@ -7,7 +7,9 @@ from random import randint
7
  import sys
8
  from subprocess import call
9
 
10
-
 
 
11
  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')
12
 
13
 
@@ -41,13 +43,28 @@ def inference(img):
41
  run_cmd("python inference_realesrgan.py --model_path RealESRGAN_x4plus.pth --input "+ INPUT_DIR + " --output " + OUTPUT_DIR + " --netscale 4 --outscale 3.5")
42
  return os.path.join(OUTPUT_DIR, "1_out.jpg")
43
 
44
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  title = "Real-ESRGAN"
46
  description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
47
  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>"
48
 
49
  gr.Interface(
50
- inference,
51
  [gr.inputs.Image(type="pil", label="Input")],
52
  gr.outputs.Image(type="file", label="Output"),
53
  title=title,
 
7
  import sys
8
  from subprocess import call
9
 
10
+
11
+ torch.hub.download_url_to_file('https://i.imgur.com/tXrot31.jpg', 'cpu.jpg')
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')
14
 
15
 
 
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
+
47
+ inferences_running = 0
48
+ def throttled_inference(image):
49
+ global inferences_running
50
+ current = inferences_running
51
+ if current >= 5:
52
+ print(f"Rejected inference when we already had {current} running")
53
+ return "cpu.jpg"
54
+ print(f"Inference starting when we already had {current} running")
55
+ inferences_running += 1
56
+ try:
57
+ return inference(image)
58
+ finally:
59
+ print("Inference finished")
60
+ inferences_running -= 1
61
+
62
  title = "Real-ESRGAN"
63
  description = "Gradio demo for Real-ESRGAN. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
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,