Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 6 |
model = joblib.load("fraud_model.pkl")
|
| 7 |
|
| 8 |
def predict_fraud(file):
|
| 9 |
df = pd.read_csv(file.name)
|
| 10 |
-
|
| 11 |
-
|
| 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
|
| 22 |
ui = gr.Interface(
|
| 23 |
fn=predict_fraud,
|
| 24 |
-
inputs=gr.File(label="Upload Transaction CSV"),
|
| 25 |
-
outputs=gr.Dataframe(label="
|
| 26 |
-
title="
|
| 27 |
-
description="Upload
|
| 28 |
)
|
| 29 |
|
| 30 |
-
|
| 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()
|
|
|
|
|
|