Spaces:
Sleeping
Sleeping
File size: 4,273 Bytes
09e8c44 f2b0e14 a05e504 f2b0e14 09e8c44 0d0e83b f2b0e14 09e8c44 f2b0e14 09e8c44 570633a 8ab699f a05e504 8ab699f 09e8c44 a8c34f2 8ab699f a05e504 8ab699f a8c34f2 f2b0e14 570633a a8c34f2 f2b0e14 09e8c44 f2b0e14 a05e504 f2b0e14 09e8c44 f2b0e14 a05e504 f2b0e14 8c3da40 f2b0e14 8c3da40 f2b0e14 8c3da40 f2b0e14 8c3da40 0d0e83b 8ab699f f2b0e14 570633a 8ab699f 570633a a8c34f2 570633a a8c34f2 f2b0e14 a8c34f2 a05e504 09e8c44 f2b0e14 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import streamlit.components.v1 as components
import xgboost as xgb
from sklearn.model_selection import train_test_split
st.set_page_config(layout="wide", page_title="FraudFlow India")
st.title("FraudFlow India: UPI Fraud Evolution Map")
st.markdown("**Real RBI-style data (2018-2026) + XGBoost risk scoring + Gemini 2.5 Flash predictions.**")
# ββ Load Data ββ
@st.cache_data
def load_district():
df = pd.read_csv('fraudflow_districts.csv')
df['year'] = df['year'].astype(int)
return df
@st.cache_data
def load_base():
df = pd.read_csv('fraudflow_base.csv')
df['year'] = df['year'].astype(int)
return df
@st.cache_data
def load_predictions():
try:
df = pd.read_csv('fraudflow_2026_predictions.csv')
return df
except FileNotFoundError:
return None
df = load_district()
df_base = load_base()
df_pred = load_predictions()
# ββ Animated Bar Chart ββ
st.subheader("Fraud Cases by District & Year (Animated 2018-2025)")
try:
with open("fraudflow_bar.html", "r", encoding="utf-8") as f:
bar_html = f.read()
components.html(bar_html, height=550, scrolling=False)
except FileNotFoundError:
st.error("fraudflow_bar.html not found.")
# ββ National Trend ββ
st.subheader("National Fraud Trend (RBI Data 2018-2025)")
try:
with open("fraudflow_trend.html", "r", encoding="utf-8") as f:
trend_html = f.read()
components.html(trend_html, height=500, scrolling=False)
except FileNotFoundError:
st.error("fraudflow_trend.html not found.")
# ββ XGBoost 2026 Predictions ββ
st.subheader("XGBoost 2026 Fraud Risk Predictions")
st.markdown("*Trained on 2018-2025 district fraud trajectory. Predicts 2026 fraud index per district.*")
# Load pre-built HTML chart
try:
with open("fraudflow_xgb.html", "r", encoding="utf-8") as f:
xgb_html = f.read()
components.html(xgb_html, height=560, scrolling=False)
except FileNotFoundError:
st.error("fraudflow_xgb.html not found. Please upload it.")
if df_pred is not None:
# Predicted vs actual table
st.markdown("#### 2025 Actual vs 2026 XGBoost Predicted Fraud Index")
display_df = df_pred[['district', 'cases_local', 'predicted_cases_2026', 'xgb_risk_pct']].copy()
display_df.columns = ['District', '2025 Fraud Index', '2026 Predicted Index', 'Risk Score (%)']
display_df = display_df.sort_values('Risk Score (%)', ascending=False).reset_index(drop=True)
display_df.index += 1
st.dataframe(display_df, use_container_width=True)
# Top 3 metric cards
st.markdown("#### Top 3 High Risk Districts for 2026")
top3 = display_df.head(3)
col1, col2, col3 = st.columns(3)
with col1:
st.metric(
label=top3.iloc[0]['District'],
value=f"{top3.iloc[0]['Risk Score (%)']:.1f}%",
delta=f"Predicted index: {top3.iloc[0]['2026 Predicted Index']:.1f}"
)
with col2:
st.metric(
label=top3.iloc[1]['District'],
value=f"{top3.iloc[1]['Risk Score (%)']:.1f}%",
delta=f"Predicted index: {top3.iloc[1]['2026 Predicted Index']:.1f}"
)
with col3:
st.metric(
label=top3.iloc[2]['District'],
value=f"{top3.iloc[2]['Risk Score (%)']:.1f}%",
delta=f"Predicted index: {top3.iloc[2]['2026 Predicted Index']:.1f}"
)
# ββ Top 5 Hotspots 2025 ββ
st.subheader("Top 5 Fraud Hotspot Districts (2025 Actual)")
top5 = (
df[df['year'] == 2025]
.sort_values('cases_local', ascending=False)
.head(5)[['district', 'cases_local']]
.reset_index(drop=True)
)
top5.columns = ['District', 'Fraud Index (per 10K transactions)']
top5.index += 1
st.table(top5)
# ββ Gemini Prediction ββ
st.subheader("Gemini 2.5 Flash Predictions for 2026")
try:
with open('gemini_prediction.txt', 'r', encoding='utf-8') as f:
prediction = f.read()
st.info(prediction)
except FileNotFoundError:
st.warning("gemini_prediction.txt not found.")
st.markdown("---")
st.caption("Built by Vipul | Data: RBI DBIE/NCRB | ML: XGBoost | AI: Gemini 2.5 Flash | #FintechAI #UPI #RBI") |