Diff of /1_🫁Segmentation.py [000000] .. [2a09d1]

Switch to unified view

a b/1_🫁Segmentation.py
1
import streamlit as st
2
import functions as f
3
import components.components as comp
4
5
# TITLE TAB
6
st.set_page_config(page_title="Segmentation 🫁")
7
8
# HEADER
9
def header_page():
10
    st.markdown("<h1 style='text-align: center;'>Modern Lung Segmentation <br> 🫁</h1>", unsafe_allow_html=True)
11
12
# FUNCTIONS
13
f.modelsCheck()
14
def inputFileUploaderSelected():
15
    st.session_state.input_selected = 'file_uploader'
16
17
def inputCameraSelected():
18
    st.session_state.input_selected = 'camera'
19
20
# BODY
21
def body_page():
22
    st.image('BG.png')
23
    # Select Model
24
    l_col_select_model, r_col_select_model = st.columns([2, 1])
25
    with l_col_select_model:
26
        st.markdown("<h4 style='text-align: center; margin:15px'>Select model to create lung segmentation:</h4>", unsafe_allow_html=True)
27
    with r_col_select_model:
28
        eval_df = f.getEvaluationDF()
29
        UNet_IoU = eval_df.loc[eval_df['Model'] == 'UNet', 'IoU'].values[0]
30
        UNetPP_IoU = eval_df.loc[eval_df['Model'] == 'UNet++', 'IoU'].values[0]
31
        AttUNet_IoU = eval_df.loc[eval_df['Model'] == 'AttUNet', 'IoU'].values[0]
32
        R2UNet_IoU = eval_df.loc[eval_df['Model'] == 'R2UNet', 'IoU'].values[0]
33
        options = [
34
            "UNet ~ IoU: {}%".format(int(UNet_IoU*100)),
35
            "UNet++ ~ IoU: {}%".format(int(UNetPP_IoU*100)),
36
            "AttUNet ~ IoU: {}%".format(int(AttUNet_IoU*100)),
37
            "R2UNet ~ IoU: {}%".format(int(R2UNet_IoU*100)),
38
            "All Models At Once"
39
        ]
40
        used_model = st.selectbox(label='',
41
                                    options=options)
42
        st.session_state.used_model = used_model
43
    # Select Input
44
    buff1, mid_col_input_1 , buff2, mid_col_input_2, buff3 = st.columns([2, 2, 1, 2, 2])
45
    btn_mid_col_input_1 = mid_col_input_1.button('Camera (Just 1 Image)', type='primary', on_click=inputCameraSelected)
46
    btn_mid_col_input_2 = mid_col_input_2.button('Upload File (More Images)', type='primary', on_click=inputFileUploaderSelected)
47
    if ('input_selected' in st.session_state):
48
        if ('camera' in st.session_state.input_selected):
49
            # Camera Input
50
            images = st.camera_input(label='Masukan Gambar', key='images', label_visibility='hidden')
51
            if images:
52
                f.saveSegmentation()
53
                f.showSegmentationFromCamera()
54
        
55
        elif ('file_uploader' in st.session_state.input_selected):
56
            # File Uploader Input
57
            images = st.file_uploader(label='Masukan Gambar', accept_multiple_files=True, key='images', type=['jpg', 'jpeg', 'png', 'bmp'], label_visibility='hidden')
58
            if images:
59
                f.saveSegmentation()
60
                f.showSegmentationFromFileUploader()
61
62
63
# SIDEBAR
64
with st.sidebar:
65
    description = "Modern lung segmentation applications aim to identify and separate the lungs from radiological images, such as Chest X-Rays (CXRs). Lung segmentation improves the accuracy of image classification model training and assists medical teams in their observations. The accuracy level is measured using the Intersection over Union (IoU) method in several models that utilize a dataset containing 3000 images and their corresponding masks."
66
67
    st.markdown(f'<p style="font-size:15px; text-align:justify">{description}', unsafe_allow_html=True)
68
    st.markdown("<span style='font-size:17px; text-align:justify font-weight:bold;'>Model Specification : </span>", unsafe_allow_html=True)
69
    st.write(f.getEvaluationDF())
70
71
72
# FOOTER
73
def footer_page():
74
    # st.markdown("<p><br></p>", unsafe_allow_html=True)
75
    # st.markdown("<div style='margin-top:200px;'></div>", unsafe_allow_html=True)
76
    comp.margin_top(200)
77
    st.markdown("<p style='text-align: center; font-style:italic;'>Copyright ⓒ 2023 - By Achmad Bauravindah</p>", unsafe_allow_html=True)
78
79
80
if __name__ == '__main__':
81
    header_page()
82
    body_page()
83
    footer_page()