Spaces:
Sleeping
Sleeping
# app.py | |
import streamlit as st | |
from streamlit_option_menu import option_menu | |
from utils.functions import ( | |
get_phone_info, | |
simple_checks, | |
analyze_message, | |
init_stats_file, | |
update_stats, | |
add_to_history, | |
init_fake_numbers_file, | |
is_fake_number, | |
add_fake_number, | |
get_history | |
) | |
import os | |
# 1. Konfiguracja strony - musi by膰 pierwszym poleceniem Streamlit | |
st.set_page_config( | |
page_title="馃摫 Detektor Fa艂szywych Wiadomo艣ci SMS", | |
page_icon="馃摫", | |
layout="wide", | |
initial_sidebar_state="collapsed" # Ukrycie sidebar domy艣lnie | |
) | |
# 2. Inicjalizacja plik贸w | |
init_stats_file() | |
init_fake_numbers_file() | |
# 3. Definiowanie t艂umacze艅 | |
translations = { | |
'Polish': { | |
'menu_analysis_sms': 'Analiza SMS', | |
'menu_about': 'O Projekcie', | |
'menu_education': 'Edukacja', | |
'menu_statistics': 'Statystyki', | |
'menu_contact': 'Kontakt', | |
'language_select': 'Wybierz j臋zyk', | |
'separator': '---', | |
'language_selected': 'Wybrany j臋zyk: ' | |
}, | |
'German': { | |
'menu_analysis_sms': 'SMS-Analyse', | |
'menu_about': '脺ber das Projekt', | |
'menu_education': 'Bildung', | |
'menu_statistics': 'Statistiken', | |
'menu_contact': 'Kontakt', | |
'language_select': 'Sprache ausw盲hlen', | |
'separator': '---', | |
'language_selected': 'Ausgew盲hlte Sprache: ' | |
}, | |
'English': { | |
'menu_analysis_sms': 'SMS Analysis', | |
'menu_about': 'About the Project', | |
'menu_education': 'Education', | |
'menu_statistics': 'Statistics', | |
'menu_contact': 'Contact', | |
'language_select': 'Select Language', | |
'separator': '---', | |
'language_selected': 'Selected Language: ' | |
} | |
} | |
# 4. Language selection with flags in an accordion | |
if 'language' not in st.session_state: | |
st.session_state.language = 'Polish' # Domy艣lny j臋zyk | |
def set_language(lang): | |
st.session_state.language = lang | |
# Wy艣wietlenie wyboru j臋zyka z flagami w akordeonie, domy艣lnie zwini臋tym | |
with st.expander(translations['Polish']['language_select'], expanded=False): | |
col1, col2, col3 = st.columns(3) | |
with col1: | |
if st.button('馃嚨馃嚤'): | |
set_language('Polish') | |
with col2: | |
if st.button('馃嚛馃嚜'): | |
set_language('German') | |
with col3: | |
if st.button('馃嚞馃嚙'): | |
set_language('English') | |
selected_language = st.session_state.language | |
# Wy艣wietlenie wybranego j臋zyka | |
st.markdown(f"**{translations[selected_language]['language_selected']} {selected_language}**") | |
# 5. Fetch translated menu options | |
menu_keys = ['menu_analysis_sms', 'menu_about', 'menu_education', 'menu_statistics', 'menu_contact'] | |
menu_options = [translations[selected_language][key] for key in menu_keys] | |
# 6. Dodanie niestandardowego CSS do wzmocnienia styl贸w menu | |
custom_css = """ | |
<style> | |
/* Stylizacja poziomego menu */ | |
.streamlit-option-menu { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
background-color: var(--st-secondary-background-color); | |
padding: 10px 0; | |
box-shadow: 0 2px 4px rgba(0,0,0,0.1); | |
} | |
/* Pod艣wietlenie wybranej zak艂adki */ | |
.streamlit-option-menu .selected { | |
background-color: #02ab21 !important; /* Zielone t艂o dla wybranej zak艂adki */ | |
color: #ffffff !important; /* Bia艂y tekst dla wybranej zak艂adki */ | |
} | |
/* Efekt hover dla element贸w menu */ | |
.streamlit-option-menu .menu-item:hover { | |
background-color: #02ab21 !important; /* Zielone t艂o podczas hover */ | |
color: #ffffff !important; /* Bia艂y tekst podczas hover */ | |
} | |
/* Zmiana koloru ikon w menu */ | |
.streamlit-option-menu .menu-item .icon { | |
color: inherit !important; | |
} | |
/* Responsywno艣膰 */ | |
@media (max-width: 768px) { | |
.streamlit-option-menu { | |
flex-direction: column; | |
} | |
.streamlit-option-menu .menu-item { | |
margin: 5px 0; | |
width: 100%; | |
text-align: center; | |
} | |
} | |
</style> | |
""" | |
st.markdown(custom_css, unsafe_allow_html=True) | |
# 7. Tworzenie poziomego menu w kontenerze | |
with st.container(): | |
selected = option_menu( | |
menu_title=None, # Brak tytu艂u menu | |
options=menu_options, | |
icons=["shield-check", "info-circle", "book", "bar-chart", "envelope"], | |
menu_icon=None, # Usuni臋cie ikony menu | |
default_index=0, | |
orientation="horizontal", | |
styles={ | |
"container": {"padding": "0!important", "background-color": "transparent"}, | |
"icon": {"color": "inherit", "font-size": "18px"}, | |
"nav-link": { | |
"font-size": "16px", | |
"text-align": "center", | |
"margin": "0px", | |
"--hover-color": "transparent" # Hover kontrolowany przez niestandardowy CSS | |
}, | |
"nav-link-selected": { | |
"background-color": "transparent", # T艂o kontrolowane przez niestandardowy CSS | |
"color": "inherit" | |
}, | |
} | |
) | |
# 8. Dodanie separatora | |
st.markdown("---") # Dodaje poziom膮 lini臋 | |
# 9. Importowanie i wywo艂ywanie modu艂贸w dla ka偶dej zak艂adki z przekazaniem j臋zyka | |
try: | |
if selected == translations[selected_language]['menu_analysis_sms']: | |
from pages.Analysis import show_analysis | |
show_analysis(selected_language) | |
elif selected == translations[selected_language]['menu_about']: | |
from pages.About import main as show_about | |
show_about(selected_language) | |
elif selected == translations[selected_language]['menu_education']: | |
from pages.Education import main as show_education | |
show_education(selected_language) | |
elif selected == translations[selected_language]['menu_statistics']: | |
from pages.Statistics import main as show_statistics | |
show_statistics(selected_language) | |
elif selected == translations[selected_language]['menu_contact']: | |
from pages.Contact import main as show_contact | |
show_contact(selected_language) | |
except ImportError as e: | |
st.error(f"B艂膮d importu: {e}") | |
except TypeError as e: | |
st.error(f"B艂膮d wywo艂ania funkcji: {e}") | |