Ahsen Khaliq commited on
Commit
1ec5abc
1 Parent(s): 6dab69a
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -12,7 +12,6 @@ import torchtext
12
  from stat import ST_CTIME
13
  from datetime import datetime, timedelta
14
  import shutil
15
- torch.hub.download_url_to_file('https://i.imgur.com/tXrot31.jpg', 'gpu.jpg')
16
  # Images
17
  torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2021/08/04/14/16/tower-6521842_1280.jpg', 'tower.jpg')
18
  torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2017/08/31/05/36/buildings-2699520_1280.jpg', 'city.jpg')
@@ -485,25 +484,12 @@ def gradio_inference(image):
485
  resize_h=400, # resize original input to this size. None means do not resize.
486
  resize_w=400, # resize original input to this size. None means do not resize.
487
  serial=True) # if need animation, serial must be True.
488
- inferences_running = 0
489
- def throttled_inference(image):
490
- global inferences_running
491
- current = inferences_running
492
- if current >= 5:
493
- print(f"Rejected inference when we already had {current} running")
494
- return "gpu.jpg",Image.open("gpu.jpg")
495
- print(f"Inference starting when we already had {current} running")
496
- inferences_running += 1
497
- try:
498
- return gradio_inference(image)
499
- finally:
500
- print("Inference finished")
501
- inferences_running -= 1
502
  title = "Paint Transformer"
503
  description = "Gradio demo for Paint Transformer: Feed Forward Neural Painting with Stroke Prediction. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
504
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.03798'>Paint Transformer: Feed Forward Neural Painting with Stroke Prediction</a> | <a href='https://github.com/Huage001/PaintTransformer'>Github Repo</a></p>"
505
  gr.Interface(
506
- throttled_inference,
507
  gr.inputs.Image(type="file", label="Input"),
508
  [gr.outputs.Image(type="file", label="Output GIF"),
509
  gr.outputs.Image(type="pil", label="Output Image")],
@@ -513,5 +499,6 @@ gr.Interface(
513
  examples=[
514
  ['city.jpg'],
515
  ['tower.jpg']
516
- ]
 
517
  ).launch(debug=True)
 
12
  from stat import ST_CTIME
13
  from datetime import datetime, timedelta
14
  import shutil
 
15
  # Images
16
  torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2021/08/04/14/16/tower-6521842_1280.jpg', 'tower.jpg')
17
  torch.hub.download_url_to_file('https://cdn.pixabay.com/photo/2017/08/31/05/36/buildings-2699520_1280.jpg', 'city.jpg')
 
484
  resize_h=400, # resize original input to this size. None means do not resize.
485
  resize_w=400, # resize original input to this size. None means do not resize.
486
  serial=True) # if need animation, serial must be True.
487
+
 
 
 
 
 
 
 
 
 
 
 
 
 
488
  title = "Paint Transformer"
489
  description = "Gradio demo for Paint Transformer: Feed Forward Neural Painting with Stroke Prediction. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
490
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2108.03798'>Paint Transformer: Feed Forward Neural Painting with Stroke Prediction</a> | <a href='https://github.com/Huage001/PaintTransformer'>Github Repo</a></p>"
491
  gr.Interface(
492
+ gradio_inference,
493
  gr.inputs.Image(type="file", label="Input"),
494
  [gr.outputs.Image(type="file", label="Output GIF"),
495
  gr.outputs.Image(type="pil", label="Output Image")],
 
499
  examples=[
500
  ['city.jpg'],
501
  ['tower.jpg']
502
+ ],
503
+ enable_queue=True
504
  ).launch(debug=True)