File size: 4,683 Bytes
d0bcbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ee54f1
3f3b3ed
d0bcbb0
0eaef7f
166c761
d0bcbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2f3182
d0bcbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2f3182
d0bcbb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2f3182
d0bcbb0
 
 
c2f3182
 
d0bcbb0
 
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import streamlit as st
from transformers import pipeline
from PIL import Image

sample_img = {
    "<None>": None,
    "Right_Normal_1": "img/[0] Normal/Normal_R_1.png",
    "Left_Normal_1": "img/[0] Normal/Normal_L_1.png",
    "Right_Normal_2": "img/[0] Normal/Normal_R_2.png",
    "Left_Normal_2": "img/[0] Normal/Normal_L_2.png",

    "Right_DFU_1": "img/[1] DFU/DFU_R_1.png",
    "Left_DFU_1": "img/[1] DFU/DFU_L_1.png",
    "Right_DFU_2": "img/[1] DFU/DFU_R_2.png",
    "Left_DFU_2": "img/[1] DFU/DFU_L_2.png"
}

def app():
    with st.sidebar:
        st.image("resources/AIB_logo.png")
        st.markdown("<h1 style='text-align: center; color: purple ;'>AI-Builders 3: Arcane Whales</h1>", unsafe_allow_html=True)
        st.write("This project was created by Picha Jetsadapattarakul under AI Builders program.")

    st.title("An Early Detection of Diabetic Foot Ulcers by using Planter Foot Thermogram with Vision Transformer Model ")
    st.info("This is an image classification project that classify thermogram image of Diabetic Foot Ulcers by using Vision Transformer(ViT) model.",icon="ℹ️")
    st.write("Choose sample image for classification.")
    with st.expander("Choose sample image here"):
        sample = st.selectbox(label = "Select image for classification here", options = list(sample_img.keys()), label_visibility="hidden")   
        st.write("Normal Group")
        c1, c2, c3, c4 = st.columns(4)
        st.write("Diabetic Foot Ulcers Group")
        with c1:
            st.image(sample_img["Right_Normal_1"], caption="Right_Normal_1", use_column_width=True)
        with c2:
            st.image(sample_img["Left_Normal_1"], caption="Left_Normal_1", use_column_width=True)
        with c3:
            st.image(sample_img["Right_Normal_2"], caption="Right_Normal_2", use_column_width=True)
        with c4:
            st.image(sample_img["Left_Normal_2"], caption="Left_Normal_2", use_column_width=True)   

        c1, c2, c3, c4 = st.columns(4)
        with c1:
            st.image(sample_img["Right_DFU_1"], caption="Right_DFU_1", use_column_width=True)
        with c2:
            st.image(sample_img["Left_DFU_1"], caption="Left_DFU_1", use_column_width=True)
        with c3:
            st.image(sample_img["Right_DFU_2"], caption="Right_DFU_2", use_column_width=True)
        with c4:
            st.image(sample_img["Left_DFU_2"], caption="Left_DFU_2", use_column_width=True)

    upload_img = st.file_uploader("Or you can upload your image here", type=["png"])

    col1, col2= st.columns(2)
    col1.header('Input Image')
    col2.header("Output")
    
    if upload_img is not None:
        # try the model
        image = Image.open(upload_img)
        col1.image(image)

        classifier = pipeline("image-classification", model="model")
        col2.success('succeed!', icon="✅")
        col2.balloons()
        preds_result = classifier(image)
        # col2.write(preds_result)

        # change label from 0 to Normal and 1 to Diabetic Foot Ulcers for visualization
        if preds_result[0]['label'] == 0:
            label_0 = "Normal"
        elif preds_result[0]['label'] == 1 :
            label_0 = "Diabetic foot Ulcers"

        if preds_result[1]['label'] == 1:
            label_1 = "Diabetic foot Ulcers"
        elif preds_result[1]['label'] == 0:
            label_1 = "Normal"
        
        col2.write("Prediction Result: ")
        col2.progress(preds_result[0]['score'], text = f"{label_0}: {round(preds_result[0]['score']*100,2)}%")
        col2.progress(preds_result[1]['score'], text = f"{label_1}: {round(preds_result[1]['score']*100,2)}%")
    
    elif sample_img[sample] is None:
        pass

    elif sample:
        # try the model
        image = Image.open(sample_img[sample])
        col1.image(image)

        classifier = pipeline("image-classification", model="model")
        col2.success('succeed!', icon="✅")
        col2.balloons()
        preds_result = classifier(image)

        # change label from 0 to Normal and 1 to Diabetic Foot Ulcers for visualization
        if preds_result[0]['label'] == 0:
            label_0 = "Normal"
        elif preds_result[0]['label'] == 1 :
            label_0 = "Diabetic foot Ulcers"

        if preds_result[1]['label'] == 1:
            label_1 = "Diabetic foot Ulcers"
        elif preds_result[1]['label'] == 0:
            label_1 = "Normal"
        
        
        col2.progress(preds_result[0]['score'], text = f"{label_0}: {round(preds_result[0]['score']*100,2)}%")
        col2.progress(preds_result[1]['score'], text = f"{label_1}: {round(preds_result[1]['score']*100,2)}%")

         
    
if __name__ == "__main__":
    app()