Spaces:
Build error
Build error
Download app.py from FuurythumbsCPT/Fraud_detection_system: direct link, hf CLI and curl.
- Browser
- Download file 1.31 kB
-
https://huggingface.co/spaces/FuurythumbsCPT/Fraud_detection_system/resolve/main/app.py
- Command line
-
hf download hf://spaces/FuurythumbsCPT/Fraud_detection_system/app.py
-
curl -L -o app.py https://huggingface.co/spaces/FuurythumbsCPT/Fraud_detection_system/resolve/main/app.py
1.31 kB
| import gradio as gr | |
| import pandas as pd | |
| from sklearn.linear_model import LogisticRegression | |
| def create_dummy_data(): | |
| import numpy as np | |
| np.random.seed(42) | |
| n = 1000 | |
| data = pd.DataFrame({ | |
| 'V1': np.random.randn(n), | |
| 'V2': np.random.randn(n), | |
| 'V3': np.random.randn(n), | |
| 'V4': np.random.randn(n), | |
| 'V5': np.random.randn(n), | |
| 'Amount': np.random.rand(n) * 100, | |
| 'Class': [0]*950 + [1]*50 | |
| }) | |
| return data | |
| def train_model(): | |
| df = create_dummy_data() | |
| X = df.drop('Class', axis=1) | |
| y = df['Class'] | |
| model = LogisticRegression(max_iter=1000) | |
| model.fit(X, y) | |
| return model | |
| model = train_model() | |
| def predict_fraud(file): | |
| df = pd.read_csv(file.name) | |
| X = df.drop(columns=['Class'], errors='ignore') | |
| preds = model.predict(X) | |
| df['Prediction'] = preds | |
| df['Prediction'] = df['Prediction'].map({0: "Legitimate", 1: "Fraudulent"}) | |
| return df | |
| iface = gr.Interface( | |
| fn=predict_fraud, | |
| inputs=gr.File(label="Upload CSV file (with columns: V1, V2, V3, V4, V5, Amount)"), | |
| outputs=gr.Dataframe(label="Predictions"), | |
| title="Credit Card Fraud Detection Demo", | |
| description="Upload a CSV file with features V1-V5 and Amount to see if transactions are fraudulent or legitimate." | |
| ) | |
| iface.launch() |