import streamlit as st from streamlit_option_menu import option_menu import tensorflow as tf #importation des librairies #from tensorflow import keras import base64 #import torch from keras.models import load_model from PIL import ImageOps, Image import numpy as np import pandas as pd import matplotlib.pyplot as plt #from util import classify def classify(image, model, class_names): """ This function takes an image, a model, and a list of class names and returns the predicted class and confidence score of the image. Parameters: image (PIL.Image.Image): An image to be classified. model (tensorflow.keras.Model): A trained machine learning model for image classification. class_names (list): A list of class names corresponding to the classes that the model can predict. Returns: A tuple of the predicted class name and the confidence score for that prediction. """ # convert image to (224, 224) image = ImageOps.fit(image, (224, 224), Image.Resampling.LANCZOS) # convert image to numpy array image_array = np.asarray(image) # normalize image normalized_image_array = (image_array.astype(np.float32) / 127.5) - 1 # set model input data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32) data[0] = normalized_image_array # make prediction prediction = model.predict(data) # index = np.argmax(prediction) index = 0 if prediction[0][0] > 0.95 else 1 class_name = class_names[index] confidence_score = prediction[0][index] return class_name, confidence_score,index model=load_model('./models/model.h5') with open('./models/names.txt', 'r') as f: class_names = [a[:-1].split(' ')[1] for a in f.readlines()] f.close() st.set_page_config(layout='wide') st.markdown(""" """, unsafe_allow_html=True) header , menu = st.columns(2) with header: st.image('static/image/cif2.PNG') with menu: # option_menu(menu_title=None, # options=['Visualisation','Prédiction'], # icons=["house","book",'envelope'], # default_index=0, # orientation="horizontal" # ) selecte=option_menu(None, ["Home", "About"], icons=['house', 'cloud-upload'], menu_icon="cast", default_index=0, orientation="horizontal", styles={ "container": {"padding": "0!important", "background-color": "#ffffff","font-family": "Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif"}, "icon": {"color": "red", "font-size": "25px" }, "nav-link": {"font-size": "20px", "text-align": "left", "margin":"0px", "--hover-color": "#eee"}, "nav-link-selected": {"background-color": "#F9C949","color":"white"}, "menu-title":{"color":"#424143"} } ) if selecte == "Home": st.title(f"A propos de la Fraude à l'Assurance Automobile") sect1_col1,sect1_col2, sect1_col3 = st.columns(3) for col in (sect1_col1,sect1_col2, sect1_col3): col.container() with open('./static/css/style.css') as f: st.markdown(f'', unsafe_allow_html=True) with sect1_col2.container(height=360): # st.markdown( # """ # # """, # unsafe_allow_html=True, # ) st.markdown(""" """ , unsafe_allow_html=True) st.write("Le secteur de l'assurance est confronté à un dilème:") #st.write(" au KENYA par an ") st.caption("Distinguer les demandes d'indmnisations authentiques des des demandes trompeuses") with sect1_col1.container(height=360): st.write("L'émergence de l'IA générative a contribué à: ",) st.caption("l'augmentation des demandes d'indemnisations frauduleuses") with sect1_col3.container(height=360): script = """
""" st.subheader("Cout de la fraude à l'assurance ") st.write("Le cout de la Fraud à l'assurance automobile est estimé à") st.metric("", "Plus de 10% ") st.write("de la somme totale des sinistres") st.title(f"Vérifiez l'Authenticité des images de vos Clients") st.markdown("Distinguez les images frauduleus des images non frauduleuses") with st.container(height=400): st.markdown( """ """, unsafe_allow_html=True ) file = st.file_uploader("Choisissez une image",type=["png","jpg"]) if file is not None: image = Image.open(file).convert('RGB') st.image(image, use_column_width=True) class_name, conf_score ,index = classify(image, model, class_names) if index == 0: st.image('static/image/not_fraud.jpg') else: st.image('static/image/alert.PNG') st.write("### score: {}%".format(int(conf_score * 1000) / 10)) footer = st.container() with footer: st.markdown("---") st.markdown( """

© Designed by ONDOA Michelle & NGNINTEDEM Marlyne.

""", unsafe_allow_html=True ) if selecte == "About": st.title("A propos du modèle") st.markdown( """ """, unsafe_allow_html=True ) with st.container(height=1500): st.title('Définition du problème') st.write('Prédire si une image de voiture donnée est une demande d\'indemnisation frauduleuse ?') st.title('Type de problème') st.write('Problème de Classification ') st.title('Problème Domaine') st.write('Vision par ordinateur') st.title('Analyse des données') st.write('L\'examination des données a montré que les données d\'entraînement sont déséquilibrées. La différence entre la distribution des classes positives et négatives est TRÈS ÉNORME !' ) c1 , c2 = st.columns(2) with c1: st.metric("Classe Négative", "94%") with c2: st.metric("Classe Positive", "6%") st.title("Modélisation") st.caption('ResNet 18 (Pré-entraîné)') st.write('Comme il s\'agit d\'un problème de vision par ordinateur, il était très clair et logique d\'essayer un réseau neuronal convolutif. Nous avons utilisé ResNet 18 avec les poids pré-entraînés sur l\'ensemble de données ImageNet .Nous avons remplacé la couche de sortie et la couche d\'entrée.Le model a donné un résultat suivants:') col1, col2 =st.columns(2) with col1: st.image('static/image/loss.png') with col2: st.image('static/image/acc.png') footer = st.container() with footer: st.markdown("---") st.markdown( """

© Designed by ONDOA Michelle & NGNINTEDEM Marlyne .

""", unsafe_allow_html=True )