File size: 2,870 Bytes
8666c23
 
 
 
 
 
 
 
c598f3e
 
ce6a6d5
8666c23
c598f3e
8666c23
 
c598f3e
8666c23
 
c598f3e
8666c23
 
c598f3e
8666c23
 
c598f3e
8666c23
 
c598f3e
8666c23
c598f3e
8666c23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import gradio as gr
import os

def inference(image, task):
    if not os.path.exists('tmp'):
      os.system('mkdir tmp')
    image.save("tmp/lq_image.png", "PNG")
    
    if not os.path.exists('results'):
      os.system('mkdir results')
    
    if task == 'Dehazing':
      os.system("python Dehazing.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/Haze4k.tjm")
  
    if task == 'LLIE':
      os.system("python Lowlight.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/Low.onnx")
    
    if task == 'SuperResolutionx2':
      os.system("python SuperResolution.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/SRx2.pth --scale 2")
    
    if task == 'SuperResolutionx3':
      os.system("python SuperResolution.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/SRx3.pth --scale 3")
      
    if task == 'SuperResolutionx4':
      os.system("python SuperResolution.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/SRx4.pth --scale 4")
        
    if task == 'Underwater Enhancement':
      os.system("python Underwater.py --test_path ./tmp/lq_image.png --save_path ./results/ --pk_path model_zoo/underwater.pth")
      
    return 'results/lq_image.png'
   
title = "Image Enhancement and Restoration"
description = ""
article = ""
#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."
#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>"


examples = [['demo/underwater.jpg', 'Underwater'],
            ['demo/low.jpg', 'LLIE'],
            ['demo/dehaze.jpg', 'Dehazing'],
            ['demo/sr.png', 'SuperResolution']]
            
iface = gr.Interface(
    inference, 
    [gr.inputs.Image(type="pil", label="Input"),
    gr.inputs.Radio(["Underwater", "LLIE", "Dehazing", "SuperResolutionx2", "SuperResolutionx3", "SuperResolutionx4"], default="Underwater", label='task'),], 
    gr.outputs.Image(type="file", label="Output"),
    title=title,
    description=description,
    article=article,
    enable_queue=True,
    examples=examples
    )
iface.launch(debug=True,enable_queue=True)