Spaces:
Sleeping
Sleeping
| # Import librairies | |
| import streamlit as st | |
| import tensorflow as tf | |
| import numpy as np | |
| import requests | |
| import json | |
| import base64 | |
| import streamlit_elements as elements | |
| import streamlit.components.v1 as components | |
| from streamlit_elements import elements, mui, html | |
| from tensorflow.keras.utils import load_img, img_to_array | |
| from tensorflow.keras.preprocessing import image | |
| from PIL import Image, ImageOps | |
| from pathlib import Path | |
| # Title | |
| st.sidebar.image("images/logo.png", use_column_width=None) | |
| # Load model | |
| model = tf.keras.models.load_model("model/model.h5") | |
| covid_classes = {'COVID19': 0, 'NORMAL': 1, 'PNEUMONIA': 2, 'TUBERCULOSIS': 3} | |
| # Define sidebar options | |
| tab1, tab2, tab3 = st.tabs(["Accueil","Prédiction","Contact"]) | |
| # Display content according to selected option | |
| with tab1: | |
| # Display home page with app description and logo | |
| st.header('Bienvenue sur l\'application de classification d\'images de radiographies pulmonaires') | |
| st.image('images/image3.png', caption='Convolutional Neural Networks') | |
| #st.title('Bienvenue sur l\'application de classification d\'images de radiographies pulmonaires') | |
| #st.markdown("<h1 style='text-align: center;'>Bienvenue sur l'application de classification d'images de radiographies pulmonaires</h1>", unsafe_allow_html=True) | |
| st.markdown("<h5 style='text-align: justify;'>Cette application utilise un modèle de machine learning pour prédire la classe d'une image parmi quatre catégories : COVID19, NORMAL, PNEUMONIA ou TUBERCULOSIS. Vous pouvez télécharger une ou plusieurs images de radiographies pulmonaires et obtenir les résultats de la prédiction en quelques secondes.</h5>", unsafe_allow_html=True) | |
| components.html( | |
| """ | |
| <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed | |
| </div> | |
| """, | |
| height=50 | |
| ) | |
| with tab2: | |
| # Display prediction page with sidebar and main | |
| # Sidebar | |
| st.header("Prédiction") | |
| #st.markdown("<h1 style='text-align: center;'>Prédiction</h1>", unsafe_allow_html=True) | |
| st.sidebar.header("Paramètre pour la prédiction") | |
| upload_file = st.sidebar.file_uploader("Télécharger le fichier", type=['jpg', 'jpeg', 'png'], key="upload") | |
| generate_pred = st.sidebar.button("Predict") | |
| # Main | |
| if upload_file: | |
| # Display uploaded image | |
| st.header("Image téléchargée") | |
| st.image(upload_file, caption="Image", use_column_width=True) | |
| # Predict label | |
| if generate_pred: | |
| # Preprocess image | |
| test_image = image.load_img(upload_file, target_size=(64, 64)) | |
| image_array = img_to_array(test_image) | |
| image_array = np.expand_dims(image_array, axis=0) | |
| # Make prediction | |
| prediction = model.predict(image_array) | |
| classe = np.argmax(prediction, axis=1) | |
| label = [key for key, value in covid_classes.items() if value == classe][0] | |
| # Display result | |
| st.header("Résultat de la prédiction") | |
| st.write(f"L'image est classée comme {label}.") | |
| components.html( | |
| """ | |
| <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed | |
| </div> | |
| """, | |
| height=70 | |
| ) | |
| with tab3: | |
| # Définir les informations de contact | |
| name = "TAYAWELBA DAWAI Hesed" | |
| email = "hesedtayawelba@gmail.com" | |
| phone = "+237 6 9340 1580" | |
| address = "Yaoundé, Cameroun" | |
| github = "https://github.com/Tayawelba" | |
| huggingface = "https://huggingface.co/tayawelba" | |
| linkedin = "https://www.linkedin.com/in/tayawelba-dawaï-hesed/" | |
| # Créer la page "Contact" | |
| st.header("Contact") | |
| st.write(f"Bonjour, je m'appelle {name} et je suis un développeur web et un expert en machine learning. Si vous souhaitez me contacter, vous pouvez utiliser les moyens suivants :") | |
| st.write(f"- Email : {email}") | |
| st.write(f"- Téléphone : {phone}") | |
| st.write(f"- Adresse : {address}") | |
| st.write("Vous pouvez également me suivre sur les réseaux sociaux suivants :") | |
| st.markdown(f'- <a href="{github}"><h5 style="text-align: justify;">GitHub : @Tayawelba</h5></a>', unsafe_allow_html=True) | |
| st.markdown(f'- <a href="{huggingface}"><h5 style="text-align: justify"> Hugging Face : @tayawelba</h5></a>', unsafe_allow_html=True) | |
| st.markdown(f'- <a href="{linkedin}"><h5 style="text-align: justify;">LinkedIn : Tayawelba Dawaï Hesed</h5></a>', unsafe_allow_html=True) | |
| st.write("Je serai ravi de discuter avec vous de vos projets, de vos idées ou de vos questions. N'hésitez pas à me contacter !") | |
| components.html( | |
| """ | |
| <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| Tous droits réservés © Février 2024 Tayawelba Dawaï Hesed | |
| </div> | |
| """, | |
| height=20 | |
| ) | |
| # # Import librairies | |
| # import streamlit as st | |
| # import tensorflow as tf | |
| # import numpy as np | |
| # import requests | |
| # import json | |
| # import base64 | |
| # import streamlit_elements as elements | |
| # import streamlit.components.v1 as components | |
| # from streamlit_elements import elements, mui, html | |
| # from tensorflow.keras.utils import load_img, img_to_array | |
| # from tensorflow.keras.preprocessing import image | |
| # from PIL import Image, ImageOps | |
| # from pathlib import Path | |
| # # Title | |
| # st.sidebar.image("logo.png", use_column_width=None) | |
| # # Load model | |
| # model = tf.keras.models.load_model("model.h5") | |
| # covid_classes = {'COVID19': 0, 'NORMAL': 1, 'PNEUMONIA': 2, 'TUBERCULOSIS': 3} | |
| # # Define sidebar options | |
| # sidebar_options = ["Accueil", "Prédiction", "Contact"] | |
| # # Display sidebar and get selected option | |
| # selected_option = st.sidebar.selectbox("MENU", sidebar_options) | |
| # # Display content according to selected option | |
| # if selected_option == "Accueil": | |
| # # Display home page with app description and logo | |
| # st.markdown("<h1 style='text-align: center;'>Bienvenue sur l'application de classification d'images</h1>", unsafe_allow_html=True) | |
| # st.markdown("<h3 style='text-align: justify;'>Cette application utilise un modèle de machine learning pour prédire la classe d'une image parmi quatre catégories : COVID19, NORMAL, PNEUMONIA ou TUBERCULOSIS. Vous pouvez télécharger une ou plusieurs images de radiographies pulmonaires et obtenir les résultats de la prédiction en quelques secondes.</h3>", unsafe_allow_html=True) | |
| # components.html( | |
| # """ | |
| # <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| # Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed | |
| # </div> | |
| # """, | |
| # height=50 | |
| # ) | |
| # elif selected_option == "Prédiction": | |
| # # Display prediction page with sidebar and main | |
| # # Sidebar | |
| # st.markdown("<h1 style='text-align: center;'>Prédiction</h1>", unsafe_allow_html=True) | |
| # st.sidebar.header("Options") | |
| # num_images = st.sidebar.number_input("Nombre d'images à prédire", min_value=1, max_value=10, value=1) | |
| # upload_files = st.sidebar.file_uploader("Télécharger des fichiers", type=['jpg', 'jpeg', 'png'], accept_multiple_files=True, key="upload") | |
| # generate_pred = st.sidebar.button("Predict") | |
| # # Main | |
| # if upload_files: | |
| # # Check if the number of uploaded files matches the number input | |
| # if len(upload_files) != num_images: | |
| # st.error(f"Veuillez télécharger exactement {num_images} image(s).") | |
| # else: | |
| # # Display uploaded images | |
| # st.header("Images téléchargées") | |
| # cols = st.columns(num_images) | |
| # for i, file in enumerate(upload_files): | |
| # cols[i].image(file, caption=f"Image {i+1}", use_column_width=True) | |
| # # Predict labels | |
| # if generate_pred: | |
| # # Preprocess images | |
| # test_images = [image.load_img(file, target_size=(64, 64)) for file in upload_files] | |
| # image_arrays = [img_to_array(img) for img in test_images] | |
| # image_arrays = np.array(image_arrays) | |
| # # Make predictions | |
| # predictions = model.predict(image_arrays) | |
| # classes = np.argmax(predictions, axis=1) | |
| # labels = [key for key, value in covid_classes.items() if value in classes] | |
| # # Display results in a table | |
| # st.header("Résultats de la prédiction") | |
| # table_data = [] | |
| # for i, (file, label) in enumerate(zip(upload_files, labels)): | |
| # # Resize image for table display | |
| # img = Image.open(file) | |
| # img = img.resize((64, 64)) | |
| # table_data.append([f"Image {i+1}", img, label]) | |
| # st.table(table_data) | |
| # components.html( | |
| # """ | |
| # <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| # Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed | |
| # </div> | |
| # """, | |
| # height=70 | |
| # ) | |
| # elif selected_option == "Contact": | |
| # # Définir une fonction pour encoder une image en base64 | |
| # def get_image_base64(image_path): | |
| # with open(image_path, "rb") as image_file: | |
| # return base64.b64encode(image_file.read()).decode() | |
| # # Définir les informations de contact | |
| # name = "TAYAWELBA DAWAI Hesed" | |
| # email = "hesedtayawelba@gmail.com" | |
| # phone = "+237 6 9340 1580" | |
| # address = "Yaoundé, Cameroun" | |
| # github = "https://github.com/Tayawelba" | |
| # huggingface = "https://huggingface.co/tayawelba" | |
| # linkedin = "https://www.linkedin.com/in/tayawelba-dawaï-hesed/" | |
| # # Définir les logos des réseaux sociaux | |
| # github_logo = get_image_base64("github.png") | |
| # huggingface_logo = get_image_base64("huggingface.png") | |
| # linkedin_logo = get_image_base64("linkedin.png") | |
| # # Créer la page "Contact" | |
| # st.title("Contact") | |
| # st.write(f"Bonjour, je m'appelle {name} et je suis un développeur web et un expert en machine learning. Si vous souhaitez me contacter, vous pouvez utiliser les moyens suivants :") | |
| # st.write(f"- Email : {email}") | |
| # st.write(f"- Téléphone : {phone}") | |
| # st.write(f"- Adresse : {address}") | |
| # st.write("Vous pouvez également me suivre sur les réseaux sociaux suivants :") | |
| # st.markdown(f'- <a href="{github}"><h5 style="text-align: justify;">GitHub : @Tayawelba</h5></a>', unsafe_allow_html=True) | |
| # st.markdown(f'- <a href="{huggingface}"><h5 style="text-align: justify"> Hugging Face : @tayawelba</h5></a>', unsafe_allow_html=True) | |
| # st.markdown(f'- <a href="{linkedin}"><h5 style="text-align: justify;">LinkedIn : Tayawelba Dawaï Hesed</h5></a>', unsafe_allow_html=True) | |
| # st.write("Je serai ravi de discuter avec vous de vos projets, de vos idées ou de vos questions. N'hésitez pas à me contacter !") | |
| # components.html( | |
| # """ | |
| # <div style="position: fixed; bottom: 0; left: 0; right: 0; text-align: center; font-size: 15px; color: gray;"> | |
| # Tous droits réservés © Décembre 2023 Tayawelba Dawaï Hesed | |
| # </div> | |
| # """, | |
| # height=20 | |
| # ) | |