| import os |
| import sys |
| import streamlit as st |
| from dotenv import load_dotenv |
|
|
| load_dotenv() |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
|
|
| from modules.home import main as semantic_filter_main |
| from modules.cluster_page import main as cluster_main |
|
|
|
|
| def load_credentials() -> dict: |
| users = {} |
| for i in range(1, 4): |
| entry = os.getenv(f"LOGIN_USER{i}", "") |
| if ":" in entry: |
| username, password = entry.split(":", 1) |
| users[username] = password |
| return users |
|
|
|
|
| def show_login() -> None: |
| st.title("π Accesso") |
| with st.form("login_form"): |
| username = st.text_input("Username") |
| password = st.text_input("Password", type="password") |
| submitted = st.form_submit_button("Accedi") |
| if submitted: |
| credentials = load_credentials() |
| if username in credentials and credentials[username] == password: |
| st.session_state.authenticated = True |
| st.session_state.username = username |
| st.rerun() |
| else: |
| st.error("Credenziali non valide. Riprova.") |
|
|
|
|
| def main() -> None: |
| st.sidebar.title("ποΈ PNRR Data Processor") |
| st.sidebar.markdown("---") |
|
|
| page = st.sidebar.radio( |
| "Seleziona una funzione:", |
| ["π Filtro Semantico", "π― Analisi Cluster"], |
| format_func=lambda x: x |
| ) |
|
|
| st.sidebar.markdown("---") |
| st.sidebar.markdown(""" |
| ### βΉοΈ Informazioni |
| |
| **Filtro Semantico**: Filtra i progetti PNRR basandosi su query testuali usando ricerca semantica. |
| |
| **Analisi Cluster**: Raggruppa automaticamente i progetti in cluster tematici per identificare pattern ricorrenti. |
| """) |
|
|
| if st.sidebar.button("πͺ Logout"): |
| st.session_state.authenticated = False |
| st.rerun() |
|
|
| if page == "π Filtro Semantico": |
| semantic_filter_main() |
| elif page == "π― Analisi Cluster": |
| cluster_main() |
|
|
|
|
| if __name__ == "__main__": |
| st.set_page_config( |
| page_title="PNRR Data Processor", |
| page_icon="ποΈ", |
| layout="wide", |
| initial_sidebar_state="expanded" |
| ) |
| if not st.session_state.get("authenticated", False): |
| show_login() |
| else: |
| main() |
|
|