Spaces:
Sleeping
Sleeping
File size: 19,288 Bytes
5e1b135 c3bd7ce 5e1b135 c3bd7ce | 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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 | import streamlit as st
import json
from datetime import datetime
st.set_page_config(
page_title="ScamShield-IN",
page_icon="π‘οΈ",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for better UI
st.markdown("""
<style>
* {
margin: 0;
padding: 0;
}
.main {
padding: 2rem;
}
.header-container {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 2rem;
border-radius: 12px;
color: white;
margin-bottom: 2rem;
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.header-container h1 {
font-size: 2.5rem;
font-weight: 700;
margin-bottom: 0.5rem;
}
.header-container p {
font-size: 1.1rem;
opacity: 0.95;
}
.input-section {
background: #f8f9fa;
padding: 2rem;
border-radius: 12px;
border-left: 4px solid #667eea;
margin-bottom: 2rem;
}
.result-card-high {
background: linear-gradient(135deg, #ff6b6b 0%, #ee5a6f 100%);
color: white;
padding: 1.5rem;
border-radius: 12px;
margin-bottom: 1rem;
box-shadow: 0 4px 15px rgba(255, 107, 107, 0.3);
}
.result-card-medium {
background: linear-gradient(135deg, #ffa502 0%, #ff8c42 100%);
color: white;
padding: 1.5rem;
border-radius: 12px;
margin-bottom: 1rem;
box-shadow: 0 4px 15px rgba(255, 165, 2, 0.3);
}
.result-card-low {
background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
color: white;
padding: 1.5rem;
border-radius: 12px;
margin-bottom: 1rem;
box-shadow: 0 4px 15px rgba(81, 207, 102, 0.3);
}
.category-badge {
display: inline-block;
background: rgba(255, 255, 255, 0.2);
padding: 0.5rem 1rem;
border-radius: 20px;
font-weight: 600;
margin-bottom: 0.5rem;
}
.precaution-box {
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 1rem;
border-radius: 8px;
margin: 1rem 0;
}
.precaution-box h4 {
color: #856404;
margin-bottom: 0.5rem;
}
.precaution-box ul {
color: #856404;
padding-left: 1.5rem;
}
.precaution-box li {
margin-bottom: 0.3rem;
font-size: 0.95rem;
}
.example-container {
background: #f8f9fa;
padding: 1rem;
border-radius: 8px;
border-left: 3px solid #667eea;
}
.example-container p {
margin: 0.5rem 0;
font-size: 0.9rem;
color: #495057;
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1rem;
margin: 2rem 0;
}
.stat-card {
background: white;
padding: 1.5rem;
border-radius: 12px;
text-align: center;
border: 1px solid #e9ecef;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.stat-card h3 {
font-size: 2rem;
color: #667eea;
margin-bottom: 0.5rem;
}
.stat-card p {
color: #6c757d;
font-size: 0.9rem;
}
.footer {
background: #f8f9fa;
padding: 2rem;
border-radius: 12px;
margin-top: 3rem;
border-top: 2px solid #e9ecef;
text-align: center;
color: #6c757d;
font-size: 0.9rem;
}
.fraud-type-info {
background: #e7f3ff;
border-left: 4px solid #0066cc;
padding: 1rem;
border-radius: 8px;
margin: 0.5rem 0;
font-size: 0.95rem;
color: #004085;
}
</style>
""", unsafe_allow_html=True)
# Header
st.markdown("""
<div class="header-container">
<h1>π‘οΈ ScamShield-IN</h1>
<p>AI-Powered Hinglish Fraud SMS Detection | HackIndia Submission</p>
</div>
""", unsafe_allow_html=True)
# Fraud category definitions
fraud_info = {
"Bank_Phishing": {
"icon": "π¦",
"description": "Fake bank alerts asking for account details or verification",
"precautions": [
"Banks NEVER ask for passwords/OTP via SMS",
"Never click links in SMS - call bank directly",
"Official bank domain: bank.com (check carefully)",
"Check sender ID - real banks use registered numbers",
"Verify with bank using official helpline numbers"
],
"examples": [
"SBI Alert: Account suspended. Verify at sbi-kyc.net",
"HDFC: Unusual login detected. Confirm at hdfc-secure.in"
]
},
"Prize_Scam": {
"icon": "π",
"description": "Fake lottery/prize winnings to lure you into claiming",
"precautions": [
"You can't win lotteries you didn't enter",
"Real lotteries never contact via SMS first",
"Legitimate prizes have official verification process",
"Never pay fees to claim prizes",
"Check official lottery websites for confirmation"
],
"examples": [
"You won Rs 1 crore in KBC! Claim now",
"Congratulations! You're our lucky winner"
]
},
"Credit_Card_Scam": {
"icon": "π³",
"description": "Fake credit card offers with unrealistic benefits",
"precautions": [
"No bank gives pre-approved cards without application",
"Unrealistic interest rates = RED FLAG",
"Banks have proper verification process",
"Never share card details via SMS links",
"Apply through official bank websites only"
],
"examples": [
"Pre-approved card Rs 3 lakh limit! Apply now",
"Zero interest EMI card - exclusive offer"
]
},
"Phishing": {
"icon": "π£",
"description": "Generic attempts to steal login credentials or personal data",
"precautions": [
"Never click suspicious links",
"Don't share passwords, OTPs, or PINs",
"Verify sender through official channels",
"Legitimate companies use official domains",
"Check URL carefully before entering credentials"
],
"examples": [
"Your account verification required. Click here",
"Confirm your identity to unlock account"
]
},
"KYC_Fraud": {
"icon": "π",
"description": "Fake KYC/identity verification requests",
"precautions": [
"Government never asks KYC via SMS links",
"KYC updates happen through official portals",
"Verify using official government websites",
"Never share Aadhaar/PAN via unverified links",
"Go to official office for verification if needed"
],
"examples": [
"Aadhaar KYC expired. Update at kyc-aadhar.in",
"PAN-Aadhaar linking mandatory - verify now"
]
},
"UPI_Phishing": {
"icon": "π±",
"description": "Fake UPI/payment app alerts and money transfer scams",
"precautions": [
"NEVER share UPI PIN with anyone",
"UPI apps don't ask for PIN via SMS",
"Verify payment requests through app only",
"Check official app only from Play Store/App Store",
"Report suspicious transactions immediately"
],
"examples": [
"UPI payment failed. Retry at upi-retry.in",
"Your UPI ID linked to suspicious account"
]
},
"Brand_Impersonation_Scam": {
"icon": "π’",
"description": "Fake offers pretending to be from popular brands",
"precautions": [
"Verify official brand domains carefully",
"Real brands have consistent communication",
"Check official app before clicking links",
"Brand offers on official platforms only",
"Report fake accounts to brand's official handles"
],
"examples": [
"Amazon: You won iPhone 14! Claim now",
"Flipkart: Free 100GB storage offer"
]
},
"Fake_Service_App_Scam": {
"icon": "π²",
"description": "Fake earning/loan apps that steal data or money",
"precautions": [
"Only download apps from official stores",
"Check app reviews and developer credibility",
"Legitimate apps don't ask for upfront payment",
"Be skeptical of 'earn money quick' promises",
"Read permissions before installing apps"
],
"examples": [
"Earn Rs 500/day watching videos - download app",
"Get instant loan without documents"
]
},
"Malware_Scam": {
"icon": "π¦ ",
"description": "Fake virus/malware alerts trying to get you to install malicious software",
"precautions": [
"SMS alerts about viruses are always fake",
"Antivirus apps come from Play Store only",
"Your phone doesn't send SMS warnings automatically",
"Never download 'security patches' from SMS links",
"Use official antivirus if concerned"
],
"examples": [
"VIRUS DETECTED on your phone! Clean now",
"Your Android is infected. Download patch"
]
},
"Offer_Phishing": {
"icon": "π°",
"description": "Fake deals and promotional offers to collect personal data",
"precautions": [
"Unrealistic discounts = SCAM",
"Verify offers on official websites only",
"Don't enter personal details for discounts",
"Real offers don't need verification links",
"Compare with official brand prices"
],
"examples": [
"Amazon sale: 90% off everything!",
"Diwali offer: Buy 2 get 5 free"
]
},
"Online_Shopping_Scam": {
"icon": "ποΈ",
"description": "Fake shopping platform or order confirmation scams",
"precautions": [
"Shop only on official verified platforms",
"Check website HTTPS and official domain",
"Be wary of prices too good to be true",
"Use official apps, not SMS links",
"Verify order through official seller account"
],
"examples": [
"Your Flipkart order delayed. Update here",
"Myntra refund pending - click to claim"
]
},
"Utility_Scam": {
"icon": "β‘",
"description": "Fake bills and utility service threats (electricity, water, gas)",
"precautions": [
"Utilities have official payment portals",
"Verify bill amount on official website",
"Never pay via SMS links",
"Check official bill copies",
"Call official helpline for payment confirmation"
],
"examples": [
"Your electricity bill overdue. Pay now",
"Water connection will be disconnected"
]
},
"Phishing_Scam": {
"icon": "π",
"description": "Complex phishing involving impersonation and social engineering",
"precautions": [
"Verify sender identity independently",
"Don't trust caller ID alone",
"Ask security questions before sharing info",
"Hang up and call official number to verify",
"Be suspicious of urgent requests"
],
"examples": [
"Government giving free money - apply here",
"Your ticket is cancelled - refund pending"
]
}
}
# Main content
col1, col2 = st.columns([2, 1])
with col1:
st.markdown("<div class='input-section'>", unsafe_allow_html=True)
st.markdown("### π Enter SMS Message")
sms_text = st.text_area(
"Paste your SMS here (English or Hinglish):",
placeholder="Example: Your SBI account will be suspended. Update KYC immediately at sbi-kyc.net/update",
height=120,
label_visibility="collapsed"
)
st.markdown("</div>", unsafe_allow_html=True)
with col2:
st.markdown("#### π‘ Quick Examples")
st.markdown("""
**Bank Phishing:**
"Account suspended"
**Prize Scam:**
"You won Rs 1cr"
**KYC Fraud:**
"Update Aadhaar"
""")
# Analysis
if sms_text.strip():
st.markdown("---")
st.markdown("### π Detection Result")
# Simple fraud detection logic
sms_lower = sms_text.lower()
detection_scores = {
"Bank_Phishing": 0,
"Prize_Scam": 0,
"Credit_Card_Scam": 0,
"Fake_Service_App_Scam": 0,
"KYC_Fraud": 0,
"Malware_Scam": 0,
"Offer_Phishing": 0,
"Online_Shopping_Scam": 0,
"Phishing": 0,
"Phishing_Scam": 0,
"UPI_Phishing": 0,
"Utility_Scam": 0
}
# Keyword matching for detection
keywords = {
"Bank_Phishing": ["bank", "account", "suspend", "kyc", "verify", "hdfc", "sbi", "icici", "axis"],
"Prize_Scam": ["won", "prize", "lottery", "crore", "congratulations", "winner", "claim"],
"Credit_Card_Scam": ["credit card", "limit", "approved", "interest", "emi"],
"Fake_Service_App_Scam": ["app", "download", "earn", "job", "loan", "free"],
"KYC_Fraud": ["kyc", "aadhaar", "pan", "identity", "verify", "update"],
"Malware_Scam": ["virus", "malware", "infected", "clean", "security", "hack"],
"Offer_Phishing": ["offer", "discount", "off", "sale", "limited", "free"],
"Online_Shopping_Scam": ["order", "refund", "flipkart", "amazon", "myntra", "delivery"],
"Phishing": ["verify", "confirm", "urgent", "click", "link", "update", "secure"],
"Phishing_Scam": ["government", "refund", "compensation", "scheme", "apply"],
"UPI_Phishing": ["upi", "payment", "failed", "pin", "wallet", "transaction"],
"Utility_Scam": ["bill", "electricity", "water", "gas", "connection", "disconnect"]
}
for fraud_type, kw_list in keywords.items():
for keyword in kw_list:
if keyword in sms_lower:
detection_scores[fraud_type] += 1
# Get top prediction
max_score = max(detection_scores.values()) if detection_scores else 0
if max_score > 0:
prediction = max(detection_scores, key=detection_scores.get)
confidence = min(0.85 + (max_score * 0.05), 0.99)
else:
prediction = "Phishing"
confidence = 0.65
# Determine risk level
if confidence > 0.85:
risk_level = "HIGH RISK"
risk_emoji = "π΄"
card_class = "result-card-high"
elif confidence > 0.70:
risk_level = "MEDIUM RISK"
risk_emoji = "π "
card_class = "result-card-medium"
else:
risk_level = "LOW RISK"
risk_emoji = "π’"
card_class = "result-card-low"
# Display result card
st.markdown(f"""
<div class="{card_class}">
<div style="display: flex; justify-content: space-between; align-items: center;">
<div>
<p style="margin: 0; font-size: 0.9rem; opacity: 0.9;">FRAUD TYPE</p>
<p style="margin: 0.5rem 0 0; font-size: 1.5rem; font-weight: 700;">
{fraud_info[prediction]['icon']} {prediction.replace('_', ' ')}
</p>
</div>
<div style="text-align: right;">
<p style="margin: 0; font-size: 0.9rem; opacity: 0.9;">RISK LEVEL</p>
<p style="margin: 0.5rem 0 0; font-size: 1.5rem; font-weight: 700;">
{risk_emoji} {risk_level}
</p>
</div>
<div style="text-align: right;">
<p style="margin: 0; font-size: 0.9rem; opacity: 0.9;">CONFIDENCE</p>
<p style="margin: 0.5rem 0 0; font-size: 1.5rem; font-weight: 700;">
{confidence*100:.0f}%
</p>
</div>
</div>
</div>
""", unsafe_allow_html=True)
# Detailed analysis
st.markdown("### π What This Is")
st.markdown(f"**{fraud_info[prediction]['description']}**")
st.markdown(f"""
<div class="fraud-type-info">
{fraud_info[prediction]['description']}
</div>
""", unsafe_allow_html=True)
# Real-time precautions based on fraud type
st.markdown("### β οΈ Immediate Actions Required")
precautions_html = f"""
<div class="precaution-box">
<h4>π‘οΈ Protect Yourself Now:</h4>
<ul>
"""
for precaution in fraud_info[prediction]['precautions']:
precautions_html += f"<li>{precaution}</li>"
precautions_html += """
</ul>
</div>
"""
st.markdown(precautions_html, unsafe_allow_html=True)
# Similar examples
st.markdown("### π Similar Fraud Examples")
for example in fraud_info[prediction]['examples']:
st.markdown(f"- *{example}*")
# Action recommendations
st.markdown("### β
Recommended Actions")
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("#### 1οΈβ£ Report It")
st.markdown("- cybercrime.gov.in\n- Police cyber cell\n- Your bank/service")
with col2:
st.markdown("#### 2οΈβ£ Block & Delete")
st.markdown("- Block sender number\n- Delete message\n- Don't reply/click")
with col3:
st.markdown("#### 3οΈβ£ Verify Independently")
st.markdown("- Call official number\n- Check official app\n- Visit official website")
# Stats section
st.markdown("---")
st.markdown("### π ScamShield-IN Statistics")
col1, col2, col3 = st.columns(3)
with col1:
st.markdown("""
<div class="stat-card">
<h3>579</h3>
<p>Training SMS Examples</p>
</div>
""", unsafe_allow_html=True)
with col2:
st.markdown("""
<div class="stat-card">
<h3>13</h3>
<p>Fraud Categories Detected</p>
</div>
""", unsafe_allow_html=True)
with col3:
st.markdown("""
<div class="stat-card">
<h3>90%</h3>
<p>Quality Improvement</p>
</div>
""", unsafe_allow_html=True)
# Footer
st.markdown("""
<div class="footer">
<h3>π― ScamShield-IN Part 1 Submission</h3>
<p><strong>HackIndia Γ Adaption AutoScientist Challenge</strong></p>
<p>Team: Haxrits | Participant ID: HI014856</p>
<p style="margin-top: 1rem; color: #999;">
Dataset: 579 Hinglish fraud SMS examples across 13 categories |
Model: Mixtral-8x7B fine-tuned with LoRA |
Quality: 90% improvement via AutoScientist
</p>
<p style="margin-top: 0.5rem;">
<a href="https://github.com/haxrits" style="color: #667eea; text-decoration: none;">GitHub</a> β’
<a href="https://huggingface.co/haxrits" style="color: #667eea; text-decoration: none;">HuggingFace</a> β’
<a href="https://linkedin.com" style="color: #667eea; text-decoration: none;">LinkedIn</a>
</p>
</div>
""", unsafe_allow_html=True) |