Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +82 -0
- requirements.txt +8 -3
app.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import json, os
|
| 4 |
+
|
| 5 |
+
st.set_page_config(
|
| 6 |
+
page_title="Hybrid AI Fraud Detection",
|
| 7 |
+
page_icon="shield",
|
| 8 |
+
layout="wide",
|
| 9 |
+
initial_sidebar_state="expanded"
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
@st.cache_resource
|
| 13 |
+
def load_results():
|
| 14 |
+
results = {}
|
| 15 |
+
for name, path in [
|
| 16 |
+
("p1", "models/p1_lgbm_results.json"),
|
| 17 |
+
("p2", "models/p2_stacking_results.json"),
|
| 18 |
+
("p3", "models/p3_pipeline_results.json"),
|
| 19 |
+
]:
|
| 20 |
+
if os.path.exists(path):
|
| 21 |
+
with open(path) as f:
|
| 22 |
+
results[name] = json.load(f)
|
| 23 |
+
return results
|
| 24 |
+
|
| 25 |
+
results = load_results()
|
| 26 |
+
|
| 27 |
+
st.title("Hybrid AI Architectures for Proactive Fraud Detection")
|
| 28 |
+
st.subheader("An XAI-Driven Optimization Framework")
|
| 29 |
+
st.markdown("**Master MAII | FSTH - Universite Abdelmalek Essaadi | Latif SINARE**")
|
| 30 |
+
st.divider()
|
| 31 |
+
|
| 32 |
+
col1, col2, col3, col4 = st.columns(4)
|
| 33 |
+
with col1:
|
| 34 |
+
st.metric("Recall cible", ">= 90%")
|
| 35 |
+
with col2:
|
| 36 |
+
st.metric("FPR cible", "< 0,01%")
|
| 37 |
+
with col3:
|
| 38 |
+
st.metric("AUPRC cible", "> 0,85")
|
| 39 |
+
with col4:
|
| 40 |
+
st.metric("Precision min", ">= 10%")
|
| 41 |
+
|
| 42 |
+
st.divider()
|
| 43 |
+
|
| 44 |
+
col_a, col_b = st.columns(2)
|
| 45 |
+
with col_a:
|
| 46 |
+
st.markdown("### Architecture des Pipelines")
|
| 47 |
+
table_lines = [
|
| 48 |
+
"| Phase | Dataset | Modeles | Optimiseur | XAI |",
|
| 49 |
+
"|-------|---------|---------|------------|-----|",
|
| 50 |
+
"| 1 - Baseline | Kaggle CC | LightGBM | CMA-ES | SHAP |",
|
| 51 |
+
"| 2 - Prototype | PaySim | LSTM + RGAT + Stacking | PSO Async | GNNExplainer |",
|
| 52 |
+
"| 3 - Production | IEEE-CIS | LSTM + RGAT + Stacking | PSO Async | SHAP + GNN |",
|
| 53 |
+
"| 4 - Extension | AMLSim | RGAT | - | GNNExplainer |",
|
| 54 |
+
]
|
| 55 |
+
st.markdown(chr(10).join(table_lines))
|
| 56 |
+
|
| 57 |
+
with col_b:
|
| 58 |
+
st.markdown("### Fonction de Fitness Penalisee")
|
| 59 |
+
st.latex(r"fitness( heta) = AUPRC - 10\cdot\max(0, 0.90 - Recall) - 10\cdot\max(0, FPR - 0.0001)")
|
| 60 |
+
st.markdown("Cette fonction garantit simultanement le Recall >= 90 pourcent et le FPR < 0,01 pourcent.")
|
| 61 |
+
|
| 62 |
+
st.divider()
|
| 63 |
+
|
| 64 |
+
if results:
|
| 65 |
+
st.markdown("### Resultats disponibles")
|
| 66 |
+
cols = st.columns(len(results))
|
| 67 |
+
labels = {"p1": "Phase 1 - Kaggle CC", "p2": "Phase 2 - PaySim", "p3": "Phase 3 - IEEE-CIS"}
|
| 68 |
+
for i, (k, res) in enumerate(results.items()):
|
| 69 |
+
with cols[i]:
|
| 70 |
+
th = res.get("test_holdout", res.get("fusion_test", {}))
|
| 71 |
+
st.markdown(f"**{labels.get(k, k)}**")
|
| 72 |
+
auprc_val = th.get("auprc", 0)
|
| 73 |
+
recall_val = th.get("recall", 0)
|
| 74 |
+
fpr_val = th.get("fpr", 0)
|
| 75 |
+
st.metric("AUPRC", f"{auprc_val:.4f}")
|
| 76 |
+
st.metric("Recall", f"{recall_val:.4f}")
|
| 77 |
+
st.metric("FPR", f"{fpr_val:.6f}")
|
| 78 |
+
else:
|
| 79 |
+
st.info("Les resultats apparaitront ici au fur et a mesure de execution des notebooks 03, 08 et 11.")
|
| 80 |
+
|
| 81 |
+
st.divider()
|
| 82 |
+
st.info("Utilisez la barre laterale pour naviguer entre les pipelines et analyser des transactions individuelles.")
|
requirements.txt
CHANGED
|
@@ -1,3 +1,8 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit>=1.28.0
|
| 2 |
+
numpy>=1.24.0
|
| 3 |
+
pandas>=2.0.0
|
| 4 |
+
scikit-learn>=1.3.0
|
| 5 |
+
lightgbm>=4.0.0
|
| 6 |
+
shap>=0.43.0
|
| 7 |
+
matplotlib>=3.7.0
|
| 8 |
+
seaborn>=0.12.0
|