FraudDetector / app.py
carlvang's picture
Update app.py
6503db3 verified
# Importing data
import pandas as pd
from sklearn.linear_model import LogisticRegression
import numpy as np
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import VotingClassifier
import joblib,os
import gradio as gr
script_dir=os.path.dirname(os.path.abspath(__file__))
model_path=os.path.join(script_dir,'model','EnsembleModel.joblib')
Ensemble_Model=joblib.load(model_path)
# Function
def Fraud(payments, min_pay, oneoff_p, purch, balance):
df=pd.DataFrame({'payments':[payments],'minimum_payments':[min_pay],
'oneoff_purchases':[oneoff_p],'purchases':[purch],
'balance':[balance]})
# prob={"Probability of Fraud": round(float(Ensemble_Model.predict_proba(df)[0][1]),4)}
prob= "The probability of fraud is: "+str(round(float(Ensemble_Model.predict_proba(df)[0][1]),4))
return prob
with gr.Blocks() as demo:
with gr.Row():
gr.Label('Fraud Detector 💰🏧💳', label='Alpha Bank™')
with gr.Row():
# gr.Image("model/alpha.jpg", scale=2)
gr.Markdown('Share the following monthly information for detecting fraud activity')
with gr.Row():
interface=[
gr.Slider(0,60000,label='Payments per month'),
gr.Slider(0,80000,label='Minimum payments per month'),
gr.Slider(0,50000, label='One-time purchases average amount'),
gr.Slider(0,50000, label='Subscription services regular payments '),
gr.Slider(0,25000, label='Balance amount')
]
with gr.Row():
predict_but=gr.Button('Analyse activity')
output= gr.Textbox(label='Result')
predict_but.click(fn=Fraud, inputs=interface, outputs=output)
if __name__ == "__main__":
# print("here")
# block1.launch()
demo.launch()