Spaces:
Running
Running
| #!/usr/bin/env python3 | |
| """ | |
| SecureX Light - Version simplifiée du système de détection de fraude | |
| """ | |
| import tkinter as tk | |
| from tkinter import scrolledtext, messagebox | |
| import re | |
| import sqlite3 | |
| import json | |
| from datetime import datetime | |
| class FraudDetector: | |
| def __init__(self): | |
| self.patterns = [ | |
| { | |
| "name": "fake_advisor", | |
| "keywords": ["conseiller", "banque", "urgent", "code"], | |
| "weight": 0.9 | |
| }, | |
| { | |
| "name": "fake_refund", | |
| "keywords": ["remboursement", "argent", "code"], | |
| "weight": 0.85 | |
| }, | |
| { | |
| "name": "credential_theft", | |
| "keywords": ["mot de passe", "identifiant", "code secret"], | |
| "weight": 0.95 | |
| } | |
| ] | |
| self.init_database() | |
| def init_database(self): | |
| """Crée une base de données SQLite simple""" | |
| self.conn = sqlite3.connect(":memory:") | |
| self.cursor = self.conn.cursor() | |
| self.cursor.execute(""" | |
| CREATE TABLE IF NOT EXISTS calls ( | |
| id INTEGER PRIMARY KEY, | |
| transcript TEXT, | |
| score REAL, | |
| timestamp DATETIME | |
| ) | |
| """) | |
| self.conn.commit() | |
| def analyze_text(self, text): | |
| """Analyse le texte avec des motifs simples""" | |
| if not text: | |
| return 0.0 | |
| text_lower = text.lower() | |
| total_score = 0.0 | |
| for pattern in self.patterns: | |
| matches = sum(1 for word in pattern["keywords"] if word in text_lower) | |
| if matches > 0: | |
| total_score += (matches / len(pattern["keywords"])) * pattern["weight"] | |
| # Détection d'urgence | |
| urgency_words = ["urgent", "immédiat", "vite", "maintenant"] | |
| if sum(1 for word in urgency_words if word in text_lower) >= 2: | |
| total_score += 0.2 | |
| return min(total_score, 1.0) | |
| def save_call(self, text, score): | |
| """Sauvegarde l'appel dans la base""" | |
| self.cursor.execute(""" | |
| INSERT INTO calls (transcript, score, timestamp) | |
| VALUES (?, ?, ?) | |
| """, (text, score, datetime.now())) | |
| self.conn.commit() | |
| class Application(tk.Tk): | |
| def __init__(self): | |
| super().__init__() | |
| self.title("SecureX Light - Détection de Fraude") | |
| self.geometry("700x500") | |
| self.detector = FraudDetector() | |
| self.create_widgets() | |
| def create_widgets(self): | |
| """Crée l'interface utilisateur""" | |
| # Zone de texte pour l'entrée | |
| tk.Label(self, text="Transcript d'appel:").pack(pady=5) | |
| self.text_input = scrolledtext.ScrolledText(self, height=10) | |
| self.text_input.pack(fill=tk.X, padx=10, pady=5) | |
| # Boutons | |
| btn_frame = tk.Frame(self) | |
| btn_frame.pack(pady=10) | |
| tk.Button(btn_frame, text="Analyser", command=self.analyze).pack(side=tk.LEFT, padx=5) | |
| tk.Button(btn_frame, text="Exemple Fraude", command=self.load_fraud_example).pack(side=tk.LEFT, padx=5) | |
| tk.Button(btn_frame, text="Exemple Normal", command=self.load_normal_example).pack(side=tk.LEFT, padx=5) | |
| # Résultats | |
| tk.Label(self, text="Résultats:").pack(pady=5) | |
| self.result_text = scrolledtext.ScrolledText(self, height=10) | |
| self.result_text.pack(fill=tk.BOTH, expand=True, padx=10, pady=5) | |
| def analyze(self): | |
| """Lance l'analyse""" | |
| text = self.text_input.get("1.0", tk.END).strip() | |
| if not text: | |
| messagebox.showwarning("Attention", "Veuillez entrer un texte à analyser") | |
| return | |
| score = self.detector.analyze_text(text) | |
| self.detector.save_call(text, score) | |
| # Affichage des résultats | |
| self.result_text.delete("1.0", tk.END) | |
| if score > 0.7: | |
| result = f"🚨 ALERTE FRAUDE (Score: {score:.0%})\n\n" | |
| result += "Indicateurs détectés:\n" | |
| result += "- Langage urgent ou pressant\n" | |
| result += "- Demande d'informations sensibles\n" | |
| result += "\nAction recommandée: Terminer l'appel et contacter votre banque" | |
| elif score > 0.4: | |
| result = f"⚠️ RISQUE MODÉRÉ (Score: {score:.0%})\n\n" | |
| result += "Soyez prudent et ne donnez pas d'informations personnelles" | |
| else: | |
| result = f"✅ APPEL NORMAL (Score: {score:.0%})\n\n" | |
| result += "Aucun indicateur de fraude détecté" | |
| self.result_text.insert(tk.END, result) | |
| def load_fraud_example(self): | |
| """Charge un exemple frauduleux""" | |
| example = ("Bonjour, je suis votre conseiller bancaire. Nous avons détecté une activité " | |
| "suspecte. Pour sécuriser votre compte, veuillez confirmer votre code secret IMMÉDIATEMENT.") | |
| self.text_input.delete("1.0", tk.END) | |
| self.text_input.insert("1.0", example) | |
| def load_normal_example(self): | |
| """Charge un exemple normal""" | |
| example = ("Bonjour, je vous appelle pour vous informer que votre carte bancaire " | |
| "arrive à expiration. Souhaitez-vous recevoir la nouvelle par courrier ?") | |
| self.text_input.delete("1.0", tk.END) | |
| self.text_input.insert("1.0", example) | |
| if __name__ == "__main__": | |
| app = Application() | |
| app.mainloop() |