Spaces:
Sleeping
Sleeping
rafaldembski
commited on
Commit
•
362c11a
1
Parent(s):
61591ed
Update pages/Analysis.py
Browse files- pages/Analysis.py +124 -5
pages/Analysis.py
CHANGED
@@ -1,26 +1,145 @@
|
|
1 |
# pages/Analysis.py
|
2 |
|
3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Definiowanie tłumaczeń dla tej podstrony
|
6 |
page_translations = {
|
7 |
'Polish': {
|
8 |
'header': "📊 Analiza SMS",
|
9 |
-
'content': """Tutaj znajduje się interfejs do analizy wiadomości SMS. Wprowadź treść wiadomości poniżej, aby sprawdzić, czy jest ona potencjalnym oszustwem."""
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
},
|
11 |
'German': {
|
12 |
'header': "📊 SMS-Analyse",
|
13 |
-
'content': """Hier befindet sich die Benutzeroberfläche zur Analyse von SMS-Nachrichten. Geben Sie den Text der Nachricht unten ein, um zu überprüfen, ob es sich um einen potenziellen Betrugsversuch handelt."""
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
},
|
15 |
'English': {
|
16 |
'header': "📊 SMS Analysis",
|
17 |
-
'content': """Here is the interface for analyzing SMS messages. Enter the content of the message below to check if it is a potential fraud attempt."""
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
}
|
19 |
}
|
20 |
|
21 |
def main(language):
|
22 |
st.header(page_translations[language]['header'])
|
23 |
st.write(page_translations[language]['content'])
|
24 |
-
# Tutaj dodaj resztę funkcjonalności analizy SMS
|
25 |
|
26 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# pages/Analysis.py
|
2 |
|
3 |
import streamlit as st
|
4 |
+
from utils.functions import (
|
5 |
+
analyze_message,
|
6 |
+
get_phone_info,
|
7 |
+
simple_checks,
|
8 |
+
add_fake_number,
|
9 |
+
is_fake_number,
|
10 |
+
update_stats,
|
11 |
+
add_to_history
|
12 |
+
)
|
13 |
|
14 |
# Definiowanie tłumaczeń dla tej podstrony
|
15 |
page_translations = {
|
16 |
'Polish': {
|
17 |
'header': "📊 Analiza SMS",
|
18 |
+
'content': """Tutaj znajduje się interfejs do analizy wiadomości SMS. Wprowadź treść wiadomości poniżej, aby sprawdzić, czy jest ona potencjalnym oszustwem.""",
|
19 |
+
'input_placeholder': "Wprowadź treść SMS...",
|
20 |
+
'analyze_button': "Analizuj",
|
21 |
+
'result_positive': "Ostrzeżenie: Wiadomość może być oszustwem!",
|
22 |
+
'result_negative': "Wiadomość wydaje się być bezpieczna.",
|
23 |
+
'report_button': "Zgłoś numer jako oszustwo",
|
24 |
+
'history_header': "Historia Analiz"
|
25 |
},
|
26 |
'German': {
|
27 |
'header': "📊 SMS-Analyse",
|
28 |
+
'content': """Hier befindet sich die Benutzeroberfläche zur Analyse von SMS-Nachrichten. Geben Sie den Text der Nachricht unten ein, um zu überprüfen, ob es sich um einen potenziellen Betrugsversuch handelt.""",
|
29 |
+
'input_placeholder': "Geben Sie den SMS-Inhalt ein...",
|
30 |
+
'analyze_button': "Analysieren",
|
31 |
+
'result_positive': "Warnung: Die Nachricht könnte ein Betrug sein!",
|
32 |
+
'result_negative': "Die Nachricht scheint sicher zu sein.",
|
33 |
+
'report_button': "Nummer als Betrug melden",
|
34 |
+
'history_header': "Analyseverlauf"
|
35 |
},
|
36 |
'English': {
|
37 |
'header': "📊 SMS Analysis",
|
38 |
+
'content': """Here is the interface for analyzing SMS messages. Enter the content of the message below to check if it is a potential fraud attempt.""",
|
39 |
+
'input_placeholder': "Enter SMS content...",
|
40 |
+
'analyze_button': "Analyze",
|
41 |
+
'result_positive': "Warning: The message may be a fraud!",
|
42 |
+
'result_negative': "The message appears to be safe.",
|
43 |
+
'report_button': "Report number as fraud",
|
44 |
+
'history_header': "Analysis History"
|
45 |
}
|
46 |
}
|
47 |
|
48 |
def main(language):
|
49 |
st.header(page_translations[language]['header'])
|
50 |
st.write(page_translations[language]['content'])
|
|
|
51 |
|
52 |
+
# Input box for SMS content
|
53 |
+
sms_content = st.text_area(
|
54 |
+
label="",
|
55 |
+
placeholder=page_translations[language]['input_placeholder'],
|
56 |
+
height=150
|
57 |
+
)
|
58 |
+
|
59 |
+
# Analyze button
|
60 |
+
if st.button(page_translations[language]['analyze_button']):
|
61 |
+
if sms_content.strip() == "":
|
62 |
+
if language == 'Polish':
|
63 |
+
st.warning("Proszę wprowadzić treść wiadomości.")
|
64 |
+
elif language == 'German':
|
65 |
+
st.warning("Bitte geben Sie den Nachrichtentext ein.")
|
66 |
+
else:
|
67 |
+
st.warning("Please enter the message content.")
|
68 |
+
else:
|
69 |
+
# Pobierz numer telefonu (przykładowy, możesz dodać input)
|
70 |
+
phone_number = st.text_input("Numer telefonu nadawcy:", value="", max_chars=15)
|
71 |
+
|
72 |
+
if phone_number:
|
73 |
+
# Weryfikacja numeru telefonu
|
74 |
+
country, operator = get_phone_info(phone_number)
|
75 |
+
if not country:
|
76 |
+
if language == 'Polish':
|
77 |
+
st.error("Nieprawidłowy numer telefonu.")
|
78 |
+
elif language == 'German':
|
79 |
+
st.error("Ungültige Telefonnummer.")
|
80 |
+
else:
|
81 |
+
st.error("Invalid phone number.")
|
82 |
+
else:
|
83 |
+
# Proste sprawdzenia heurystyczne
|
84 |
+
warnings = simple_checks(sms_content)
|
85 |
+
for warning in warnings:
|
86 |
+
st.warning(warning)
|
87 |
+
|
88 |
+
# Analiza wiadomości
|
89 |
+
additional_info = f"Kraj: {country}, Operator: {operator}"
|
90 |
+
analysis, risk, recommendations = analyze_message(sms_content, phone_number, additional_info, os.getenv('SAMBANOVA_API_KEY'))
|
91 |
+
|
92 |
+
st.subheader("📄 Analiza Treści")
|
93 |
+
st.write(analysis)
|
94 |
+
|
95 |
+
st.subheader("⚖️ Ocena Ryzyka")
|
96 |
+
st.write(risk)
|
97 |
+
|
98 |
+
st.subheader("✅ Zalecenia")
|
99 |
+
st.write(recommendations)
|
100 |
+
|
101 |
+
# Aktualizacja statystyk
|
102 |
+
fraud_detected = "Wiadomość może być oszustwem" in analysis or "Betrug" in analysis or "fraud" in analysis
|
103 |
+
update_stats(fraud_detected=fraud_detected)
|
104 |
+
|
105 |
+
# Dodanie do historii
|
106 |
+
add_to_history(sms_content, phone_number, analysis, risk, recommendations)
|
107 |
+
|
108 |
+
# Zgłoś numer jako oszustwo
|
109 |
+
if fraud_detected:
|
110 |
+
if st.button(page_translations[language]['report_button']):
|
111 |
+
success = add_fake_number(phone_number)
|
112 |
+
if success:
|
113 |
+
if language == 'Polish':
|
114 |
+
st.success("Numer został zgłoszony jako oszustwo.")
|
115 |
+
elif language == 'German':
|
116 |
+
st.success("Nummer wurde als Betrug gemeldet.")
|
117 |
+
else:
|
118 |
+
st.success("Number reported as fraud.")
|
119 |
+
else:
|
120 |
+
if language == 'Polish':
|
121 |
+
st.info("Numer został już zgłoszony jako oszustwo.")
|
122 |
+
elif language == 'German':
|
123 |
+
st.info("Nummer wurde bereits als Betrug gemeldet.")
|
124 |
+
else:
|
125 |
+
st.info("Number has already been reported as fraud.")
|
126 |
+
|
127 |
+
# Wyświetlanie historii analiz
|
128 |
+
st.subheader(page_translations[language]['history_header'])
|
129 |
+
history = get_history()
|
130 |
+
if history:
|
131 |
+
for entry in reversed(history[-5:]): # Wyświetl ostatnie 5 analiz
|
132 |
+
with st.expander(f"{entry['timestamp']} - {entry['phone_number']}"):
|
133 |
+
st.write(f"**Wiadomość:** {entry['message']}")
|
134 |
+
st.write(f"**Analiza:** {entry['analysis']}")
|
135 |
+
st.write(f"**Ocena Ryzyka:** {entry['risk_assessment']}")
|
136 |
+
st.write(f"**Zalecenia:** {entry['recommendations']}")
|
137 |
+
else:
|
138 |
+
if language == 'Polish':
|
139 |
+
st.info("Brak historii analiz.")
|
140 |
+
elif language == 'German':
|
141 |
+
st.info("Keine Analysehistorie vorhanden.")
|
142 |
+
else:
|
143 |
+
st.info("No analysis history available.")
|
144 |
+
|
145 |
+
# Nie dodawaj "if __name__ == '__main__':" w podstronach
|