|
|
|
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 |
|
|
|
|
|
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("medias/keyce.jpg", width=80) |
|
yy = col3 |
|
|
|
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(" ") |
|
|
|
st.image("medias/fondacc.png", width=None) |
|
|
|
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") |
|
|
|
st.image("medias/tvl.PNG", width=700) |
|
|
|
with menu2: |
|
|
|
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")) |
|
|
|
upload_file = st.file_uploader("Charger le fichier image:", type=['JPG', 'JPEG', 'PNG']) |
|
|
|
if f_name and l_name and datnaiss and upload_file: |
|
|
|
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) |
|
|
|
|
|
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: |
|
|
|
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 |
|
|
|
|
|
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]") |
|
|
|
|
|
|
|
donnee_sortie = pd.DataFrame({ |
|
'Nom':str(f_name), |
|
'Prenom':str(l_name), |
|
'Date de naissance':str(datnaiss), |
|
'Sexe':str(sexe), |
|
|
|
'Resultat du diqgnostic':str(cle), |
|
}, index=[0]) |
|
|
|
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() |