Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
|
| 5 |
-
# Load
|
| 6 |
-
model = joblib.load("
|
| 7 |
|
| 8 |
-
def
|
| 9 |
df = pd.read_csv(file.name)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
prediction = model.predict(df)
|
| 15 |
-
df['Prediction'] = prediction
|
| 16 |
-
return df
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
)
|