File size: 1,378 Bytes
ffe582f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105b241
f023709
105b241
 
 
ffe582f
f023709
ffe582f
 
 
 
f023709
ea7c504
f023709
ffe582f
 
36a8e57
 
 
 
 
ffe582f
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from tensorflow import keras
from PIL import Image
import io

import model


def configure():
    st.set_page_config(page_title="Low-light image enhancement")
    if "model" not in st.session_state:
        st.session_state["model"]: keras.Model = model.create_model()


def describe_service():
    st.title("Low-light image enhancement")
    st.subheader("Just upload your low-light image and get the processed one!")


@st.experimental_memo
def call_model(uploaded_file: io.BytesIO) -> Image.Image:
    return model.run_model(uploaded_file, st.session_state["model"])


def process_image():
    uploaded_file = st.file_uploader(
        label="Choose a file (you can upload new files without refreshing the page)",
        type=["png", "jpg", "jpeg"],
    )
    if uploaded_file:
        placeholder = st.empty()
        placeholder.info("The image is being processed. It may take some time. Wait, please...")
        image = call_model(uploaded_file)
        placeholder.empty()
        placeholder.image(image)
        image_bytes = io.BytesIO()
        image.save(image_bytes, format="png")
        st.download_button(
            label="Download lightened image", data=image_bytes, file_name="lightened.png", mime="image/png"
        )


def main():
    describe_service()
    process_image()


if __name__ == "__main__":
    configure()
    main()