Spaces:
Running
Running
Update pages/Analysis.py
Browse files- pages/Analysis.py +58 -55
pages/Analysis.py
CHANGED
@@ -2,12 +2,13 @@
|
|
2 |
|
3 |
import streamlit as st
|
4 |
from utils.functions import (
|
|
|
5 |
get_phone_info,
|
6 |
simple_checks,
|
7 |
-
|
|
|
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
|
@@ -103,74 +104,77 @@ def show_analysis(language):
|
|
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 |
-
|
109 |
-
|
110 |
-
|
|
|
|
|
|
|
111 |
with st.form("sms_form"):
|
112 |
message = st.text_area(
|
113 |
-
|
114 |
-
placeholder=
|
115 |
height=150
|
116 |
)
|
117 |
phone_number = st.text_input(
|
118 |
-
|
119 |
placeholder="+48123123123"
|
120 |
)
|
121 |
-
|
122 |
-
st.markdown("### " +
|
123 |
frequency = st.selectbox(
|
124 |
-
|
125 |
-
|
126 |
)
|
127 |
last_received = st.selectbox(
|
128 |
-
|
129 |
-
|
130 |
)
|
131 |
confidence_level = st.slider(
|
132 |
-
|
133 |
1, 5, 3,
|
134 |
-
help=
|
135 |
)
|
136 |
unexpected = st.radio(
|
137 |
-
|
138 |
-
|
139 |
)
|
140 |
additional_notes = st.text_area(
|
141 |
-
|
142 |
height=100
|
143 |
)
|
144 |
-
|
145 |
-
submitted = st.form_submit_button(
|
146 |
-
|
147 |
if submitted:
|
148 |
if not message.strip():
|
149 |
-
st.error(
|
150 |
elif not phone_number.strip():
|
151 |
-
st.error(
|
152 |
else:
|
153 |
# Informacje o numerze telefonu
|
154 |
country, operator = get_phone_info(phone_number)
|
155 |
if country and operator:
|
156 |
-
st.write(f"**{
|
157 |
-
st.write(f"**{
|
158 |
else:
|
159 |
-
st.
|
160 |
-
|
161 |
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
162 |
if is_fake_number(phone_number):
|
163 |
-
st.warning(
|
164 |
else:
|
165 |
-
st.info(
|
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}
|
@@ -179,24 +183,24 @@ def show_analysis(language):
|
|
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(
|
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"
|
@@ -210,32 +214,31 @@ def show_analysis(language):
|
|
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(
|
218 |
-
|
219 |
# Zgłoś numer jako oszustwo
|
220 |
if fraud_detected:
|
221 |
-
if st.button(
|
222 |
success = add_fake_number(phone_number)
|
223 |
if success:
|
224 |
-
st.success(
|
225 |
else:
|
226 |
-
st.info(
|
227 |
-
|
228 |
# Wyświetlanie historii analiz
|
229 |
-
st.subheader(
|
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"**{
|
235 |
-
st.write(f"**{
|
236 |
-
st.write(f"**{
|
237 |
-
st.write(f"**{
|
238 |
else:
|
239 |
-
st.info(
|
240 |
-
|
241 |
-
# Usuń blok "if __name__ == '__main__':" z podstron
|
|
|
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 |
import os
|
14 |
import re # Dodany import do obsługi wyrażeń regularnych
|
|
|
104 |
'remember_note': "📌 Remember: Always exercise caution when receiving messages from unknown senders. Do not share confidential information and do not click on suspicious links."
|
105 |
}
|
106 |
}
|
107 |
+
|
108 |
def show_analysis(language):
|
109 |
+
# Pobierz tłumaczenia dla wybranego języka
|
110 |
+
pt = page_translations.get(language, page_translations['Polish'])
|
111 |
+
|
112 |
+
st.header(pt['header'])
|
113 |
+
st.write(pt['content'])
|
114 |
+
|
115 |
with st.form("sms_form"):
|
116 |
message = st.text_area(
|
117 |
+
pt['message_label'],
|
118 |
+
placeholder=pt['message_label'],
|
119 |
height=150
|
120 |
)
|
121 |
phone_number = st.text_input(
|
122 |
+
pt['phone_label'],
|
123 |
placeholder="+48123123123"
|
124 |
)
|
125 |
+
|
126 |
+
st.markdown("### " + pt['frequency_label'])
|
127 |
frequency = st.selectbox(
|
128 |
+
pt['frequency_label'],
|
129 |
+
pt['frequency_options']
|
130 |
)
|
131 |
last_received = st.selectbox(
|
132 |
+
pt['last_received_label'],
|
133 |
+
pt['last_received_options']
|
134 |
)
|
135 |
confidence_level = st.slider(
|
136 |
+
pt['confidence_label'],
|
137 |
1, 5, 3,
|
138 |
+
help=pt['confidence_help']
|
139 |
)
|
140 |
unexpected = st.radio(
|
141 |
+
pt['unexpected_label'],
|
142 |
+
pt['unexpected_options']
|
143 |
)
|
144 |
additional_notes = st.text_area(
|
145 |
+
pt['additional_notes_label'],
|
146 |
height=100
|
147 |
)
|
148 |
+
|
149 |
+
submitted = st.form_submit_button(pt['analyze_button'])
|
150 |
+
|
151 |
if submitted:
|
152 |
if not message.strip():
|
153 |
+
st.error(pt['missing_message'])
|
154 |
elif not phone_number.strip():
|
155 |
+
st.error(pt['missing_phone'])
|
156 |
else:
|
157 |
# Informacje o numerze telefonu
|
158 |
country, operator = get_phone_info(phone_number)
|
159 |
if country and operator:
|
160 |
+
st.write(f"**{'Country' if language == 'English' else ('Kraj' if language == 'Polish' else 'Land')}:** {country}")
|
161 |
+
st.write(f"**{'Operator' if language == 'English' else ('Operator' if language == 'Polish' else 'Betreiber')}:** {operator}")
|
162 |
else:
|
163 |
+
st.error(pt['invalid_phone'])
|
164 |
+
|
165 |
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
166 |
if is_fake_number(phone_number):
|
167 |
+
st.warning(pt['warning_fraud'])
|
168 |
else:
|
169 |
+
st.info(pt['safe_message'])
|
170 |
+
|
171 |
# Przeprowadź proste sprawdzenia heurystyczne
|
172 |
warnings = simple_checks(message)
|
173 |
if warnings:
|
174 |
st.warning("Znaleziono następujące potencjalne czerwone flagi:")
|
175 |
for warn in warnings:
|
176 |
st.write(f"- {warn}")
|
177 |
+
|
178 |
# Zbierz dodatkowe informacje
|
179 |
additional_info = f"""
|
180 |
**How often do you receive messages from this number?** {frequency}
|
|
|
183 |
**Was receiving this message unexpected for you?** {unexpected}
|
184 |
**Additional notes or information:** {additional_notes}
|
185 |
"""
|
186 |
+
|
187 |
# Pobierz klucz API
|
188 |
api_key = os.getenv('SAMBANOVA_API_KEY')
|
189 |
if not api_key:
|
190 |
+
st.error(pt['api_key_missing'])
|
191 |
else:
|
192 |
# Analiza za pomocą modelu AI
|
193 |
with st.spinner("Analizuję wiadomość przy użyciu modelu AI..."):
|
194 |
analysis_text, risk_text, recommendations_text = analyze_message(message, phone_number, additional_info, api_key)
|
195 |
st.subheader("📑 " + ("Message Content Analysis:" if language == 'English' else ("Analiza treści wiadomości:" if language == 'Polish' else "Analyse des Nachrichtentextes:")))
|
196 |
st.markdown(analysis_text)
|
197 |
+
|
198 |
st.subheader("⚠️ " + ("Fraud Risk Assessment:" if language == 'English' else ("Ocena ryzyka oszustwa:" if language == 'Polish' else "Betrugsrisikobewertung:")))
|
199 |
st.markdown(risk_text)
|
200 |
+
|
201 |
st.subheader("✅ " + ("User Recommendations:" if language == 'English' else ("Zalecenia dla użytkownika:" if language == 'Polish' else "Benutzerempfehlungen:")))
|
202 |
st.markdown(recommendations_text)
|
203 |
+
|
204 |
# Aktualizacja statystyk na podstawie oceny ryzyka
|
205 |
try:
|
206 |
# Zakładając, że risk_text zawiera np. "Ryzyko: 7/10"
|
|
|
214 |
fraud_detected = False
|
215 |
except:
|
216 |
fraud_detected = False
|
217 |
+
|
218 |
# Dodanie analizy do historii
|
219 |
add_to_history(message, phone_number, analysis_text, risk_text, recommendations_text)
|
220 |
+
|
221 |
+
st.info(pt['remember_note'])
|
222 |
+
|
223 |
# Zgłoś numer jako oszustwo
|
224 |
if fraud_detected:
|
225 |
+
if st.button(pt['report_button']):
|
226 |
success = add_fake_number(phone_number)
|
227 |
if success:
|
228 |
+
st.success(pt['reported_success'])
|
229 |
else:
|
230 |
+
st.info(pt['reported_exists'])
|
231 |
+
|
232 |
# Wyświetlanie historii analiz
|
233 |
+
st.subheader(pt['history_header'])
|
234 |
history = get_history()
|
235 |
if history:
|
236 |
for entry in reversed(history[-5:]): # Wyświetl ostatnie 5 analiz
|
237 |
with st.expander(f"{entry['timestamp']} - {entry['phone_number']}"):
|
238 |
+
st.write(f"**{'Message' if language == 'English' else ('Wiadomość' if language == 'Polish' else 'Nachricht')}:** {entry['message']}")
|
239 |
+
st.write(f"**{'Analysis' if language == 'English' else ('Analiza' if language == 'Polish' else 'Analyse')}:** {entry['analysis']}")
|
240 |
+
st.write(f"**{'Risk Assessment' if language == 'English' else ('Ocena Ryzyka' if language == 'Polish' else 'Risikobewertung')}:** {entry['risk_assessment']}")
|
241 |
+
st.write(f"**{'Recommendations' if language == 'English' else ('Zalecenia' if language == 'Polish' else 'Empfehlungen')}:** {entry['recommendations']}")
|
242 |
else:
|
243 |
+
st.info(pt['no_history'])
|
244 |
+
|
|