Spaces:
Running
Running
Update utils/functions.py
Browse files- utils/functions.py +23 -22
utils/functions.py
CHANGED
@@ -189,8 +189,8 @@ def get_phone_info(phone_number):
|
|
189 |
"""
|
190 |
try:
|
191 |
parsed_number = phonenumbers.parse(phone_number, None)
|
192 |
-
country = geocoder.description_for_number(parsed_number, 'en') #
|
193 |
-
operator = carrier.name_for_number(parsed_number, 'en')
|
194 |
logging.info(f"Numer {phone_number} - Kraj: {country}, Operator: {operator}.")
|
195 |
return country, operator
|
196 |
except phonenumbers.NumberParseException as e:
|
@@ -212,11 +212,11 @@ def simple_checks(message, language):
|
|
212 |
selected_keywords = scam_keywords.get(language, scam_keywords['English'])
|
213 |
|
214 |
if any(keyword in message.lower() for keyword in selected_keywords):
|
215 |
-
warnings.append("
|
216 |
if re.search(r'http[s]?://', message):
|
217 |
-
warnings.append("
|
218 |
-
if re.search(r'\b(
|
219 |
-
warnings.append("
|
220 |
return warnings
|
221 |
|
222 |
def analyze_message(message, phone_number, additional_info, api_key, language):
|
@@ -225,39 +225,40 @@ def analyze_message(message, phone_number, additional_info, api_key, language):
|
|
225 |
"""
|
226 |
if not api_key:
|
227 |
logging.error("Brak klucza API.")
|
228 |
-
return "
|
229 |
|
230 |
url = "https://api.sambanova.ai/v1/chat/completions"
|
231 |
headers = {
|
232 |
-
"Authorization": f"Bearer {api_key}"
|
|
|
233 |
}
|
234 |
|
235 |
# System prompts w trzech językach
|
236 |
system_prompts = {
|
237 |
'Polish': """
|
238 |
-
|
239 |
|
240 |
<analysis>
|
241 |
-
**
|
242 |
-
-
|
243 |
-
-
|
244 |
-
-
|
245 |
</analysis>
|
246 |
|
247 |
<risk_assessment>
|
248 |
-
**
|
249 |
-
-
|
250 |
-
-
|
251 |
</risk_assessment>
|
252 |
|
253 |
<recommendations>
|
254 |
-
**
|
255 |
-
-
|
256 |
-
-
|
257 |
-
-
|
258 |
</recommendations>
|
259 |
|
260 |
-
|
261 |
""",
|
262 |
'German': """
|
263 |
Du bist ein fortgeschrittener KI-Assistent, spezialisiert auf die Identifizierung gefälschter SMS-Nachrichten. Deine Aufgabe ist es, eine detaillierte Analyse der Nachricht durchzuführen, indem du einen tiefgreifenden Denkprozess nutzt und eine umfassende Bewertung lieferst. Deine Antwort sollte in drei Abschnitte unterteilt sein:
|
@@ -324,7 +325,7 @@ Additional Information:
|
|
324 |
Provide your analysis and conclusions following the guidelines above."""
|
325 |
|
326 |
payload = {
|
327 |
-
"model": "Meta-Llama-3.1-8B-Instruct",
|
328 |
"messages": [
|
329 |
{"role": "system", "content": system_prompt},
|
330 |
{"role": "user", "content": user_prompt}
|
|
|
189 |
"""
|
190 |
try:
|
191 |
parsed_number = phonenumbers.parse(phone_number, None)
|
192 |
+
country = geocoder.description_for_number(parsed_number, 'en') # Możesz zmienić język na 'pl' lub 'de'
|
193 |
+
operator = carrier.name_for_number(parsed_number, 'en') # Możesz zmienić język na 'pl' lub 'de'
|
194 |
logging.info(f"Numer {phone_number} - Kraj: {country}, Operator: {operator}.")
|
195 |
return country, operator
|
196 |
except phonenumbers.NumberParseException as e:
|
|
|
212 |
selected_keywords = scam_keywords.get(language, scam_keywords['English'])
|
213 |
|
214 |
if any(keyword in message.lower() for keyword in selected_keywords):
|
215 |
+
warnings.append("Wiadomość zawiera słowa kluczowe związane z potencjalnym oszustwem.")
|
216 |
if re.search(r'http[s]?://', message):
|
217 |
+
warnings.append("Wiadomość zawiera link.")
|
218 |
+
if re.search(r'\b(podaj|prześlij|udostępnij)\b.*\b(hasło|kod|dane osobowe|numer konta)\b', message.lower()):
|
219 |
+
warnings.append("Wiadomość zawiera prośbę o poufne informacje.")
|
220 |
return warnings
|
221 |
|
222 |
def analyze_message(message, phone_number, additional_info, api_key, language):
|
|
|
225 |
"""
|
226 |
if not api_key:
|
227 |
logging.error("Brak klucza API.")
|
228 |
+
return "Brak klucza API.", "Brak klucza API.", "Brak klucza API."
|
229 |
|
230 |
url = "https://api.sambanova.ai/v1/chat/completions"
|
231 |
headers = {
|
232 |
+
"Authorization": f"Bearer {api_key}",
|
233 |
+
"Content-Type": "application/json"
|
234 |
}
|
235 |
|
236 |
# System prompts w trzech językach
|
237 |
system_prompts = {
|
238 |
'Polish': """
|
239 |
+
Jesteś zaawansowanym asystentem AI specjalizującym się w identyfikacji fałszywych wiadomości SMS. Twoim zadaniem jest przeprowadzenie szczegółowej analizy wiadomości, wykorzystując głęboki proces myślenia i dostarczając kompleksową ocenę. Twoja odpowiedź powinna być podzielona na trzy sekcje:
|
240 |
|
241 |
<analysis>
|
242 |
+
**Analiza Treści Wiadomości:**
|
243 |
+
- Przeprowadź szczegółową analizę treści wiadomości, identyfikując potencjalne czerwone flagi, takie jak błędy językowe, prośby o dane osobowe, pilne prośby o kontakt itp.
|
244 |
+
- Opisz kontekst językowy i kulturowy wiadomości.
|
245 |
+
- Zidentyfikuj wszelkie elementy, które mogą sugerować, że wiadomość jest próbą wyłudzenia informacji lub pieniędzy.
|
246 |
</analysis>
|
247 |
|
248 |
<risk_assessment>
|
249 |
+
**Ocena Ryzyka Oszustwa:**
|
250 |
+
- Na podstawie analizy treści i dostępnych informacji oceń prawdopodobieństwo, że wiadomość jest oszustwem. Użyj skali od 1 do 10, gdzie 1 oznacza bardzo niskie ryzyko, a 10 bardzo wysokie ryzyko.
|
251 |
+
- Wyjaśnij, jakie czynniki wpływają na tę ocenę.
|
252 |
</risk_assessment>
|
253 |
|
254 |
<recommendations>
|
255 |
+
**Zalecenia dla Użytkownika:**
|
256 |
+
- Podaj jasne i konkretne zalecenia dotyczące dalszych kroków, które użytkownik powinien podjąć.
|
257 |
+
- Uwzględnij sugestie dotyczące bezpieczeństwa, takie jak blokowanie nadawcy, zgłaszanie wiadomości do odpowiednich instytucji, czy też ignorowanie wiadomo��ci.
|
258 |
+
- Jeśli to możliwe, zasugeruj dodatkowe środki ostrożności, które użytkownik może podjąć, aby chronić swoje dane osobowe i finansowe.
|
259 |
</recommendations>
|
260 |
|
261 |
+
Twoja odpowiedź powinna być sformatowana dokładnie w powyższy sposób, używając znaczników <analysis>, <risk_assessment> i <recommendations>. Upewnij się, że każda sekcja jest wypełniona kompletnie i szczegółowo.
|
262 |
""",
|
263 |
'German': """
|
264 |
Du bist ein fortgeschrittener KI-Assistent, spezialisiert auf die Identifizierung gefälschter SMS-Nachrichten. Deine Aufgabe ist es, eine detaillierte Analyse der Nachricht durchzuführen, indem du einen tiefgreifenden Denkprozess nutzt und eine umfassende Bewertung lieferst. Deine Antwort sollte in drei Abschnitte unterteilt sein:
|
|
|
325 |
Provide your analysis and conclusions following the guidelines above."""
|
326 |
|
327 |
payload = {
|
328 |
+
"model": "Meta-Llama-3.1-8B-Instruct", # Upewnij się, że to poprawny model API
|
329 |
"messages": [
|
330 |
{"role": "system", "content": system_prompt},
|
331 |
{"role": "user", "content": user_prompt}
|