FuurythumbsCPT commited on
Commit
d5b74cd
·
verified ·
1 Parent(s): 81625cd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -12
app.py CHANGED
@@ -1,19 +1,21 @@
1
- import gradio as gr
2
  import pandas as pd
3
  import joblib
4
 
5
- # Load your trained model
6
- model = joblib.load("model.pkl")
7
 
8
- def detect_fraud(file):
9
  df = pd.read_csv(file.name)
10
- # Drop 'Class' if it exists
11
- if 'Class' in df.columns:
12
- df = df.drop(columns=['Class'])
13
 
14
- prediction = model.predict(df)
15
- df['Prediction'] = prediction
16
- return df
17
 
18
- iface = gr.Interface(fn=detect_fraud, inputs=gr.File(label="Upload CSV"), outputs="dataframe")
19
- iface.launch()
 
 
 
 
 
 
 
 
1
  import pandas as pd
2
  import joblib
3
 
4
+ # Load trained model
5
+ model = joblib.load("fraud_model.pkl")
6
 
7
+ def predict_fraud(file):
8
  df = pd.read_csv(file.name)
9
+ predictions = model.predict(df.drop("Class", axis=1)) # Drop target column
10
+ df["Prediction"] = predictions
11
+ return df[df["Prediction"] == 1] # Return only fraudulent predictions
12
 
 
 
 
13
 
14
+ interface = gr.Interface(
15
+
16
+ fn=predict_fraud,
17
+ inputs=gr.File(label="Upload CSV File"),
18
+ outputs=gr.Dataframe(label="Fraudulent Transactions"),
19
+ title="Fraud Detection System",
20
+ description="Upload a bank transaction CSV file to detect fraud. Ensure the format matches the training dataset (columns V1-V28, Time, Amount, Class)."
21
+ )