Ahsen Khaliq commited on
Commit
503d196
·
1 Parent(s): 8f9a0bc

Update app.py

Browse files
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')
@@ -486,25 +485,12 @@ def gradio_inference(image):
486
  resize_h=400, # resize original input to this size. None means do not resize.
487
  resize_w=400, # resize original input to this size. None means do not resize.
488
  serial=True) # if need animation, serial must be True.
489
- inferences_running = 0
490
- def throttled_inference(image):
491
- global inferences_running
492
- current = inferences_running
493
- if current >= 5:
494
- print(f"Rejected inference when we already had {current} running")
495
- return "gpu.jpg",Image.open("gpu.jpg")
496
- print(f"Inference starting when we already had {current} running")
497
- inferences_running += 1
498
- try:
499
- return gradio_inference(image)
500
- finally:
501
- print("Inference finished")
502
- inferences_running -= 1
503
  title = "Paint Transformer"
504
  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."
505
  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>"
506
  gr.Interface(
507
- throttled_inference,
508
  gr.inputs.Image(type="file", label="Input"),
509
  [gr.outputs.Image(type="file", label="Output GIF"),
510
  gr.outputs.Image(type="pil", label="Output Image")],
@@ -514,5 +500,6 @@ gr.Interface(
514
  examples=[
515
  ['city.jpg'],
516
  ['tower.jpg']
517
- ]
 
518
  ).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')
 
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
+
 
 
 
 
 
 
 
 
 
 
 
 
 
489
  title = "Paint Transformer"
490
  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."
491
  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>"
492
  gr.Interface(
493
+ gradio_inference,
494
  gr.inputs.Image(type="file", label="Input"),
495
  [gr.outputs.Image(type="file", label="Output GIF"),
496
  gr.outputs.Image(type="pil", label="Output Image")],
 
500
  examples=[
501
  ['city.jpg'],
502
  ['tower.jpg']
503
+ ],
504
+ enable_queue=True
505
  ).launch(debug=True)