Spaces:
Sleeping
Sleeping
Download app.py from DxKcm/fraud_detection: direct link, hf CLI and curl.
- Browser
- Download file 2.53 kB
-
https://huggingface.co/spaces/DxKcm/fraud_detection/resolve/main/app.py
- Command line
-
hf download hf://spaces/DxKcm/fraud_detection/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DxKcm/fraud_detection/resolve/main/app.py
2.53 kB
| import gradio as gr | |
| import joblib | |
| import numpy as np | |
| model = joblib.load("fraud_detection_model.pkl") | |
| info_text = """ | |
| ## 🔍 Comprendre les caractéristiques d'entrée | |
| L'ensemble de données utilisé pour la détection de fraude contient des **caractéristiques anonymisées transformées par ACP**. | |
| - **V1 à V28** → Il s'agit de caractéristiques issues d'une *analyse en composantes principales (ACP)*. | |
| Elles **ne représentent pas des valeurs réelles** (comme l'âge, le pays, le type de commerçant, etc.). | |
| Ce sont des transformations purement mathématiques utilisées pour préserver l'anonymat. | |
| - **Montant** → Montant de la transaction en euros. | |
| ### 🧠 Fonctionnement du modèle | |
| Le modèle utilise ces caractéristiques numériques transformées pour détecter les schémas inhabituels typiques des transactions frauduleuses. | |
| Il vous suffit de fournir des **valeurs numériques**, même si elles semblent abstraites ; le modèle les interprète automatiquement. | |
| """ | |
| def predict(amount, *values): | |
| features = np.array([amount] + list(values)).reshape(1, -1) | |
| prediction = model.predict(features)[0] | |
| return { | |
| "Prediction": "⚠️ Fraudulent Transaction" if prediction == 1 else "✔️ Clean Transaction", | |
| "Fraud_Flag": int(prediction) | |
| } | |
| with gr.Blocks(theme=gr.themes.Soft(), css=""" | |
| .gr-button {font-size: 18px !important; height: 60px;} | |
| .gr-markdown {font-size: 16px !important;} | |
| """) as demo: | |
| gr.Markdown("# 💳 Fraud Detection AI Model") | |
| gr.Markdown("Enter transaction data below to determine whether it is fraudulent.") | |
| gr.Markdown(info_text) | |
| with gr.Accordion("🧾 Enter Transaction Features", open=True): | |
| with gr.Row(): | |
| amount = gr.Number(label="💰 Amount", value=0.0) | |
| inputs = [amount] | |
| with gr.Row(): | |
| with gr.Column(): | |
| for i in range(1, 10): | |
| inputs.append(gr.Number(label=f"V{i}", value=0.0)) | |
| with gr.Column(): | |
| for i in range(10, 19): | |
| inputs.append(gr.Number(label=f"V{i}", value=0.0)) | |
| with gr.Column(): | |
| for i in range(19, 29): | |
| inputs.append(gr.Number(label=f"V{i}", value=0.0)) | |
| gr.Markdown("## 📊 Model Output") | |
| output = gr.JSON(label="Prediction Result") | |
| submit_btn = gr.Button("🚀 Run Fraud Detection", variant="primary") | |
| submit_btn.click(fn=predict, inputs=inputs, outputs=output) | |
| demo.launch() | |