IanNathaniel commited on
Commit
690c3ba
1 Parent(s): ac46847

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -52
app.py CHANGED
@@ -1,52 +1,52 @@
1
- import gradio as gr
2
- import torch
3
- import torch.nn as nn
4
- import torchvision
5
- import torch.backends.cudnn as cudnn
6
- import torch.optim
7
- import os
8
- import sys
9
- import argparse
10
- import dataloader
11
- import model
12
- import numpy as np
13
- from torchvision import transforms
14
- from PIL import Image
15
- import glob
16
-
17
-
18
- def lowlight(image):
19
- os.environ['CUDA_VISIBLE_DEVICES']=''
20
- data_lowlight = Image.open(image)
21
-
22
- data_lowlight = (np.asarray(data_lowlight)/255.0)
23
- data_lowlight = torch.from_numpy(data_lowlight).float()
24
- data_lowlight = data_lowlight.permute(2,0,1)
25
- data_lowlight = data_lowlight.cpu().unsqueeze(0)
26
-
27
- DCE_net = model.enhance_net_nopool().cpu()
28
- DCE_net.load_state_dict(torch.load('Epoch99.pth', map_location=torch.device('cpu')))
29
-
30
- _,enhanced_image,_ = DCE_net(data_lowlight)
31
-
32
- torchvision.utils.save_image(enhanced_image, f'01.png')
33
-
34
- return '01.png'
35
-
36
-
37
- title = "Low-Light Image Enhancement using Zero-DCE"
38
- description = "Gradio Demo for Low-Light Enhancement using Zero-DCE. The model improves the quality of images that have poor contrast, low brightness, and suboptimal exposure. To use it, simply upload your image, or click one of the examples to load them. Check out the original paper and the GitHub repo at the links below. "
39
- article = "<p style='text-align: center'><a href='http://openaccess.thecvf.com/content_CVPR_2020/papers/Guo_Zero-Reference_Deep_Curve_Estimation_for_Low-Light_Image_Enhancement_CVPR_2020_paper.pdf' target='_blank'>Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement</a> | <a href='https://github.com/Li-Chongyi/Zero-DCE' target='_blank'>Github Repo</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=52Hz_CMFNet_deblurring' alt='visitor badge'></center>"
40
-
41
- examples = [['01.jpg'], ['02.jpg'], ['03.jpg'], ['04.png'], ['05.jpg'],]
42
- gr.Interface(
43
- lowlight,
44
- [gr.inputs.Image(type="file", label="Input")],
45
- [gr.outputs.Image(type="file", label="Output")],
46
- title=title,
47
- description=description,
48
- article=article,
49
- allow_flagging=False,
50
- allow_screenshot=False,
51
- examples=examples
52
- ).launch(debug=True)
1
+ import gradio as gr
2
+ import torch
3
+ import torch.nn as nn
4
+ import torchvision
5
+ import torch.backends.cudnn as cudnn
6
+ import torch.optim
7
+ import os
8
+ import sys
9
+ import argparse
10
+ import dataloader
11
+ import model
12
+ import numpy as np
13
+ from torchvision import transforms
14
+ from PIL import Image
15
+ import glob
16
+
17
+
18
+ def lowlight(image):
19
+ os.environ['CUDA_VISIBLE_DEVICES']=''
20
+ data_lowlight = Image.open(image)
21
+
22
+ data_lowlight = (np.asarray(data_lowlight)/255.0)
23
+ data_lowlight = torch.from_numpy(data_lowlight).float()
24
+ data_lowlight = data_lowlight.permute(2,0,1)
25
+ data_lowlight = data_lowlight.cpu().unsqueeze(0)
26
+
27
+ DCE_net = model.enhance_net_nopool().cpu()
28
+ DCE_net.load_state_dict(torch.load('Epoch99.pth', map_location=torch.device('cpu')))
29
+
30
+ _,enhanced_image,_ = DCE_net(data_lowlight)
31
+
32
+ torchvision.utils.save_image(enhanced_image, f'01.png')
33
+
34
+ return '01.png'
35
+
36
+
37
+ title = "Low-Light Image Enhancement using Zero-DCE"
38
+ description = "Gradio Demo for Low-Light Enhancement using Zero-DCE. The model improves the quality of images that have poor contrast, low brightness, and suboptimal exposure. To use it, simply upload your image, or click one of the examples to load them. Check out the original paper and the GitHub repo at the links below. "
39
+ article = "<p style='text-align: center'><a href='http://openaccess.thecvf.com/content_CVPR_2020/papers/Guo_Zero-Reference_Deep_Curve_Estimation_for_Low-Light_Image_Enhancement_CVPR_2020_paper.pdf' target='_blank'>Zero-Reference Deep Curve Estimation for Low-Light Image Enhancement</a> | <a href='https://github.com/Li-Chongyi/Zero-DCE' target='_blank'>Github Repo</a></p> <center><img src='https://visitor-badge.glitch.me/badge?page_id=52Hz_CMFNet_deblurring' alt='visitor badge'></center>"
40
+
41
+ examples = [['01.jpg'], ['02.jpg'], ['03.jpg'], ['04.png'], ['05.jpg'],]
42
+ gr.Interface(
43
+ lowlight,
44
+ [gr.inputs.Image(type="file", label="Input")],
45
+ [gr.outputs.Image(type="file", label="Output")],
46
+ title=title,
47
+ description=description,
48
+ article=article,
49
+ allow_flagging=False,
50
+ allow_screenshot=False,
51
+ examples=examples
52
+ ).launch(debug=True)