Spaces:
Sleeping
Sleeping
rafaldembski
commited on
Commit
•
2e9428f
1
Parent(s):
27f4c94
Update utils/functions.py
Browse files- utils/functions.py +18 -12
utils/functions.py
CHANGED
@@ -73,6 +73,13 @@ def is_fake_number(phone_number):
|
|
73 |
logging.info(f"Sprawdzanie numeru {phone_number}: {'znaleziony' if exists else 'nie znaleziony'}.")
|
74 |
return exists
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
def add_to_history(message, phone_number, analysis, risk, recommendations):
|
77 |
"""
|
78 |
Dodaje wpis do historii analiz w pliku history.json.
|
@@ -132,7 +139,7 @@ def get_phone_info(phone_number):
|
|
132 |
return country, operator
|
133 |
except phonenumbers.NumberParseException as e:
|
134 |
logging.error(f"Nie udało się przetworzyć numeru telefonu {phone_number}: {e}")
|
135 |
-
return
|
136 |
|
137 |
def simple_checks(message, language):
|
138 |
"""
|
@@ -150,11 +157,11 @@ def simple_checks(message, language):
|
|
150 |
|
151 |
message_lower = message.lower()
|
152 |
|
153 |
-
if any(keyword in message_lower for keyword in selected_keywords):
|
154 |
warnings.append("Wiadomość zawiera słowa kluczowe związane z potencjalnym oszustwem.")
|
155 |
if re.search(r'http[s]?://', message):
|
156 |
warnings.append("Wiadomość zawiera link.")
|
157 |
-
if re.search(r'\b(podaj|prześlij|udostępnij|sende|übermittle|teile)\b.*\b(hasło|kod|dane osobowe|numer konta|Passwort|Code|persönliche Daten|Kontonummer)\b', message_lower):
|
158 |
warnings.append("Wiadomość zawiera prośbę o poufne informacje.")
|
159 |
return warnings
|
160 |
|
@@ -250,7 +257,7 @@ Your response should be formatted exactly as specified above, using the <analysi
|
|
250 |
"""
|
251 |
}
|
252 |
|
253 |
-
system_prompt = system_prompts.get(language, system_prompts['English']) #
|
254 |
|
255 |
user_prompt = f"""Analyze the following message for potential fraud:
|
256 |
|
@@ -284,15 +291,14 @@ Provide your analysis and conclusions following the guidelines above."""
|
|
284 |
risk_assessment = re.search(r'<risk_assessment>(.*?)</risk_assessment>', ai_response, re.DOTALL)
|
285 |
recommendations = re.search(r'<recommendations>(.*?)</recommendations>', ai_response, re.DOTALL)
|
286 |
|
287 |
-
analysis_text = analysis.group(1).strip() if analysis else "
|
288 |
-
risk_text = risk_assessment.group(1).strip() if risk_assessment else "
|
289 |
-
recommendations_text = recommendations.group(1).strip() if recommendations else "
|
290 |
|
291 |
return analysis_text, risk_text, recommendations_text
|
292 |
else:
|
293 |
-
logging.error(f"API
|
294 |
-
return f"API
|
295 |
except Exception as e:
|
296 |
-
logging.error(f"
|
297 |
-
return f"
|
298 |
-
|
|
|
73 |
logging.info(f"Sprawdzanie numeru {phone_number}: {'znaleziony' if exists else 'nie znaleziony'}.")
|
74 |
return exists
|
75 |
|
76 |
+
def get_fake_numbers():
|
77 |
+
"""
|
78 |
+
Pobiera listę fałszywych numerów z pliku fake_numbers.json.
|
79 |
+
"""
|
80 |
+
fake_numbers = load_json(FAKE_NUMBERS_FILE)
|
81 |
+
return fake_numbers
|
82 |
+
|
83 |
def add_to_history(message, phone_number, analysis, risk, recommendations):
|
84 |
"""
|
85 |
Dodaje wpis do historii analiz w pliku history.json.
|
|
|
139 |
return country, operator
|
140 |
except phonenumbers.NumberParseException as e:
|
141 |
logging.error(f"Nie udało się przetworzyć numeru telefonu {phone_number}: {e}")
|
142 |
+
return "Nieznany", "Nieznany"
|
143 |
|
144 |
def simple_checks(message, language):
|
145 |
"""
|
|
|
157 |
|
158 |
message_lower = message.lower()
|
159 |
|
160 |
+
if any(keyword.lower() in message_lower for keyword in selected_keywords):
|
161 |
warnings.append("Wiadomość zawiera słowa kluczowe związane z potencjalnym oszustwem.")
|
162 |
if re.search(r'http[s]?://', message):
|
163 |
warnings.append("Wiadomość zawiera link.")
|
164 |
+
if re.search(r'\b(podaj|prześlij|udostępnij|sende|übermittle|teile|send|provide|share)\b.*\b(hasło|kod|dane osobowe|numer konta|Passwort|Code|persönliche Daten|Kontonummer|password|code|personal information|account number)\b', message_lower):
|
165 |
warnings.append("Wiadomość zawiera prośbę o poufne informacje.")
|
166 |
return warnings
|
167 |
|
|
|
257 |
"""
|
258 |
}
|
259 |
|
260 |
+
system_prompt = system_prompts.get(language, system_prompts['English']) # Domyślnie angielski, jeśli język nie jest obsługiwany
|
261 |
|
262 |
user_prompt = f"""Analyze the following message for potential fraud:
|
263 |
|
|
|
291 |
risk_assessment = re.search(r'<risk_assessment>(.*?)</risk_assessment>', ai_response, re.DOTALL)
|
292 |
recommendations = re.search(r'<recommendations>(.*?)</recommendations>', ai_response, re.DOTALL)
|
293 |
|
294 |
+
analysis_text = analysis.group(1).strip() if analysis else "Brak analizy."
|
295 |
+
risk_text = risk_assessment.group(1).strip() if risk_assessment else "Brak oceny ryzyka."
|
296 |
+
recommendations_text = recommendations.group(1).strip() if recommendations else "Brak zaleceń."
|
297 |
|
298 |
return analysis_text, risk_text, recommendations_text
|
299 |
else:
|
300 |
+
logging.error(f"Błąd API: {response.status_code} - {response.text}")
|
301 |
+
return f"Błąd API: {response.status_code} - {response.text}", "Błąd analizy.", "Błąd analizy."
|
302 |
except Exception as e:
|
303 |
+
logging.error(f"Błąd połączenia z API: {e}")
|
304 |
+
return f"Błąd połączenia z API: {e}", "Błąd analizy.", "Błąd analizy."
|
|