Spaces:
Running
Running
Update pages/Analysis.py
Browse files- pages/Analysis.py +221 -111
pages/Analysis.py
CHANGED
@@ -8,8 +8,7 @@ from utils.functions import (
|
|
8 |
add_fake_number,
|
9 |
is_fake_number,
|
10 |
update_stats,
|
11 |
-
add_to_history
|
12 |
-
get_history
|
13 |
)
|
14 |
import os
|
15 |
import re # Dodany import do obsługi wyrażeń regularnych
|
@@ -18,173 +17,284 @@ import re # Dodany import do obsługi wyrażeń regularnych
|
|
18 |
page_translations = {
|
19 |
'Polish': {
|
20 |
'header': "📊 Analiza SMS",
|
21 |
-
'content': "
|
22 |
-
'
|
23 |
-
'
|
24 |
'analyze_button': "Analizuj wiadomość",
|
25 |
'result_positive': "Ostrzeżenie: Wiadomość może być oszustwem!",
|
26 |
'result_negative': "Wiadomość wydaje się być bezpieczna.",
|
27 |
'report_button': "Zgłoś numer jako oszustwo",
|
28 |
'history_header': "Historia Analiz",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
'no_history': "Brak historii analiz.",
|
30 |
-
'invalid_api_key': "Brak klucza API. Ustaw zmienną środowiskową SAMBANOVA_API_KEY w ustawieniach aplikacji.",
|
31 |
'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.",
|
32 |
-
'
|
33 |
-
'
|
34 |
-
'
|
35 |
-
'
|
|
|
|
|
36 |
},
|
37 |
'German': {
|
38 |
'header': "📊 SMS-Analyse",
|
39 |
-
'content': "
|
40 |
-
'
|
41 |
-
'
|
42 |
'analyze_button': "Nachricht analysieren",
|
43 |
'result_positive': "Warnung: Die Nachricht könnte ein Betrug sein!",
|
44 |
'result_negative': "Die Nachricht scheint sicher zu sein.",
|
45 |
'report_button': "Nummer als Betrug melden",
|
46 |
'history_header': "Analyseverlauf",
|
47 |
-
'
|
48 |
-
'
|
49 |
-
'
|
50 |
-
'
|
51 |
-
'
|
52 |
-
'
|
53 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
},
|
55 |
'English': {
|
56 |
'header': "📊 SMS Analysis",
|
57 |
-
'content': "
|
58 |
-
'
|
59 |
-
'
|
60 |
'analyze_button': "Analyze Message",
|
61 |
'result_positive': "Warning: The message may be a fraud!",
|
62 |
'result_negative': "The message appears to be safe.",
|
63 |
-
'report_button': "Report
|
64 |
'history_header': "Analysis History",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
'no_history': "No analysis history available.",
|
66 |
-
'
|
67 |
-
'
|
68 |
-
'
|
69 |
-
'
|
70 |
-
'
|
71 |
-
'
|
|
|
72 |
}
|
73 |
}
|
74 |
|
75 |
def show_analysis(language):
|
76 |
-
translations = page_translations
|
|
|
77 |
st.header(translations['header'])
|
78 |
st.write(translations['content'])
|
79 |
|
80 |
with st.form("sms_form"):
|
81 |
-
message = st.text_area(
|
82 |
-
phone_number = st.text_input(
|
|
|
|
|
|
|
|
|
83 |
|
84 |
-
st.markdown("### Dodatkowe Informacje")
|
85 |
-
# Dodane pytania
|
86 |
frequency = st.selectbox(
|
87 |
-
|
88 |
-
|
89 |
)
|
90 |
last_received = st.selectbox(
|
91 |
-
|
92 |
-
|
93 |
)
|
94 |
confidence_level = st.slider(
|
95 |
-
|
96 |
1, 5, 3,
|
97 |
-
help="1:
|
|
|
|
|
98 |
)
|
99 |
unexpected = st.radio(
|
100 |
-
|
101 |
-
|
102 |
)
|
103 |
-
additional_notes = st.text_area(
|
104 |
|
105 |
submitted = st.form_submit_button(translations['analyze_button'])
|
106 |
|
107 |
if submitted:
|
108 |
if not message.strip():
|
109 |
-
st.error(translations['
|
110 |
elif not phone_number.strip():
|
111 |
-
st.error(translations['
|
112 |
else:
|
113 |
-
#
|
114 |
country, operator = get_phone_info(phone_number)
|
115 |
-
if
|
116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
else:
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
else:
|
|
|
|
|
|
|
126 |
st.info("Numer telefonu nie znajduje się w bazie fałszywych numerów.")
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
131 |
st.warning("Znaleziono następujące potencjalne czerwone flagi:")
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
# Zbierz dodatkowe informacje
|
136 |
-
additional_info = f"""
|
137 |
-
**Jak często otrzymujesz wiadomości od tego numeru?** {frequency}
|
138 |
-
**Kiedy ostatnio otrzymałeś podobną wiadomość?** {last_received}
|
139 |
-
**Jak bardzo jesteś pewny, że wiadomość jest autentyczna?** {confidence_level}/5
|
140 |
-
**Czy otrzymanie tej wiadomości było dla Ciebie niespodziewane?** {unexpected}
|
141 |
-
**Dodatkowe uwagi lub informacje:** {additional_notes}
|
142 |
-
"""
|
143 |
-
|
144 |
-
# Pobierz klucz API
|
145 |
-
api_key = os.getenv('SAMBANOVA_API_KEY')
|
146 |
-
if not api_key:
|
147 |
-
st.error(translations['invalid_api_key'])
|
148 |
else:
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
st.markdown(analysis_text)
|
154 |
-
|
|
|
155 |
st.markdown(risk_text)
|
|
|
156 |
st.subheader("✅ Zalecenia dla użytkownika:")
|
157 |
st.markdown(recommendations_text)
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
fraud_detected = False
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
st.info(translations['info_reminder'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
#
|
179 |
-
|
180 |
-
history = get_history()
|
181 |
-
if history:
|
182 |
-
for entry in reversed(history[-5:]): # Wyświetl ostatnie 5 analiz
|
183 |
-
with st.expander(f"{entry['timestamp']} - {entry['phone_number']}"):
|
184 |
-
st.write(f"**Wiadomość:** {entry['message']}")
|
185 |
-
st.write(f"**Analiza:** {entry['analysis']}")
|
186 |
-
st.write(f"**Ocena Ryzyka:** {entry['risk_assessment']}")
|
187 |
-
st.write(f"**Zalecenia:** {entry['recommendations']}")
|
188 |
-
else:
|
189 |
-
st.info(translations['no_history'])
|
190 |
-
|
|
|
8 |
add_fake_number,
|
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
|
|
|
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 |
+
translations = page_translations[language]
|
109 |
+
|
110 |
st.header(translations['header'])
|
111 |
st.write(translations['content'])
|
112 |
|
113 |
with st.form("sms_form"):
|
114 |
+
message = st.text_area(translations['form_label_message'], placeholder=translations['sms_placeholder'], height=150)
|
115 |
+
phone_number = st.text_input(translations['form_label_phone'], placeholder=translations['phone_placeholder'], max_chars=15)
|
116 |
+
|
117 |
+
st.markdown("### " + "Dodatkowe Informacje" if language == 'Polish' else
|
118 |
+
"### " + "Zusätzliche Informationen" if language == 'German' else
|
119 |
+
"### " + "Additional Information")
|
120 |
|
|
|
|
|
121 |
frequency = st.selectbox(
|
122 |
+
translations['form_label_frequency'],
|
123 |
+
translations['form_frequency_options']
|
124 |
)
|
125 |
last_received = st.selectbox(
|
126 |
+
translations['form_label_last_received'],
|
127 |
+
translations['form_last_received_options']
|
128 |
)
|
129 |
confidence_level = st.slider(
|
130 |
+
translations['form_label_confidence'],
|
131 |
1, 5, 3,
|
132 |
+
help="1: Very Unconfident, 5: Very Confident" if language == 'English' else
|
133 |
+
"1: Bardzo mało pewny, 5: Bardzo pewny" if language == 'Polish' else
|
134 |
+
"1: Sehr unsicher, 5: Sehr sicher"
|
135 |
)
|
136 |
unexpected = st.radio(
|
137 |
+
translations['form_label_unexpected'],
|
138 |
+
translations['form_unexpected_options']
|
139 |
)
|
140 |
+
additional_notes = st.text_area(translations['form_label_notes'], height=100)
|
141 |
|
142 |
submitted = st.form_submit_button(translations['analyze_button'])
|
143 |
|
144 |
if submitted:
|
145 |
if not message.strip():
|
146 |
+
st.error(translations['warning_no_message'])
|
147 |
elif not phone_number.strip():
|
148 |
+
st.error(translations['warning_no_phone'])
|
149 |
else:
|
150 |
+
# Informacje o numerze telefonu
|
151 |
country, operator = get_phone_info(phone_number)
|
152 |
+
if country and operator:
|
153 |
+
if language == 'Polish':
|
154 |
+
st.write(f"**Informacje o numerze telefonu:**")
|
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 |
+
if language == 'Polish':
|
167 |
+
st.write("Nie udało się uzyskać informacji o numerze telefonu.")
|
168 |
+
elif language == 'German':
|
169 |
+
st.write("Informationen zur Telefonnummer konnten nicht abgerufen werden.")
|
170 |
+
else:
|
171 |
+
st.write("Failed to retrieve phone number information.")
|
172 |
+
|
173 |
+
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
174 |
+
if is_fake_number(phone_number):
|
175 |
+
if language == 'Polish':
|
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.warning("The phone number is in the database of known fake numbers.")
|
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 |
+
# Przeprowadź proste sprawdzenia heurystyczne
|
190 |
+
warnings = simple_checks(message)
|
191 |
+
if warnings:
|
192 |
+
if language == 'Polish':
|
193 |
st.warning("Znaleziono następujące potencjalne czerwone flagi:")
|
194 |
+
elif language == 'German':
|
195 |
+
st.warning("Folgende potenzielle Warnsignale wurden gefunden:")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
else:
|
197 |
+
st.warning("The following potential red flags were found:")
|
198 |
+
for warn in warnings:
|
199 |
+
st.write(f"- {warn}")
|
200 |
+
|
201 |
+
# Zbierz dodatkowe informacje
|
202 |
+
additional_info = f"""
|
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 |
st.subheader("✅ Zalecenia dla użytkownika:")
|
227 |
st.markdown(recommendations_text)
|
228 |
+
elif language == 'German':
|
229 |
+
st.subheader("📑 Analyse des Nachrichtentextes:")
|
230 |
+
st.markdown(analysis_text)
|
231 |
+
|
232 |
+
st.subheader("⚠️ Bewertung des Betrugsrisikos:")
|
233 |
+
st.markdown(risk_text)
|
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 for the User:")
|
245 |
+
st.markdown(recommendations_text)
|
246 |
+
|
247 |
+
# Aktualizacja statystyk na podstawie oceny ryzyka
|
248 |
+
try:
|
249 |
+
# Zakładając, że risk_text zawiera np. "Ryzyko: 7/10" lub podobne w innych językach
|
250 |
+
# Możesz dostosować parsowanie w zależności od formatu
|
251 |
+
match = re.search(r'(\d+)/10', risk_text)
|
252 |
+
if match:
|
253 |
+
risk_score = int(match.group(1))
|
254 |
+
fraud_detected = risk_score >= 7 # Przykładowy próg
|
255 |
+
update_stats(fraud_detected=fraud_detected)
|
256 |
+
else:
|
257 |
fraud_detected = False
|
258 |
+
except:
|
259 |
+
fraud_detected = False
|
260 |
+
|
261 |
+
# Dodanie analizy do historii
|
262 |
+
add_to_history(message, phone_number, analysis_text, risk_text, recommendations_text)
|
263 |
+
|
264 |
+
# Zgłoś numer jako oszustwo, jeśli fraud_detected
|
265 |
+
if fraud_detected:
|
266 |
+
if st.button(translations['report_button']):
|
267 |
+
success = add_fake_number(phone_number)
|
268 |
+
if success:
|
269 |
+
if language == 'Polish':
|
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 |
+
if language == 'Polish':
|
277 |
+
st.info(translations['info_already_reported'])
|
278 |
+
elif language == 'German':
|
279 |
+
st.info(translations['info_already_reported'])
|
280 |
+
else:
|
281 |
+
st.info(translations['info_already_reported'])
|
282 |
+
|
283 |
+
if language == 'Polish':
|
284 |
+
st.info(translations['info_reminder'])
|
285 |
+
elif language == 'German':
|
286 |
+
st.info(translations['info_reminder'])
|
287 |
+
else:
|
288 |
st.info(translations['info_reminder'])
|
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 |
+
# Nie dodawaj "if __name__ == '__main__':" w podstronach
|
300 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|