Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,9 +5,7 @@ import plotly.graph_objects as go
|
|
| 5 |
import numpy as np
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
-
# ==========================================
|
| 9 |
# 1. PAGE CONFIGURATION
|
| 10 |
-
# ==========================================
|
| 11 |
st.set_page_config(
|
| 12 |
page_title="Sentinel | UIDAI Fraud Detection",
|
| 13 |
page_icon="π‘οΈ",
|
|
@@ -15,9 +13,7 @@ st.set_page_config(
|
|
| 15 |
initial_sidebar_state="expanded"
|
| 16 |
)
|
| 17 |
|
| 18 |
-
# ==========================================
|
| 19 |
# 2. PROFESSIONAL STYLING (THEME OVERRIDE)
|
| 20 |
-
# ==========================================
|
| 21 |
st.markdown("""
|
| 22 |
<style>
|
| 23 |
/* IMPORT FONTS */
|
|
@@ -101,9 +97,7 @@ st.markdown("""
|
|
| 101 |
</style>
|
| 102 |
""", unsafe_allow_html=True)
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
# 3. SMART DATA LOADING (FIXED MAPPING)
|
| 106 |
-
# ==========================================
|
| 107 |
@st.cache_data
|
| 108 |
def load_data():
|
| 109 |
# 1. Load or Generate Data
|
|
@@ -114,7 +108,7 @@ def load_data():
|
|
| 114 |
dates = pd.date_range(start="2025-01-01", periods=200)
|
| 115 |
df = pd.DataFrame({
|
| 116 |
'date': dates,
|
| 117 |
-
'state': np.random.choice(['Maharashtra', 'Uttar Pradesh', 'Bihar', 'Karnataka', 'Delhi', 'West Bengal', 'Tamil Nadu'], 200),
|
| 118 |
'district': np.random.choice(['North', 'South', 'East', 'West', 'Central', 'Rural A', 'Urban B'], 200),
|
| 119 |
'pincode': np.random.randint(110001, 800000, 200),
|
| 120 |
'RISK_SCORE': np.random.uniform(15, 99, 200),
|
|
@@ -128,23 +122,45 @@ def load_data():
|
|
| 128 |
if 'date' in df.columns:
|
| 129 |
df['date'] = pd.to_datetime(df['date'])
|
| 130 |
|
| 131 |
-
#
|
| 132 |
-
#
|
| 133 |
-
# ---------------------------------------------------------
|
| 134 |
-
# Define approximate center points for major states
|
| 135 |
state_centers = {
|
| 136 |
-
'
|
| 137 |
-
'
|
|
|
|
|
|
|
| 138 |
'Bihar': (25.0961, 85.3131),
|
| 139 |
-
'
|
|
|
|
|
|
|
| 140 |
'Delhi': (28.7041, 77.1025),
|
| 141 |
-
'
|
| 142 |
-
'Tamil Nadu': (11.1271, 78.6569),
|
| 143 |
-
'Kerala': (10.8505, 76.2711),
|
| 144 |
'Gujarat': (22.2587, 71.1924),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
'Rajasthan': (27.0238, 74.2179),
|
| 146 |
-
'
|
| 147 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
def get_coords(row):
|
|
@@ -193,9 +209,7 @@ def load_data():
|
|
| 193 |
# Load Data
|
| 194 |
df = load_data()
|
| 195 |
|
| 196 |
-
# ==========================================
|
| 197 |
# 4. SIDEBAR & FILTERS
|
| 198 |
-
# ==========================================
|
| 199 |
with st.sidebar:
|
| 200 |
st.markdown("### π‘οΈ Sentinel Control")
|
| 201 |
st.markdown("---")
|
|
@@ -229,12 +243,16 @@ with st.sidebar:
|
|
| 229 |
if risk_filter:
|
| 230 |
filtered_df = filtered_df[filtered_df['risk_category'].isin(risk_filter)]
|
| 231 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
st.markdown("---")
|
| 233 |
st.info(f"**User:** UIDAI_Officer\n\n**Team:** UIDAI_4571")
|
| 234 |
|
| 235 |
-
# ==========================================
|
| 236 |
# 5. HEADER & KPI METRICS
|
| 237 |
-
# ==========================================
|
| 238 |
col1, col2 = st.columns([3, 1])
|
| 239 |
with col1:
|
| 240 |
st.title("Project Sentinel Dashboard")
|
|
@@ -264,12 +282,10 @@ m4.metric("Weekend Spikes", f"{weekend_alerts}", "Unauthorized", delta_color="of
|
|
| 264 |
|
| 265 |
st.markdown("##") # Spacer
|
| 266 |
|
| 267 |
-
# ==========================================
|
| 268 |
# 6. MAIN TABS
|
| 269 |
-
# ==========================================
|
| 270 |
tab_map, tab_list, tab_charts = st.tabs(["πΊοΈ Geographic Risk", "π Priority List", "π Pattern Analytics"])
|
| 271 |
|
| 272 |
-
#
|
| 273 |
with tab_map:
|
| 274 |
col_map, col_details = st.columns([3, 1])
|
| 275 |
|
|
@@ -312,7 +328,7 @@ with tab_map:
|
|
| 312 |
</div>
|
| 313 |
""", unsafe_allow_html=True)
|
| 314 |
|
| 315 |
-
#
|
| 316 |
with tab_list:
|
| 317 |
st.subheader("Target Investigation List")
|
| 318 |
st.markdown("Filter: *Showing centers with Risk Score > 75*")
|
|
@@ -381,9 +397,7 @@ with tab_charts:
|
|
| 381 |
fig_hist.update_layout(bargap=0.1)
|
| 382 |
st.plotly_chart(fig_hist, use_container_width=True)
|
| 383 |
|
| 384 |
-
# ==========================================
|
| 385 |
# 7. FOOTER
|
| 386 |
-
# ==========================================
|
| 387 |
st.markdown("---")
|
| 388 |
st.markdown("""
|
| 389 |
<div style="text-align: center; font-size: 13px; color: #94a3b8;">
|
|
|
|
| 5 |
import numpy as np
|
| 6 |
from datetime import datetime
|
| 7 |
|
|
|
|
| 8 |
# 1. PAGE CONFIGURATION
|
|
|
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="Sentinel | UIDAI Fraud Detection",
|
| 11 |
page_icon="π‘οΈ",
|
|
|
|
| 13 |
initial_sidebar_state="expanded"
|
| 14 |
)
|
| 15 |
|
|
|
|
| 16 |
# 2. PROFESSIONAL STYLING (THEME OVERRIDE)
|
|
|
|
| 17 |
st.markdown("""
|
| 18 |
<style>
|
| 19 |
/* IMPORT FONTS */
|
|
|
|
| 97 |
</style>
|
| 98 |
""", unsafe_allow_html=True)
|
| 99 |
|
| 100 |
+
# 3. SMART DATA LOADING (MAPPING)
|
|
|
|
|
|
|
| 101 |
@st.cache_data
|
| 102 |
def load_data():
|
| 103 |
# 1. Load or Generate Data
|
|
|
|
| 108 |
dates = pd.date_range(start="2025-01-01", periods=200)
|
| 109 |
df = pd.DataFrame({
|
| 110 |
'date': dates,
|
| 111 |
+
'state': np.random.choice(['Maharashtra', 'Uttar Pradesh', 'Bihar', 'Karnataka', 'Delhi', 'West Bengal', 'Tamil Nadu', 'Gujarat', 'Rajasthan', 'Kerala'], 200),
|
| 112 |
'district': np.random.choice(['North', 'South', 'East', 'West', 'Central', 'Rural A', 'Urban B'], 200),
|
| 113 |
'pincode': np.random.randint(110001, 800000, 200),
|
| 114 |
'RISK_SCORE': np.random.uniform(15, 99, 200),
|
|
|
|
| 122 |
if 'date' in df.columns:
|
| 123 |
df['date'] = pd.to_datetime(df['date'])
|
| 124 |
|
| 125 |
+
# SMART GEO-CLUSTERING LOGIC
|
| 126 |
+
# Comprehensive Center Points for Indian States & UTs
|
|
|
|
|
|
|
| 127 |
state_centers = {
|
| 128 |
+
'Andaman and Nicobar Islands': (11.7401, 92.6586),
|
| 129 |
+
'Andhra Pradesh': (15.9129, 79.7400),
|
| 130 |
+
'Arunachal Pradesh': (28.2180, 94.7278),
|
| 131 |
+
'Assam': (26.2006, 92.9376),
|
| 132 |
'Bihar': (25.0961, 85.3131),
|
| 133 |
+
'Chandigarh': (30.7333, 76.7794),
|
| 134 |
+
'Chhattisgarh': (21.2787, 81.8661),
|
| 135 |
+
'Dadra and Nagar Haveli and Daman and Diu': (20.4283, 72.8397),
|
| 136 |
'Delhi': (28.7041, 77.1025),
|
| 137 |
+
'Goa': (15.2993, 74.1240),
|
|
|
|
|
|
|
| 138 |
'Gujarat': (22.2587, 71.1924),
|
| 139 |
+
'Haryana': (29.0588, 76.0856),
|
| 140 |
+
'Himachal Pradesh': (31.1048, 77.1734),
|
| 141 |
+
'Jammu and Kashmir': (33.7782, 76.5762),
|
| 142 |
+
'Jharkhand': (23.6102, 85.2799),
|
| 143 |
+
'Karnataka': (15.3173, 75.7139),
|
| 144 |
+
'Kerala': (10.8505, 76.2711),
|
| 145 |
+
'Ladakh': (34.1526, 77.5770),
|
| 146 |
+
'Lakshadweep': (10.5667, 72.6417),
|
| 147 |
+
'Madhya Pradesh': (22.9734, 78.6569),
|
| 148 |
+
'Maharashtra': (19.7515, 75.7139),
|
| 149 |
+
'Manipur': (24.6637, 93.9063),
|
| 150 |
+
'Meghalaya': (25.4670, 91.3662),
|
| 151 |
+
'Mizoram': (23.1645, 92.9376),
|
| 152 |
+
'Nagaland': (26.1584, 94.5624),
|
| 153 |
+
'Odisha': (20.9517, 85.0985),
|
| 154 |
+
'Puducherry': (11.9416, 79.8083),
|
| 155 |
+
'Punjab': (31.1471, 75.3412),
|
| 156 |
'Rajasthan': (27.0238, 74.2179),
|
| 157 |
+
'Sikkim': (27.5330, 88.5122),
|
| 158 |
+
'Tamil Nadu': (11.1271, 78.6569),
|
| 159 |
+
'Telangana': (18.1124, 79.0193),
|
| 160 |
+
'Tripura': (23.9408, 91.9882),
|
| 161 |
+
'Uttar Pradesh': (26.8467, 80.9462),
|
| 162 |
+
'Uttarakhand': (30.0668, 79.0193),
|
| 163 |
+
'West Bengal': (22.9868, 87.8550)
|
| 164 |
}
|
| 165 |
|
| 166 |
def get_coords(row):
|
|
|
|
| 209 |
# Load Data
|
| 210 |
df = load_data()
|
| 211 |
|
|
|
|
| 212 |
# 4. SIDEBAR & FILTERS
|
|
|
|
| 213 |
with st.sidebar:
|
| 214 |
st.markdown("### π‘οΈ Sentinel Control")
|
| 215 |
st.markdown("---")
|
|
|
|
| 243 |
if risk_filter:
|
| 244 |
filtered_df = filtered_df[filtered_df['risk_category'].isin(risk_filter)]
|
| 245 |
|
| 246 |
+
st.markdown("---")
|
| 247 |
+
|
| 248 |
+
# Links
|
| 249 |
+
st.markdown("**Resources**")
|
| 250 |
+
st.link_button("π Open Notebook in Colab", "https://colab.research.google.com/drive/1YAQ4nfxltvG_cts3fmGc_zi2JQc4oPOT?usp=sharing")
|
| 251 |
+
|
| 252 |
st.markdown("---")
|
| 253 |
st.info(f"**User:** UIDAI_Officer\n\n**Team:** UIDAI_4571")
|
| 254 |
|
|
|
|
| 255 |
# 5. HEADER & KPI METRICS
|
|
|
|
| 256 |
col1, col2 = st.columns([3, 1])
|
| 257 |
with col1:
|
| 258 |
st.title("Project Sentinel Dashboard")
|
|
|
|
| 282 |
|
| 283 |
st.markdown("##") # Spacer
|
| 284 |
|
|
|
|
| 285 |
# 6. MAIN TABS
|
|
|
|
| 286 |
tab_map, tab_list, tab_charts = st.tabs(["πΊοΈ Geographic Risk", "π Priority List", "π Pattern Analytics"])
|
| 287 |
|
| 288 |
+
# TAB 1: GEOGRAPHIC RISK (MAP)
|
| 289 |
with tab_map:
|
| 290 |
col_map, col_details = st.columns([3, 1])
|
| 291 |
|
|
|
|
| 328 |
</div>
|
| 329 |
""", unsafe_allow_html=True)
|
| 330 |
|
| 331 |
+
# TAB 2: PRIORITY LIST (DATAFRAME)
|
| 332 |
with tab_list:
|
| 333 |
st.subheader("Target Investigation List")
|
| 334 |
st.markdown("Filter: *Showing centers with Risk Score > 75*")
|
|
|
|
| 397 |
fig_hist.update_layout(bargap=0.1)
|
| 398 |
st.plotly_chart(fig_hist, use_container_width=True)
|
| 399 |
|
|
|
|
| 400 |
# 7. FOOTER
|
|
|
|
| 401 |
st.markdown("---")
|
| 402 |
st.markdown("""
|
| 403 |
<div style="text-align: center; font-size: 13px; color: #94a3b8;">
|