leonelhs commited on
Commit
31579cf
1 Parent(s): 20d6d90
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +69 -0
  3. requirements.txt +5 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea/
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ import gradio as gr
4
+ import numpy as np
5
+ import torch
6
+ from torchvision.utils import make_grid
7
+ from huggingface_hub import snapshot_download
8
+ from zero_dce import enhance_net_nopool
9
+
10
+ os.system("pip freeze")
11
+
12
+ REPO_ID = "leonelhs/lowlight"
13
+ MODEL_NAME = "Epoch99.pth"
14
+
15
+ model = enhance_net_nopool().cpu()
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
+ snapshot_folder = snapshot_download(repo_id=REPO_ID)
18
+ model_path = os.path.join(snapshot_folder, MODEL_NAME)
19
+ state = torch.load(model_path, map_location=device)
20
+ model.load_state_dict(state)
21
+
22
+
23
+ def tensor_to_ndarray(tensor, nrow=1, padding=0, normalize=True):
24
+ grid = make_grid(tensor, nrow, padding, normalize)
25
+ return grid.mul(255).add_(0.5).clamp_(0, 255).permute(1, 2, 0).to("cpu", torch.uint8).numpy()
26
+
27
+
28
+ def inference(image):
29
+ image = (np.asarray(image) / 255.0)
30
+ image = torch.from_numpy(image).float()
31
+ image = image.permute(2, 0, 1)
32
+ image = image.cpu().unsqueeze(0)
33
+ _, enhanced_image, _ = model(image)
34
+ return tensor_to_ndarray(enhanced_image, nrow=8, padding=2, normalize=False)
35
+
36
+
37
+ title = "Zero-DCE"
38
+ description = r"""
39
+ ## Low-Light Image Enhancement using Zero-DCE
40
+
41
+ The model improves the quality of images that have poor contrast, low brightness, and suboptimal exposure.
42
+
43
+ This is an implementation of <a href='https://github.com/Li-Chongyi/Zero-DCE' target='_blank'>Zero-DCE</a>.
44
+
45
+ It has no any particular purpose than start research on AI models.
46
+
47
+ """
48
+
49
+ article = r"""
50
+ Questions, doubts, comments, please email 📧 `leonelhs@gmail.com`
51
+
52
+ This demo is running on a CPU, if you like this project please make us a donation to run on a GPU or just give us a <a href='https://github.com/leonelhs/Zero-DCE' target='_blank'>Github ⭐</a>
53
+
54
+ <a href="https://www.buymeacoffee.com/leonelhs"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=leonelhs&button_colour=FFDD00&font_colour=000000&font_family=Cookie&outline_colour=000000&coffee_colour=ffffff" /></a>
55
+
56
+ <center><img src='https://visitor-badge.glitch.me/badge?page_id=zerodce.visitor-badge' alt='visitor badge'></center>
57
+ """
58
+
59
+ demo = gr.Interface(
60
+ inference, [
61
+ gr.Image(type="pil", label="Image low light"),
62
+ ], [
63
+ gr.Image(type="numpy", label="Image enhanced")
64
+ ],
65
+ title=title,
66
+ description=description,
67
+ article=article)
68
+
69
+ demo.queue().launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ torch>=2.0.1
2
+ zero_dce
3
+
4
+
5
+