File size: 6,791 Bytes
ac5172f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5e595c
ac5172f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5e595c
ac5172f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b75faa9
ac5172f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
#Importation des librairies pour notre application:
import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
import streamlit as st
from streamlit_option_menu import option_menu
import streamlit.components.v1 as html 
import tensorflow as tf 
from tensorflow.keras.utils import load_img, img_to_array
from tensorflow.keras.preprocessing import image
from PIL import Image, ImageOps 

#changement du logo et du titre de mon application en anglais
st.set_page_config(page_title="PMP", page_icon="ocean", layout="centered", menu_items=None)

col1, col2, col3 = st.columns(3)
xx = col1
ar = col2.image("keyce.jpg", width=80)
yy = col3
#title
st.title("CLASSIFICATION DES MALADIES PULMONAIRES")

def main():
    with st.sidebar:
        choose = option_menu("Menu", ["Acceuil", "Prédiction"], icons=['house', 'bar-chart'], menu_icon="list", default_index=0,
                                    styles={
                                    "container": {"padding": "5!important", "background-color": "#fff"},
                                    "icon": {"color": "#333", "font-size": "20px"}, 
                                    "nav-link": {"font-size": "16px", "text-align": "left", "margin":"0px", "--hover-color": "#f9d1ac"},
                                    "nav-link-selected": {"background-color": "#FF9633", "color": "#333"},
                                    }
                            )
        st.markdown('''<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <h6 style='text-align:center;color:grey;font-size:11px;'> © 2023 - KEYCE - Tout droits reservés </h6>''',  unsafe_allow_html=True)

    if choose == "Acceuil":
        st.markdown("<hr/>", unsafe_allow_html=True)
        st.subheader("Bienvenue")
        st.caption(" ")
        #Insertion d'une image 
        st.image("fondacc.png", width=None)  
        #inserer une case à cocher pour savoir ce que nous faisons
        state = st.checkbox("Que faisons-nous exactement dans cette application ?", value=False)
        if state:
            st.write("Bonjour à tout le monde! concernant notre application elle permet, à partir d'un model.h5 que nous avons généré, de prédire à partir des images radio que vous saisirez si un patient est affecté soit par le COVID19, NORMAL, PNEUMONIE, TURBERCULOSE. et cette application vous donne également la possibilité de télécharger la prédiction du patient dans un fichier Excel.")
        else:
            pass 


    elif choose=='Prédiction':
        st.markdown("<hr/>", unsafe_allow_html=True)
        menu1, menu2 = st.tabs(["📈 Évaluation du modèle", ":staff_of_aesculapius: Prédiction"])

        with menu1:
            st.subheader("Évaluer notre modèle")
            #Inserer des images
            st.image("tvl.png", width=700)

        with menu2:
            #Exemple de formulaire:
            st.subheader("Diagnostic et enregistrement du patient")
            f_name = st.text_input("Nom:", max_chars=50)
            l_name = st.text_input("Prénom:", max_chars=50)
            datnaiss = st.date_input("Date de naissance:")
            sexe = st.radio("Sexe:", options=("Masculin", "Féminin"))
            #Charger l'image pour la prédiction
            upload_file = st.file_uploader("Charger le fichier image:",  type=['JPG', 'JPEG', 'PNG'])

            if f_name and l_name and datnaiss and upload_file:
                #Chargons le model.h5
                model = tf.keras.models.load_model("model.h5")

                predict_classes = {'COVID19':0, 'NORMAL':1, 'PNEUMONIA':2, 'TUBERCULOSIS':3}

                if upload_file:
                    st.image(upload_file, use_column_width=True)
                    tets_image = image.load_img(upload_file, target_size=(64, 64))
                    image_array = img_to_array(tets_image)
                    image_array = np.expand_dims(image_array, axis=0)

                    #Boutton pour effectuer la prédiction
                    btn_prediction = st.button("faire le diagnostic")

                    if btn_prediction:
                        predictions = model.predict(image_array)
                        classes = np.argmax(predictions[0])

                        for cle, valeur in predict_classes.items():
                            if valeur == classes:
                                # Resultat de la prédiction
                                st.markdown("<hr/>", unsafe_allow_html=True)
                                col1, col2, col3 = st.columns(3)
                                aa = col1
                                ag = col2.markdown('''<h6 style='text-align:center;'> État diagnostique de M/Mme '''  f'{f_name}' '''</h6>''', unsafe_allow_html=True)
                                ss = col3

                                #Affichage de la prediction
                                col1, col2, col3 = st.columns(3)
                                xx = col1
                                ar = col2.markdown(''' <h2 style='text-align:center; color:#FF9633;'> ''' f'{cle}' ''' </h2> ''', unsafe_allow_html=True)
                                yy = col3

                                if cle == "NORMAL":
                                    st.info(":green[Bien, il est en bonne santé]")
                                else:
                                    st.info(":red[Désolé, il est malade]")

                                #Téléchargeons le diagnostic de la prédiction dans un fichier excel:
                                 # Créer un DataFrame avec les nouvelles données d'entrée
                                donnee_sortie = pd.DataFrame({
                                                'Nom':str(f_name),
                                                'Prenom':str(l_name),
                                                'Date de naissance':str(datnaiss),
                                                'Sexe':str(sexe),
                                                #'Image du scanner':image(upload_file),
                                                'Resultat du diqgnostic':str(cle),
                                }, index=[0])
                                #telechargement de la prediction:
                                col1, col2, col3 = st.columns(3)
                                xx = col1
                                ar = col2.download_button(label="Téléchargez le diagnostic sous forme de fichier .csv", data=donnee_sortie.to_csv(), file_name="Resultat_Diagnostic_"f'{f_name}'".csv", mime="text/csv")
                                yy = col3
            else:
                st.info("Merci de renseigner tous les champs avant de valider le diagnostic et son enregistrement")

if __name__=='__main__':
    main()