FuurythumbsCPT commited on
Commit
5abb857
·
verified ·
1 Parent(s): 51a15ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -18
app.py CHANGED
@@ -2,31 +2,22 @@ import gradio as gr
2
  import pandas as pd
3
  import joblib
4
 
5
- # Load your trained model (make sure you have this in your repo)
6
  model = joblib.load("fraud_model.pkl")
7
 
8
  def predict_fraud(file):
9
  df = pd.read_csv(file.name)
10
- # Drop columns not used by the model (if any)
11
- features = df.drop(columns=["Time", "Class"], errors="ignore")
12
- predictions = model.predict(features)
13
-
14
- # Map predictions 0/1 to labels
15
- label_map = {0: "Legitimate", 1: "Fraudulent"}
16
- labeled_predictions = [label_map[p] for p in predictions]
17
-
18
- df["Prediction"] = labeled_predictions
19
  return df
20
 
21
- # Create Gradio interface
22
  ui = gr.Interface(
23
  fn=predict_fraud,
24
- inputs=gr.File(label="Upload Transaction CSV"),
25
- outputs=gr.Dataframe(label="Fraud Detection Results"),
26
- title="Credit Card Fraud Detection",
27
- description="Upload your transaction CSV file to detect fraudulent activity."
28
  )
29
 
30
- if __name__ == "__main__":
31
- ui.launch()
32
- interface.launch()
 
2
  import pandas as pd
3
  import joblib
4
 
5
+ # Load your trained model
6
  model = joblib.load("fraud_model.pkl")
7
 
8
  def predict_fraud(file):
9
  df = pd.read_csv(file.name)
10
+ predictions = model.predict(df.drop(columns=["Time", "Class"], errors="ignore"))
11
+ df["Prediction"] = predictions
 
 
 
 
 
 
 
12
  return df
13
 
14
+ # Create a simple UI with file upload
15
  ui = gr.Interface(
16
  fn=predict_fraud,
17
+ inputs=gr.File(label="Upload Bank Transaction CSV"),
18
+ outputs=gr.Dataframe(label="Predictions"),
19
+ title="Fraud Detection System",
20
+ description="Upload a transaction CSV file and detect fraudulent entries.",
21
  )
22
 
23
+ ui.launch()