File size: 2,219 Bytes
7e85729 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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()
|