swzamir commited on
Commit
e84ed63
1 Parent(s): cae5c8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -16
app.py CHANGED
@@ -18,28 +18,35 @@ examples = [['sample_images/Real_Denoising/degraded/117355.png', 'Denoising'],
18
  ['sample_images/Motion_Deblurring/degraded/GoPro-GOPR0854_11_00-000090-input.jpg','Motion Deblurring'],
19
  ['sample_images/Deraining/degraded/Rain100H-77-input.jpg','Deraining']]
20
 
 
21
 
22
  title = "Restormer"
23
  description = """
24
- Gradio demo for Restormer: Efficient Transformer for High-Resolution Image Restoration, CVPR 2022--ORAL. <a href='https://arxiv.org/abs/2111.09881'>[Paper]</a><a href='https://github.com/swz30/Restormer'>[Github Code]</a>\n
25
- With Restormer, you can perform: (1) Image Denoising, (2) Defocus Deblurring, (3) Motion Deblurring, and (4) Image Deraining.
26
- To use it, simply upload your own image, or click one of the examples provided below.
27
  """
 
 
 
28
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2111.09881'>Restormer: Efficient Transformer for High-Resolution Image Restoration </a> | <a href='https://github.com/swz30/Restormer'>Github Repo</a></p>"
29
 
30
 
31
- def inference(img,task):
32
- os.system('mkdir temp')
33
-
34
- # Resize the longer edge of the input image
35
- max_res = 512
36
- width, height = img.size
37
- if max(width,height) > max_res:
38
- scale = max_res /max(width,height)
39
- width = int(scale*width)
40
- height = int(scale*height)
41
- img = img.resize((width,height), Image.ANTIALIAS)
42
-
 
 
 
 
43
  img.save("temp/image.jpg", "JPEG")
44
 
45
  if task == 'Motion Deblurring':
@@ -63,12 +70,15 @@ gr.Interface(
63
  inference,
64
  [
65
  gr.inputs.Image(type="pil", label="Input"),
66
- gr.inputs.Radio(["Denoising", "Defocus Deblurring", "Motion Deblurring", "Deraining"], default="Denoising", label='task type')
 
 
67
  ],
68
  gr.outputs.Image(type="file", label="Output"),
69
  title=title,
70
  description=description,
71
  article=article,
 
72
  examples=examples,
73
  allow_flagging=False,
74
  ).launch(debug=False,enable_queue=True)
18
  ['sample_images/Motion_Deblurring/degraded/GoPro-GOPR0854_11_00-000090-input.jpg','Motion Deblurring'],
19
  ['sample_images/Deraining/degraded/Rain100H-77-input.jpg','Deraining']]
20
 
21
+ inference_on = ['Full Resolution Image', 'Downsampled Image']
22
 
23
  title = "Restormer"
24
  description = """
25
+ Gradio demo for <b>Restormer: Efficient Transformer for High-Resolution Image Restoration</b>, CVPR 2022--ORAL. <a href='https://arxiv.org/abs/2111.09881'>[Paper]</a><a href='https://github.com/swz30/Restormer'>[Github Code]</a>\n
26
+ <b> Note:</b> Since this demo uses CPU, by default it will run on the downsampled version of the input image (for speedup). But if you want to perform inference on the original input, then choose the option "Full Resolution Image" from the dropdown menu.
 
27
  """
28
+ ##With Restormer, you can perform: (1) Image Denoising, (2) Defocus Deblurring, (3) Motion Deblurring, and (4) Image Deraining.
29
+ ##To use it, simply upload your own image, or click one of the examples provided below.
30
+
31
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2111.09881'>Restormer: Efficient Transformer for High-Resolution Image Restoration </a> | <a href='https://github.com/swz30/Restormer'>Github Repo</a></p>"
32
 
33
 
34
+ def inference(img, task, run_on):
35
+ if not os.path.exists('temp'):
36
+ os.system('mkdir temp')
37
+
38
+ if run_on == 'Full Resolution Image':
39
+ img = img
40
+ else: # 'Downsampled Image'
41
+ #### Resize the longer edge of the input image
42
+ max_res = 512
43
+ width, height = img.size
44
+ if max(width,height) > max_res:
45
+ scale = max_res /max(width,height)
46
+ width = int(scale*width)
47
+ height = int(scale*height)
48
+ img = img.resize((width,height), Image.ANTIALIAS)
49
+
50
  img.save("temp/image.jpg", "JPEG")
51
 
52
  if task == 'Motion Deblurring':
70
  inference,
71
  [
72
  gr.inputs.Image(type="pil", label="Input"),
73
+ gr.inputs.Radio(["Denoising", "Defocus Deblurring", "Motion Deblurring", "Deraining"], default="Denoising", label='task'),
74
+ gr.inputs.Dropdown(choices=inference_on, type="value", default='Downsampled Image', label='Inference on')
75
+
76
  ],
77
  gr.outputs.Image(type="file", label="Output"),
78
  title=title,
79
  description=description,
80
  article=article,
81
+ theme ="huggingface",
82
  examples=examples,
83
  allow_flagging=False,
84
  ).launch(debug=False,enable_queue=True)