import streamlit as st import joblib import numpy as np import pandas as pd from sklearn.preprocessing import StandardScaler from huggingface_hub import hf_hub_download # Download the model from Hugging Face Hub model_path = hf_hub_download(repo_id="tajuarAkash/Health_Insurance_Fraud_detection_using_Random_forest", filename="random_forest_model.joblib") # Load the model from the downloaded path model = joblib.load(model_path) # Title and description for the app st.title("Insurance Claim Fraud Detection") st.write(""" This app predicts whether an insurance claim is fraudulent or legitimate based on user input. Please enter the information below. """) # Input fields for users to provide claim details claim_amount = st.number_input("Enter the claim amount", min_value=0) patient_age = st.number_input("Enter the patient's age", min_value=0) patient_income = st.number_input("Enter the patient's income", min_value=0) patient_gender = st.selectbox("Select patient's gender", ["Male", "Female"]) claim_status = st.selectbox("Claim status", ["Denied", "Pending", "Approved"]) # Create a button to trigger prediction if st.button('Predict Fraud'): # Preprocess the input data (this may need adjustments based on how you preprocessed during training) input_data = { "ClaimAmount": [claim_amount], "PatientAge": [patient_age], "PatientIncome": [patient_income], "PatientGender": [patient_gender], "ClaimStatus": [claim_status], } # Convert the input data to a pandas DataFrame input_df = pd.DataFrame(input_data) # Encode the gender (if needed) input_df['PatientGender'] = input_df['PatientGender'].apply(lambda x: 1 if x == 'Male' else 0) # Encode the ClaimStatus (example ordinal encoding, adjust based on training) claim_status_mapping = {"Denied": 0, "Pending": 1, "Approved": 2} input_df['ClaimStatus'] = input_df['ClaimStatus'].map(claim_status_mapping) # Assuming the model expects the data to be scaled (adjust as per your preprocessing) scaler = StandardScaler() input_scaled = scaler.fit_transform(input_df) # Get the prediction from the model prediction = model.predict(input_scaled) # Display the result if prediction == 1: st.write("This claim is predicted to be **fraudulent**.") else: st.write("This claim is predicted to be **legitimate**.")