Spaces:
Sleeping
Sleeping
rafaldembski
commited on
Commit
•
ecdab25
1
Parent(s):
ca01798
Update pages/Analysis.py
Browse files- pages/Analysis.py +201 -260
pages/Analysis.py
CHANGED
@@ -2,299 +2,240 @@
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from utils.functions import (
|
5 |
-
analyze_message,
|
6 |
get_phone_info,
|
7 |
simple_checks,
|
8 |
-
|
9 |
-
is_fake_number,
|
10 |
update_stats,
|
11 |
-
add_to_history
|
|
|
12 |
)
|
13 |
import os
|
14 |
import re # Dodany import do obsługi wyrażeń regularnych
|
15 |
|
16 |
-
# Definiowanie tłumaczeń dla tej podstrony
|
17 |
-
page_translations = {
|
18 |
-
'Polish': {
|
19 |
-
'header': "📊 Analiza SMS",
|
20 |
-
'content': "Tutaj znajduje się interfejs do analizy wiadomości SMS. Wprowadź treść wiadomości oraz numer telefonu nadawcy, aby sprawdzić, czy jest ona potencjalnym oszustwem.",
|
21 |
-
'sms_placeholder': "Wprowadź treść SMS...",
|
22 |
-
'phone_placeholder': "Numer telefonu nadawcy (np. +48123123123)",
|
23 |
-
'analyze_button': "Analizuj wiadomość",
|
24 |
-
'result_positive': "Ostrzeżenie: Wiadomość może być oszustwem!",
|
25 |
-
'result_negative': "Wiadomość wydaje się być bezpieczna.",
|
26 |
-
'report_button': "Zgłoś numer jako oszustwo",
|
27 |
-
'history_header': "Historia Analiz",
|
28 |
-
'form_label_message': "Treść wiadomości SMS",
|
29 |
-
'form_label_phone': "Numer telefonu nadawcy",
|
30 |
-
'form_label_frequency': "Jak często otrzymujesz wiadomości od tego numeru?",
|
31 |
-
'form_label_last_received': "Kiedy ostatnio otrzymałeś podobną wiadomość?",
|
32 |
-
'form_label_confidence': "Jak bardzo jesteś pewny, że wiadomość jest autentyczna?",
|
33 |
-
'form_label_unexpected': "Czy otrzymanie tej wiadomości było dla Ciebie niespodziewane?",
|
34 |
-
'form_label_notes': "Dodatkowe uwagi lub informacje (opcjonalnie)",
|
35 |
-
'form_frequency_options': ['Pierwszy raz', 'Sporadycznie', 'Regularnie'],
|
36 |
-
'form_last_received_options': ['Dziś', 'W ciągu ostatniego tygodnia', 'W ciągu ostatniego miesiąca', 'Dłużej'],
|
37 |
-
'form_unexpected_options': ['Tak', 'Nie'],
|
38 |
-
'no_history': "Brak historii analiz.",
|
39 |
-
'info_reminder': "📌 Pamiętaj: zawsze zachowuj ostrożność przy otrzymywaniu wiadomości od nieznanych nadawców. Nie udostępniaj poufnych informacji i nie klikaj w podejrzane linki.",
|
40 |
-
'error_no_api_key': "Brak klucza API. Ustaw zmienną środowiskową SAMBANOVA_API_KEY w ustawieniach aplikacji.",
|
41 |
-
'error_invalid_phone': "Nieprawidłowy numer telefonu.",
|
42 |
-
'warning_no_message': "Proszę wprowadzić treść wiadomości.",
|
43 |
-
'warning_no_phone': "Proszę wprowadzić numer telefonu nadawcy.",
|
44 |
-
'success_reported': "Numer został zgłoszony jako oszustwo.",
|
45 |
-
'info_already_reported': "Numer został już zgłoszony jako oszustwo."
|
46 |
-
},
|
47 |
-
'German': {
|
48 |
-
'header': "📊 SMS-Analyse",
|
49 |
-
'content': "Hier befindet sich die Benutzeroberfläche zur Analyse von SMS-Nachrichten. Geben Sie den Text der Nachricht sowie die Telefonnummer des Absenders ein, um zu überprüfen, ob es sich um einen potenziellen Betrugsversuch handelt.",
|
50 |
-
'sms_placeholder': "Geben Sie den SMS-Inhalt ein...",
|
51 |
-
'phone_placeholder': "Telefonnummer des Absenders (z.B. +49123123123)",
|
52 |
-
'analyze_button': "Nachricht analysieren",
|
53 |
-
'result_positive': "Warnung: Die Nachricht könnte ein Betrug sein!",
|
54 |
-
'result_negative': "Die Nachricht scheint sicher zu sein.",
|
55 |
-
'report_button': "Nummer als Betrug melden",
|
56 |
-
'history_header': "Analyseverlauf",
|
57 |
-
'form_label_message': "SMS-Nachricht Inhalt",
|
58 |
-
'form_label_phone': "Telefonnummer des Absenders",
|
59 |
-
'form_label_frequency': "Wie häufig erhalten Sie Nachrichten von dieser Nummer?",
|
60 |
-
'form_label_last_received': "Wann haben Sie zuletzt eine ähnliche Nachricht erhalten?",
|
61 |
-
'form_label_confidence': "Wie sicher sind Sie, dass die Nachricht authentisch ist?",
|
62 |
-
'form_label_unexpected': "War das Erhalten dieser Nachricht für Sie unerwartet?",
|
63 |
-
'form_label_notes': "Zusätzliche Anmerkungen oder Informationen (optional)",
|
64 |
-
'form_frequency_options': ['Zum ersten Mal', 'Gelegentlich', 'Regelmäßig'],
|
65 |
-
'form_last_received_options': ['Heute', 'In der letzten Woche', 'In den letzten Monaten', 'Länger'],
|
66 |
-
'form_unexpected_options': ['Ja', 'Nein'],
|
67 |
-
'no_history': "Keine Analyseverlauf vorhanden.",
|
68 |
-
'info_reminder': "📌 Erinnerung: Seien Sie immer vorsichtig beim Erhalt von Nachrichten von unbekannten Absendern. Geben Sie keine vertraulichen Informationen preis und klicken Sie nicht auf verdächtige Links.",
|
69 |
-
'error_no_api_key': "Kein API-Schlüssel vorhanden. Setzen Sie die Umgebungsvariable SAMBANOVA_API_KEY in den Anwendungseinstellungen.",
|
70 |
-
'error_invalid_phone': "Ungültige Telefonnummer.",
|
71 |
-
'warning_no_message': "Bitte geben Sie den Nachrichtentext ein.",
|
72 |
-
'warning_no_phone': "Bitte geben Sie die Telefonnummer des Absenders ein.",
|
73 |
-
'success_reported': "Nummer wurde als Betrug gemeldet.",
|
74 |
-
'info_already_reported': "Nummer wurde bereits als Betrug gemeldet."
|
75 |
-
},
|
76 |
-
'English': {
|
77 |
-
'header': "📊 SMS Analysis",
|
78 |
-
'content': "Here is the interface for analyzing SMS messages. Enter the message content and the sender's phone number to check if it is a potential fraud attempt.",
|
79 |
-
'sms_placeholder': "Enter SMS content...",
|
80 |
-
'phone_placeholder': "Sender's phone number (e.g., +123123123123)",
|
81 |
-
'analyze_button': "Analyze Message",
|
82 |
-
'result_positive': "Warning: The message may be a fraud!",
|
83 |
-
'result_negative': "The message appears to be safe.",
|
84 |
-
'report_button': "Report number as fraud",
|
85 |
-
'history_header': "Analysis History",
|
86 |
-
'form_label_message': "SMS Message Content",
|
87 |
-
'form_label_phone': "Sender's Phone Number",
|
88 |
-
'form_label_frequency': "How often do you receive messages from this number?",
|
89 |
-
'form_label_last_received': "When did you last receive a similar message?",
|
90 |
-
'form_label_confidence': "How confident are you that the message is authentic?",
|
91 |
-
'form_label_unexpected': "Was receiving this message unexpected for you?",
|
92 |
-
'form_label_notes': "Additional notes or information (optional)",
|
93 |
-
'form_frequency_options': ['First time', 'Occasionally', 'Regularly'],
|
94 |
-
'form_last_received_options': ['Today', 'Within the last week', 'Within the last month', 'Longer'],
|
95 |
-
'form_unexpected_options': ['Yes', 'No'],
|
96 |
-
'no_history': "No analysis history available.",
|
97 |
-
'info_reminder': "📌 Remember: always exercise caution when receiving messages from unknown senders. Do not share confidential information and do not click on suspicious links.",
|
98 |
-
'error_no_api_key': "No API key available. Set the SAMBANOVA_API_KEY environment variable in the application settings.",
|
99 |
-
'error_invalid_phone': "Invalid phone number.",
|
100 |
-
'warning_no_message': "Please enter the message content.",
|
101 |
-
'warning_no_phone': "Please enter the sender's phone number.",
|
102 |
-
'success_reported': "Number reported as fraud.",
|
103 |
-
'info_already_reported': "Number has already been reported as fraud."
|
104 |
-
}
|
105 |
-
}
|
106 |
-
|
107 |
def show_analysis(language):
|
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 |
-
st.
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
st.write(f"- **Kraj:** {country}")
|
156 |
-
st.write(f"- **Operator:** {operator}")
|
157 |
-
elif language == 'German':
|
158 |
-
st.write(f"**Informationen zur Telefonnummer:**")
|
159 |
-
st.write(f"- **Land:** {country}")
|
160 |
-
st.write(f"- **Anbieter:** {operator}")
|
161 |
-
else:
|
162 |
-
st.write(f"**Phone Number Information:**")
|
163 |
-
st.write(f"- **Country:** {country}")
|
164 |
-
st.write(f"- **Carrier:** {operator}")
|
165 |
else:
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
st.write("
|
|
|
170 |
else:
|
171 |
-
st.write(
|
172 |
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
st.warning("Numer telefonu znajduje się w bazie znanych fałszywych numerów.")
|
177 |
-
elif language == 'German':
|
178 |
-
st.warning("Die Telefonnummer befindet sich in der Datenbank bekannter betrügerischer Nummern.")
|
179 |
else:
|
180 |
-
st.
|
181 |
-
else:
|
182 |
-
if language == 'Polish':
|
183 |
-
st.info("Numer telefonu nie znajduje się w bazie fałszywych numerów.")
|
184 |
-
elif language == 'German':
|
185 |
-
st.info("Die Telefonnummer befindet sich nicht in der Datenbank bekannter betrügerischer Nummern.")
|
186 |
-
else:
|
187 |
-
st.info("The phone number is not in the database of known fake numbers.")
|
188 |
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
if language == 'Polish':
|
193 |
st.warning("Znaleziono następujące potencjalne czerwone flagi:")
|
194 |
-
|
195 |
-
|
196 |
-
else:
|
197 |
-
st.warning("The following potential red flags were found:")
|
198 |
-
for warn in warnings:
|
199 |
-
st.write(f"- {warn}")
|
200 |
|
201 |
-
|
202 |
-
|
203 |
**How often do you receive messages from this number?** {frequency}
|
204 |
**When did you last receive a similar message?** {last_received}
|
205 |
**How confident are you that the message is authentic?** {confidence_level}/5
|
206 |
**Was receiving this message unexpected for you?** {unexpected}
|
207 |
**Additional notes or information:** {additional_notes}
|
208 |
-
|
209 |
-
|
210 |
-
# Pobierz klucz API
|
211 |
-
api_key = os.getenv('SAMBANOVA_API_KEY')
|
212 |
-
if not api_key:
|
213 |
-
st.error(translations['error_no_api_key'])
|
214 |
-
else:
|
215 |
-
# Analiza za pomocą modelu AI
|
216 |
-
with st.spinner(translations['analyze_button'] + "..."):
|
217 |
-
analysis_text, risk_text, recommendations_text = analyze_message(message, phone_number, additional_info, api_key)
|
218 |
-
|
219 |
-
if language == 'Polish':
|
220 |
-
st.subheader("📑 Analiza treści wiadomości:")
|
221 |
-
st.markdown(analysis_text)
|
222 |
-
|
223 |
-
st.subheader("⚠️ Ocena ryzyka oszustwa:")
|
224 |
-
st.markdown(risk_text)
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
st.subheader("✅ Empfehlungen für den Benutzer:")
|
236 |
-
st.markdown(recommendations_text)
|
237 |
-
else:
|
238 |
-
st.subheader("📑 Message Content Analysis:")
|
239 |
st.markdown(analysis_text)
|
240 |
|
241 |
-
st.subheader("⚠️ Fraud Risk Assessment:")
|
242 |
st.markdown(risk_text)
|
243 |
|
244 |
-
st.subheader("✅ Recommendations
|
245 |
st.markdown(recommendations_text)
|
246 |
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
|
|
|
|
257 |
fraud_detected = False
|
258 |
-
except:
|
259 |
-
fraud_detected = False
|
260 |
|
261 |
-
|
262 |
-
|
|
|
|
|
263 |
|
264 |
-
# Zgłoś numer jako oszustwo
|
265 |
if fraud_detected:
|
266 |
-
if st.button(
|
267 |
success = add_fake_number(phone_number)
|
268 |
if success:
|
269 |
-
|
270 |
-
st.success(translations['success_reported'])
|
271 |
-
elif language == 'German':
|
272 |
-
st.success(translations['success_reported'])
|
273 |
-
else:
|
274 |
-
st.success(translations['success_reported'])
|
275 |
else:
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
st.
|
285 |
-
|
286 |
-
st.
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
# Funkcja do sprawdzenia, czy numer jest fałszywy (dodatkowa funkcja)
|
291 |
-
def is_fake_number(phone_number):
|
292 |
-
try:
|
293 |
-
with open('fake_numbers.json', 'r') as f:
|
294 |
-
fake_numbers = json.load(f)
|
295 |
-
return any(entry["phone_number"] == phone_number for entry in fake_numbers)
|
296 |
-
except (json.JSONDecodeError, FileNotFoundError):
|
297 |
-
return False
|
298 |
|
299 |
-
|
300 |
-
|
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from utils.functions import (
|
|
|
5 |
get_phone_info,
|
6 |
simple_checks,
|
7 |
+
analyze_message,
|
|
|
8 |
update_stats,
|
9 |
+
add_to_history,
|
10 |
+
is_fake_number # Dodany import
|
11 |
)
|
12 |
import os
|
13 |
import re # Dodany import do obsługi wyrażeń regularnych
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def show_analysis(language):
|
16 |
+
# Definiowanie tłumaczeń dla tej podstrony
|
17 |
+
page_translations = {
|
18 |
+
'Polish': {
|
19 |
+
'header': "📊 Analiza SMS",
|
20 |
+
'content': """Tutaj znajduje się interfejs do analizy wiadomości SMS. Wprowadź treść wiadomości oraz numer telefonu nadawcy, aby sprawdzić, czy jest ona potencjalnym oszustwem.""",
|
21 |
+
'message_label': "Treść wiadomości SMS",
|
22 |
+
'phone_label': "Numer telefonu nadawcy (w formacie międzynarodowym, np. +48123123123)",
|
23 |
+
'frequency_label': "Jak często otrzymujesz wiadomości od tego numeru?",
|
24 |
+
'frequency_options': ['Pierwszy raz', 'Sporadycznie', 'Regularnie'],
|
25 |
+
'last_received_label': "Kiedy ostatnio otrzymałeś podobną wiadomość?",
|
26 |
+
'last_received_options': ['Dziś', 'W ciągu ostatniego tygodnia', 'W ciągu ostatniego miesiąca', 'Dłużej'],
|
27 |
+
'confidence_label': "Jak bardzo jesteś pewny, że wiadomość jest autentyczna?",
|
28 |
+
'confidence_help': "1: Bardzo mało pewny, 5: Bardzo pewny",
|
29 |
+
'unexpected_label': "Czy otrzymanie tej wiadomości było dla Ciebie niespodziewane?",
|
30 |
+
'unexpected_options': ['Tak', 'Nie'],
|
31 |
+
'additional_notes_label': "Dodatkowe uwagi lub informacje (opcjonalnie)",
|
32 |
+
'analyze_button': "Analizuj wiadomość",
|
33 |
+
'report_button': "Zgłoś numer jako oszustwo",
|
34 |
+
'history_header': "Historia Analiz",
|
35 |
+
'no_history': "Brak historii analiz.",
|
36 |
+
'invalid_phone': "Nieprawidłowy numer telefonu.",
|
37 |
+
'missing_message': "Proszę wprowadzić treść wiadomości.",
|
38 |
+
'missing_phone': "Proszę wprowadzić numer telefonu nadawcy.",
|
39 |
+
'api_error': "Błąd API. Spróbuj ponownie później.",
|
40 |
+
'api_key_missing': "Brak klucza API. Ustaw zmienną środowiskową SAMBANOVA_API_KEY w ustawieniach aplikacji.",
|
41 |
+
'warning_fraud': "Wiadomość może być oszustwem!",
|
42 |
+
'safe_message': "Wiadomość wydaje się być bezpieczna.",
|
43 |
+
'reported_success': "Numer został zgłoszony jako oszustwo.",
|
44 |
+
'reported_exists': "Numer został już zgłoszony jako oszustwo.",
|
45 |
+
'remember_note': "📌 Pamiętaj: zawsze zachowuj ostrożność przy otrzymywaniu wiadomości od nieznanych nadawców. Nie udostępniaj poufnych informacji i nie klikaj w podejrzane linki."
|
46 |
+
},
|
47 |
+
'German': {
|
48 |
+
'header': "📊 SMS-Analyse",
|
49 |
+
'content': """Hier befindet sich die Benutzeroberfläche zur Analyse von SMS-Nachrichten. Geben Sie den Text der Nachricht sowie die Telefonnummer des Absenders ein, um zu überprüfen, ob es sich um einen potenziellen Betrugsversuch handelt.""",
|
50 |
+
'message_label': "SMS-Nachricht Inhalt",
|
51 |
+
'phone_label': "Telefonnummer des Absenders (im internationalen Format, z.B. +49123123123)",
|
52 |
+
'frequency_label': "Wie oft erhalten Sie Nachrichten von dieser Nummer?",
|
53 |
+
'frequency_options': ['Erstes Mal', 'Gelegentlich', 'Regelmäßig'],
|
54 |
+
'last_received_label': "Wann haben Sie zuletzt eine ähnliche Nachricht erhalten?",
|
55 |
+
'last_received_options': ['Heute', 'Innerhalb der letzten Woche', 'Innerhalb des letzten Monats', 'Länger'],
|
56 |
+
'confidence_label': "Wie sicher sind Sie, dass die Nachricht authentisch ist?",
|
57 |
+
'confidence_help': "1: Sehr unsicher, 5: Sehr sicher",
|
58 |
+
'unexpected_label': "War der Empfang dieser Nachricht für Sie unerwartet?",
|
59 |
+
'unexpected_options': ['Ja', 'Nein'],
|
60 |
+
'additional_notes_label': "Zusätzliche Anmerkungen oder Informationen (optional)",
|
61 |
+
'analyze_button': "Nachricht analysieren",
|
62 |
+
'report_button': "Nummer als Betrug melden",
|
63 |
+
'history_header': "Analyseverlauf",
|
64 |
+
'no_history': "Keine Analysehistorie vorhanden.",
|
65 |
+
'invalid_phone': "Ungültige Telefonnummer.",
|
66 |
+
'missing_message': "Bitte geben Sie den Nachrichtentext ein.",
|
67 |
+
'missing_phone': "Bitte geben Sie die Telefonnummer des Absenders ein.",
|
68 |
+
'api_error': "API-Fehler. Bitte versuchen Sie es später erneut.",
|
69 |
+
'api_key_missing': "API-Schlüssel fehlt. Setzen Sie die Umgebungsvariable SAMBANOVA_API_KEY in den App-Einstellungen.",
|
70 |
+
'warning_fraud': "Warnung: Die Nachricht könnte ein Betrug sein!",
|
71 |
+
'safe_message': "Die Nachricht scheint sicher zu sein.",
|
72 |
+
'reported_success': "Nummer wurde als Betrug gemeldet.",
|
73 |
+
'reported_exists': "Nummer wurde bereits als Betrug gemeldet.",
|
74 |
+
'remember_note': "📌 Erinnerung: Seien Sie immer vorsichtig beim Empfang von Nachrichten von unbekannten Absendern. Teilen Sie keine vertraulichen Informationen und klicken Sie nicht auf verdächtige Links."
|
75 |
+
},
|
76 |
+
'English': {
|
77 |
+
'header': "📊 SMS Analysis",
|
78 |
+
'content': """Here is the interface for analyzing SMS messages. Enter the message content and sender's phone number to check if it is a potential fraud attempt.""",
|
79 |
+
'message_label': "SMS Message Content",
|
80 |
+
'phone_label': "Sender's Phone Number (in international format, e.g., +123123123)",
|
81 |
+
'frequency_label': "How often do you receive messages from this number?",
|
82 |
+
'frequency_options': ['First time', 'Occasionally', 'Regularly'],
|
83 |
+
'last_received_label': "When did you last receive a similar message?",
|
84 |
+
'last_received_options': ['Today', 'Within the last week', 'Within the last month', 'Longer'],
|
85 |
+
'confidence_label': "How confident are you that the message is authentic?",
|
86 |
+
'confidence_help': "1: Very Unconfident, 5: Very Confident",
|
87 |
+
'unexpected_label': "Was receiving this message unexpected for you?",
|
88 |
+
'unexpected_options': ['Yes', 'No'],
|
89 |
+
'additional_notes_label': "Additional notes or information (optional)",
|
90 |
+
'analyze_button': "Analyze Message",
|
91 |
+
'report_button': "Report Number as Fraud",
|
92 |
+
'history_header': "Analysis History",
|
93 |
+
'no_history': "No analysis history available.",
|
94 |
+
'invalid_phone': "Invalid phone number.",
|
95 |
+
'missing_message': "Please enter the message content.",
|
96 |
+
'missing_phone': "Please enter the sender's phone number.",
|
97 |
+
'api_error': "API error. Please try again later.",
|
98 |
+
'api_key_missing': "API key missing. Set the SAMBANOVA_API_KEY environment variable in the app settings.",
|
99 |
+
'warning_fraud': "Warning: The message may be a fraud!",
|
100 |
+
'safe_message': "The message appears to be safe.",
|
101 |
+
'reported_success': "Number reported as fraud.",
|
102 |
+
'reported_exists': "Number has already been reported as fraud.",
|
103 |
+
'remember_note': "📌 Remember: Always exercise caution when receiving messages from unknown senders. Do not share confidential information and do not click on suspicious links."
|
104 |
+
}
|
105 |
+
}
|
106 |
|
107 |
+
def show_analysis(language):
|
108 |
+
st.header(page_translations[language]['header'])
|
109 |
+
st.write(page_translations[language]['content'])
|
110 |
+
|
111 |
+
with st.form("sms_form"):
|
112 |
+
message = st.text_area(
|
113 |
+
page_translations[language]['message_label'],
|
114 |
+
placeholder=page_translations[language]['message_label'],
|
115 |
+
height=150
|
116 |
+
)
|
117 |
+
phone_number = st.text_input(
|
118 |
+
page_translations[language]['phone_label'],
|
119 |
+
placeholder="+48123123123"
|
120 |
+
)
|
121 |
+
|
122 |
+
st.markdown("### " + " ".join(page_translations[language]['frequency_label'].split()))
|
123 |
+
frequency = st.selectbox(
|
124 |
+
page_translations[language]['frequency_label'],
|
125 |
+
page_translations[language]['frequency_options']
|
126 |
+
)
|
127 |
+
last_received = st.selectbox(
|
128 |
+
page_translations[language]['last_received_label'],
|
129 |
+
page_translations[language]['last_received_options']
|
130 |
+
)
|
131 |
+
confidence_level = st.slider(
|
132 |
+
page_translations[language]['confidence_label'],
|
133 |
+
1, 5, 3,
|
134 |
+
help=page_translations[language]['confidence_help']
|
135 |
+
)
|
136 |
+
unexpected = st.radio(
|
137 |
+
page_translations[language]['unexpected_label'],
|
138 |
+
page_translations[language]['unexpected_options']
|
139 |
+
)
|
140 |
+
additional_notes = st.text_area(
|
141 |
+
page_translations[language]['additional_notes_label'],
|
142 |
+
height=100
|
143 |
+
)
|
144 |
+
|
145 |
+
submitted = st.form_submit_button(page_translations[language]['analyze_button'])
|
146 |
+
|
147 |
+
if submitted:
|
148 |
+
if not message.strip():
|
149 |
+
st.error(page_translations[language]['missing_message'])
|
150 |
+
elif not phone_number.strip():
|
151 |
+
st.error(page_translations[language]['missing_phone'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
152 |
else:
|
153 |
+
# Informacje o numerze telefonu
|
154 |
+
country, operator = get_phone_info(phone_number)
|
155 |
+
if country and operator:
|
156 |
+
st.write(f"**{ 'Country' if language == 'English' else ('Kraj' if language == 'Polish' else 'Land') }:** {country}")
|
157 |
+
st.write(f"**{ 'Operator' if language == 'English' else ('Operator' if language == 'Polish' else 'Betreiber') }:** {operator}")
|
158 |
else:
|
159 |
+
st.write(page_translations[language]['invalid_phone'])
|
160 |
|
161 |
+
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
162 |
+
if is_fake_number(phone_number):
|
163 |
+
st.warning(page_translations[language]['warning_fraud'])
|
|
|
|
|
|
|
164 |
else:
|
165 |
+
st.info(page_translations[language]['safe_message'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
+
# Przeprowadź proste sprawdzenia heurystyczne
|
168 |
+
warnings = simple_checks(message)
|
169 |
+
if warnings:
|
|
|
170 |
st.warning("Znaleziono następujące potencjalne czerwone flagi:")
|
171 |
+
for warn in warnings:
|
172 |
+
st.write(f"- {warn}")
|
|
|
|
|
|
|
|
|
173 |
|
174 |
+
# Zbierz dodatkowe informacje
|
175 |
+
additional_info = f"""
|
176 |
**How often do you receive messages from this number?** {frequency}
|
177 |
**When did you last receive a similar message?** {last_received}
|
178 |
**How confident are you that the message is authentic?** {confidence_level}/5
|
179 |
**Was receiving this message unexpected for you?** {unexpected}
|
180 |
**Additional notes or information:** {additional_notes}
|
181 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
+
# Pobierz klucz API
|
184 |
+
api_key = os.getenv('SAMBANOVA_API_KEY')
|
185 |
+
if not api_key:
|
186 |
+
st.error(page_translations[language]['api_key_missing'])
|
187 |
+
else:
|
188 |
+
# Analiza za pomocą modelu AI
|
189 |
+
with st.spinner("Analizuję wiadomość przy użyciu modelu AI..."):
|
190 |
+
analysis_text, risk_text, recommendations_text = analyze_message(message, phone_number, additional_info, api_key)
|
191 |
+
st.subheader("📑 " + ("Message Content Analysis:" if language == 'English' else ("Analiza treści wiadomości:" if language == 'Polish' else "Analyse des Nachrichtentextes:")))
|
|
|
|
|
|
|
|
|
192 |
st.markdown(analysis_text)
|
193 |
|
194 |
+
st.subheader("⚠️ " + ("Fraud Risk Assessment:" if language == 'English' else ("Ocena ryzyka oszustwa:" if language == 'Polish' else "Betrugsrisikobewertung:")))
|
195 |
st.markdown(risk_text)
|
196 |
|
197 |
+
st.subheader("✅ " + ("User Recommendations:" if language == 'English' else ("Zalecenia dla użytkownika:" if language == 'Polish' else "Benutzerempfehlungen:")))
|
198 |
st.markdown(recommendations_text)
|
199 |
|
200 |
+
# Aktualizacja statystyk na podstawie oceny ryzyka
|
201 |
+
try:
|
202 |
+
# Zakładając, że risk_text zawiera np. "Ryzyko: 7/10"
|
203 |
+
# Możesz dostosować parsowanie w zależności od formatu
|
204 |
+
match = re.search(r'(\d+)/10', risk_text)
|
205 |
+
if match:
|
206 |
+
risk_score = int(match.group(1))
|
207 |
+
fraud_detected = risk_score >= 7 # Przykładowy próg
|
208 |
+
update_stats(fraud_detected=fraud_detected)
|
209 |
+
else:
|
210 |
+
fraud_detected = False
|
211 |
+
except:
|
212 |
fraud_detected = False
|
|
|
|
|
213 |
|
214 |
+
# Dodanie analizy do historii
|
215 |
+
add_to_history(message, phone_number, analysis_text, risk_text, recommendations_text)
|
216 |
+
|
217 |
+
st.info(page_translations[language]['remember_note'])
|
218 |
|
219 |
+
# Zgłoś numer jako oszustwo
|
220 |
if fraud_detected:
|
221 |
+
if st.button(page_translations[language]['report_button']):
|
222 |
success = add_fake_number(phone_number)
|
223 |
if success:
|
224 |
+
st.success(page_translations[language]['reported_success'])
|
|
|
|
|
|
|
|
|
|
|
225 |
else:
|
226 |
+
st.info(page_translations[language]['reported_exists'])
|
227 |
+
|
228 |
+
# Wyświetlanie historii analiz
|
229 |
+
st.subheader(page_translations[language]['history_header'])
|
230 |
+
history = get_history()
|
231 |
+
if history:
|
232 |
+
for entry in reversed(history[-5:]): # Wyświetl ostatnie 5 analiz
|
233 |
+
with st.expander(f"{entry['timestamp']} - {entry['phone_number']}"):
|
234 |
+
st.write(f"**{ 'Message' if language == 'English' else ('Wiadomość' if language == 'Polish' else 'Nachricht') }:** {entry['message']}")
|
235 |
+
st.write(f"**{ 'Analysis' if language == 'English' else ('Analiza' if language == 'Polish' else 'Analyse') }:** {entry['analysis']}")
|
236 |
+
st.write(f"**{ 'Risk Assessment' if language == 'English' else ('Ocena Ryzyka' if language == 'Polish' else 'Risikobewertung') }:** {entry['risk_assessment']}")
|
237 |
+
st.write(f"**{ 'Recommendations' if language == 'English' else ('Zalecenia' if language == 'Polish' else 'Empfehlungen') }:** {entry['recommendations']}")
|
238 |
+
else:
|
239 |
+
st.info(page_translations[language]['no_history'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
+
# Usuń blok "if __name__ == '__main__':" z podstron
|
|