Spaces:
Running
Running
Upload main (2).py
Browse files- main (2).py +149 -0
main (2).py
ADDED
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
"""
|
3 |
+
SecureX Light - Version simplifiée du système de détection de fraude
|
4 |
+
"""
|
5 |
+
|
6 |
+
import tkinter as tk
|
7 |
+
from tkinter import scrolledtext, messagebox
|
8 |
+
import re
|
9 |
+
import sqlite3
|
10 |
+
import json
|
11 |
+
from datetime import datetime
|
12 |
+
|
13 |
+
class FraudDetector:
|
14 |
+
def __init__(self):
|
15 |
+
self.patterns = [
|
16 |
+
{
|
17 |
+
"name": "fake_advisor",
|
18 |
+
"keywords": ["conseiller", "banque", "urgent", "code"],
|
19 |
+
"weight": 0.9
|
20 |
+
},
|
21 |
+
{
|
22 |
+
"name": "fake_refund",
|
23 |
+
"keywords": ["remboursement", "argent", "code"],
|
24 |
+
"weight": 0.85
|
25 |
+
},
|
26 |
+
{
|
27 |
+
"name": "credential_theft",
|
28 |
+
"keywords": ["mot de passe", "identifiant", "code secret"],
|
29 |
+
"weight": 0.95
|
30 |
+
}
|
31 |
+
]
|
32 |
+
self.init_database()
|
33 |
+
|
34 |
+
def init_database(self):
|
35 |
+
"""Crée une base de données SQLite simple"""
|
36 |
+
self.conn = sqlite3.connect(":memory:")
|
37 |
+
self.cursor = self.conn.cursor()
|
38 |
+
self.cursor.execute("""
|
39 |
+
CREATE TABLE IF NOT EXISTS calls (
|
40 |
+
id INTEGER PRIMARY KEY,
|
41 |
+
transcript TEXT,
|
42 |
+
score REAL,
|
43 |
+
timestamp DATETIME
|
44 |
+
)
|
45 |
+
""")
|
46 |
+
self.conn.commit()
|
47 |
+
|
48 |
+
def analyze_text(self, text):
|
49 |
+
"""Analyse le texte avec des motifs simples"""
|
50 |
+
if not text:
|
51 |
+
return 0.0
|
52 |
+
|
53 |
+
text_lower = text.lower()
|
54 |
+
total_score = 0.0
|
55 |
+
|
56 |
+
for pattern in self.patterns:
|
57 |
+
matches = sum(1 for word in pattern["keywords"] if word in text_lower)
|
58 |
+
if matches > 0:
|
59 |
+
total_score += (matches / len(pattern["keywords"])) * pattern["weight"]
|
60 |
+
|
61 |
+
# Détection d'urgence
|
62 |
+
urgency_words = ["urgent", "immédiat", "vite", "maintenant"]
|
63 |
+
if sum(1 for word in urgency_words if word in text_lower) >= 2:
|
64 |
+
total_score += 0.2
|
65 |
+
|
66 |
+
return min(total_score, 1.0)
|
67 |
+
|
68 |
+
def save_call(self, text, score):
|
69 |
+
"""Sauvegarde l'appel dans la base"""
|
70 |
+
self.cursor.execute("""
|
71 |
+
INSERT INTO calls (transcript, score, timestamp)
|
72 |
+
VALUES (?, ?, ?)
|
73 |
+
""", (text, score, datetime.now()))
|
74 |
+
self.conn.commit()
|
75 |
+
|
76 |
+
class Application(tk.Tk):
|
77 |
+
def __init__(self):
|
78 |
+
super().__init__()
|
79 |
+
self.title("SecureX Light - Détection de Fraude")
|
80 |
+
self.geometry("700x500")
|
81 |
+
self.detector = FraudDetector()
|
82 |
+
|
83 |
+
self.create_widgets()
|
84 |
+
|
85 |
+
def create_widgets(self):
|
86 |
+
"""Crée l'interface utilisateur"""
|
87 |
+
# Zone de texte pour l'entrée
|
88 |
+
tk.Label(self, text="Transcript d'appel:").pack(pady=5)
|
89 |
+
self.text_input = scrolledtext.ScrolledText(self, height=10)
|
90 |
+
self.text_input.pack(fill=tk.X, padx=10, pady=5)
|
91 |
+
|
92 |
+
# Boutons
|
93 |
+
btn_frame = tk.Frame(self)
|
94 |
+
btn_frame.pack(pady=10)
|
95 |
+
|
96 |
+
tk.Button(btn_frame, text="Analyser", command=self.analyze).pack(side=tk.LEFT, padx=5)
|
97 |
+
tk.Button(btn_frame, text="Exemple Fraude", command=self.load_fraud_example).pack(side=tk.LEFT, padx=5)
|
98 |
+
tk.Button(btn_frame, text="Exemple Normal", command=self.load_normal_example).pack(side=tk.LEFT, padx=5)
|
99 |
+
|
100 |
+
# Résultats
|
101 |
+
tk.Label(self, text="Résultats:").pack(pady=5)
|
102 |
+
self.result_text = scrolledtext.ScrolledText(self, height=10)
|
103 |
+
self.result_text.pack(fill=tk.BOTH, expand=True, padx=10, pady=5)
|
104 |
+
|
105 |
+
def analyze(self):
|
106 |
+
"""Lance l'analyse"""
|
107 |
+
text = self.text_input.get("1.0", tk.END).strip()
|
108 |
+
if not text:
|
109 |
+
messagebox.showwarning("Attention", "Veuillez entrer un texte à analyser")
|
110 |
+
return
|
111 |
+
|
112 |
+
score = self.detector.analyze_text(text)
|
113 |
+
self.detector.save_call(text, score)
|
114 |
+
|
115 |
+
# Affichage des résultats
|
116 |
+
self.result_text.delete("1.0", tk.END)
|
117 |
+
|
118 |
+
if score > 0.7:
|
119 |
+
result = f"🚨 ALERTE FRAUDE (Score: {score:.0%})\n\n"
|
120 |
+
result += "Indicateurs détectés:\n"
|
121 |
+
result += "- Langage urgent ou pressant\n"
|
122 |
+
result += "- Demande d'informations sensibles\n"
|
123 |
+
result += "\nAction recommandée: Terminer l'appel et contacter votre banque"
|
124 |
+
elif score > 0.4:
|
125 |
+
result = f"⚠️ RISQUE MODÉRÉ (Score: {score:.0%})\n\n"
|
126 |
+
result += "Soyez prudent et ne donnez pas d'informations personnelles"
|
127 |
+
else:
|
128 |
+
result = f"✅ APPEL NORMAL (Score: {score:.0%})\n\n"
|
129 |
+
result += "Aucun indicateur de fraude détecté"
|
130 |
+
|
131 |
+
self.result_text.insert(tk.END, result)
|
132 |
+
|
133 |
+
def load_fraud_example(self):
|
134 |
+
"""Charge un exemple frauduleux"""
|
135 |
+
example = ("Bonjour, je suis votre conseiller bancaire. Nous avons détecté une activité "
|
136 |
+
"suspecte. Pour sécuriser votre compte, veuillez confirmer votre code secret IMMÉDIATEMENT.")
|
137 |
+
self.text_input.delete("1.0", tk.END)
|
138 |
+
self.text_input.insert("1.0", example)
|
139 |
+
|
140 |
+
def load_normal_example(self):
|
141 |
+
"""Charge un exemple normal"""
|
142 |
+
example = ("Bonjour, je vous appelle pour vous informer que votre carte bancaire "
|
143 |
+
"arrive à expiration. Souhaitez-vous recevoir la nouvelle par courrier ?")
|
144 |
+
self.text_input.delete("1.0", tk.END)
|
145 |
+
self.text_input.insert("1.0", example)
|
146 |
+
|
147 |
+
if __name__ == "__main__":
|
148 |
+
app = Application()
|
149 |
+
app.mainloop()
|