Oğuzcan Turan commited on
Commit
7f2197d
1 Parent(s): c6ce017

demo added

Browse files
Files changed (4) hide show
  1. LICENSE +21 -0
  2. README.md +4 -4
  3. app.py +137 -0
  4. requirements.txt +5 -0
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Oğuzcan Turan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
  title: Light Side
3
- emoji: 📈
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: app.py
@@ -10,4 +10,4 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Light Side
3
+ emoji: ⚡️
4
+ colorFrom: black
5
+ colorTo: white
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: app.py
 
10
  license: mit
11
  ---
12
 
13
+ Check out the configuration reference at <https://huggingface.co/docs/hub/spaces-config-reference>
app.py ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ from datetime import datetime
3
+
4
+ import av
5
+ import light_side as ls
6
+ import numpy as np
7
+ import requests
8
+ import streamlit as st
9
+ from PIL import Image
10
+ from streamlit_image_comparison import image_comparison
11
+ from streamlit_webrtc import VideoProcessorBase, webrtc_streamer
12
+
13
+
14
+ def main():
15
+ # pylint: disable=no-member
16
+
17
+ st.set_page_config(
18
+ page_title="Light Side Demo Page",
19
+ page_icon="⚡️",
20
+ layout="centered",
21
+ initial_sidebar_state="expanded",
22
+ menu_items={
23
+ "Get Help": "https://canturan10.github.io/light_side/",
24
+ "About": "Low-Light Image Enhancement",
25
+ },
26
+ )
27
+ st.title("Light Side Demo Page")
28
+
29
+ url = "https://raw.githubusercontent.com/canturan10/light_side/master/src/light_side.png?raw=true"
30
+ light_side = Image.open(requests.get(url, stream=True).raw)
31
+
32
+ st.sidebar.image(light_side, width=100)
33
+ st.sidebar.title("Light Side of the Night")
34
+ st.sidebar.caption(ls.__description__)
35
+
36
+ st.sidebar.write(
37
+ "**Light Side** is an low-light image enhancement library that consist state-of-the-art deep learning methods. The light side of the Force is referenced. The aim is to create a light structure that will find the `Light Side of the Night`."
38
+ )
39
+
40
+ st.sidebar.caption(f"Version: `{ls.__version__}`")
41
+ st.sidebar.caption(f"License: `{ls.__license__}`")
42
+ st.sidebar.caption("")
43
+ st.sidebar.caption(f"[Website](https://lnkd.in/dKejmaH2)")
44
+ st.sidebar.caption(f"[Docs](https://lnkd.in/dt-2T4ZN)")
45
+ st.sidebar.caption(f"[Github](https://lnkd.in/dDttpiEG)")
46
+ # st.sidebar.caption(f"[Demo Page](https://lnkd.in/dxy-632M)")
47
+ st.sidebar.caption(f"[Hugging Face]( https://lnkd.in/d5-VVK62)")
48
+ st.sidebar.caption(f"[Pypi](https://lnkd.in/d7eDNb-B)")
49
+ st.sidebar.caption("")
50
+ st.sidebar.caption(ls.__copyright__)
51
+
52
+ selected_model = st.selectbox(
53
+ "Select model",
54
+ ls.available_models(),
55
+ )
56
+ selected_version = st.selectbox(
57
+ "Select version",
58
+ ls.get_model_versions(selected_model),
59
+ )
60
+
61
+ mode = st.radio("Select Inference Mode", ("Image", "Video (WebRTC)"))
62
+
63
+ model = ls.Enhancer.from_pretrained(selected_model, selected_version)
64
+ model.eval()
65
+
66
+ if mode == "Image":
67
+ uploaded_file = st.file_uploader(
68
+ "", type=["png", "jpg", "jpeg"], accept_multiple_files=False
69
+ )
70
+ if uploaded_file is None:
71
+ st.write("Default Image")
72
+ # Default image.
73
+ url = f"https://github.com/canturan10/light_side/blob/master/src/sample/{random_sample}?raw=true"
74
+ image = Image.open(requests.get(url, stream=True).raw)
75
+
76
+ else:
77
+ # User-selected image.
78
+ image = Image.open(uploaded_file)
79
+
80
+ image = np.array(image.convert("RGB"))
81
+
82
+ results = model.predict(image)[0]
83
+ orj_img = results["image"]
84
+ enh_img = results["enhanced"]
85
+
86
+ image_comparison(
87
+ img1=orj_img,
88
+ img2=enh_img,
89
+ label1="Dark Side",
90
+ label2="Light Side",
91
+ )
92
+ else:
93
+
94
+ st.write(
95
+ "If video is not playing, please refresh the page. Depends on your browser and connection, it may take some time to load the video."
96
+ )
97
+
98
+ class VideoProcessor(VideoProcessorBase):
99
+ def recv(self, frame):
100
+
101
+ img = frame.to_ndarray(format="bgr24")
102
+ results = model.predict(img)[0]
103
+ orj_img = results["image"]
104
+ enh_img = results["enhanced"]
105
+
106
+ return av.VideoFrame.from_ndarray(
107
+ np.concatenate((orj_img, enh_img), axis=1), format="bgr24"
108
+ )
109
+
110
+ ctx = webrtc_streamer(
111
+ key="example",
112
+ video_processor_factory=VideoProcessor,
113
+ rtc_configuration={
114
+ "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
115
+ },
116
+ media_stream_constraints={
117
+ "video": True,
118
+ "audio": False,
119
+ },
120
+ )
121
+
122
+
123
+ if __name__ == "__main__":
124
+
125
+ samples = [
126
+ "0_orj.png",
127
+ "1_orj.png",
128
+ "2_orj.png",
129
+ "3_orj.png",
130
+ "4_orj.png",
131
+ "5_orj.png",
132
+ ]
133
+
134
+ random.seed(datetime.now())
135
+ random_sample = samples[random.randint(0, len(samples) - 1)]
136
+
137
+ main()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ av~=9.2.0
2
+ light_side
3
+ streamlit-image-comparison~=0.0.2
4
+ streamlit-webrtc~=0.42.0
5
+ streamlit~=1.8.1