Prajwal-r-k commited on
Commit
9ebeb6f
·
verified ·
1 Parent(s): 5964ed4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -22
app.py CHANGED
@@ -1,43 +1,53 @@
1
  import gradio as gr
2
  import os
3
 
4
-
5
  os.system("git clone https://github.com/megvii-research/NAFNet")
6
  os.system("mv NAFNet/* ./")
7
  os.system("mv *.pth experiments/pretrained_models/")
8
  os.system("python3 setup.py develop --no_cuda_ext --user")
9
 
10
-
11
  def inference(image, task):
12
  if not os.path.exists('tmp'):
13
- os.system('mkdir tmp')
14
  image.save("tmp/lq_image.png", "PNG")
15
 
16
  if task == 'Denoising':
17
- os.system("python basicsr/demo.py -opt options/test/SIDD/NAFNet-width64.yml --input_path ./tmp/lq_image.png --output_path ./tmp/image.png")
18
-
19
- if task == 'Deblurring':
20
- os.system("python basicsr/demo.py -opt options/test/REDS/NAFNet-width64.yml --input_path ./tmp/lq_image.png --output_path ./tmp/image.png")
21
-
22
- return 'tmp/image.png'
23
-
24
  title = "NAFNet"
25
- description = "Gradio demo for <b>NAFNet: Nonlinear Activation Free Network for Image Restoration</b>. NAFNet achieves state-of-the-art performance on three tasks: image denoising, image debluring and stereo image super-resolution (SR). See the paper and project page for detailed results below. Here, we provide a demo for image denoise and deblur. To use it, simply upload your image, or click one of the examples to load them. Inference needs some time since this demo uses CPU."
26
- article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2204.04676' target='_blank'>Simple Baselines for Image Restoration</a> | <a href='https://arxiv.org/abs/2204.08714' target='_blank'>NAFSSR: Stereo Image Super-Resolution Using NAFNet</a> | <a href='https://github.com/megvii-research/NAFNet' target='_blank'> Github Repo</a></p>"
 
 
 
 
 
 
 
 
27
 
 
28
 
29
- examples = [['demo/noisy.png', 'Denoising'],
30
- ['demo/blurry.jpg', 'Deblurring']]
31
-
32
  iface = gr.Interface(
33
- inference,
34
- [gr.inputs.Image(type="pil", label="Input"),
35
- gr.inputs.Radio(["Denoising", "Deblurring"], default="Denoising", label='task'),],
36
- gr.outputs.Image(type="file", label="Output"),
 
 
37
  title=title,
38
  description=description,
39
  article=article,
40
- enable_queue=True,
41
  examples=examples
42
- )
43
- iface.launch(debug=True,enable_queue=True)
 
 
 
1
  import gradio as gr
2
  import os
3
 
4
+ # Cloning and setting up the model
5
  os.system("git clone https://github.com/megvii-research/NAFNet")
6
  os.system("mv NAFNet/* ./")
7
  os.system("mv *.pth experiments/pretrained_models/")
8
  os.system("python3 setup.py develop --no_cuda_ext --user")
9
 
10
+ # Inference function
11
  def inference(image, task):
12
  if not os.path.exists('tmp'):
13
+ os.makedirs('tmp')
14
  image.save("tmp/lq_image.png", "PNG")
15
 
16
  if task == 'Denoising':
17
+ os.system("python basicsr/demo.py -opt options/test/SIDD/NAFNet-width64.yml --input_path ./tmp/lq_image.png --output_path ./tmp/image.png")
18
+ elif task == 'Deblurring':
19
+ os.system("python basicsr/demo.py -opt options/test/REDS/NAFNet-width64.yml --input_path ./tmp/lq_image.png --output_path ./tmp/image.png")
20
+
21
+ return "tmp/image.png"
22
+
23
+ # Title and description
24
  title = "NAFNet"
25
+ description = """Gradio demo for <b>NAFNet: Nonlinear Activation Free Network for Image Restoration</b>.
26
+ NAFNet achieves state-of-the-art performance on three tasks: image denoising, image deblurring, and stereo image super-resolution (SR).
27
+ See the paper and project page for detailed results below. Here, we provide a demo for image denoise and deblur.
28
+ To use it, simply upload your image, or click one of the examples to load them. Inference needs some time since this demo uses CPU."""
29
+
30
+ article = """<p style='text-align: center'>
31
+ <a href='https://arxiv.org/abs/2204.04676' target='_blank'>Simple Baselines for Image Restoration</a> |
32
+ <a href='https://arxiv.org/abs/2204.08714' target='_blank'>NAFSSR: Stereo Image Super-Resolution Using NAFNet</a> |
33
+ <a href='https://github.com/megvii-research/NAFNet' target='_blank'>Github Repo</a>
34
+ </p>"""
35
 
36
+ examples = [['demo/noisy.png', 'Denoising'], ['demo/blurry.jpg', 'Deblurring']]
37
 
38
+ # Updated Gradio Interface
 
 
39
  iface = gr.Interface(
40
+ fn=inference, # Updated function syntax
41
+ inputs=[
42
+ gr.Image(type="pil", label="Input Image"), # Replaced gr.inputs.Image
43
+ gr.Radio(["Denoising", "Deblurring"], value="Denoising", label="Task") # Replaced gr.inputs.Radio
44
+ ],
45
+ outputs=gr.Image(type="file", label="Output Image"), # Replaced gr.outputs.Image
46
  title=title,
47
  description=description,
48
  article=article,
 
49
  examples=examples
50
+ )
51
+
52
+ # Launch interface
53
+ iface.launch(debug=True)