import streamlit as st import pandas as pd import os def show_gateway_manager(config): # Recupera il percorso dal config.yaml, con fallback # Nota: cerchiamo sia sotto 'infer' che 'collect_train' se necessario csv_path = config.get('infer', {}).get('gateways_csv', '/data/config/gateway.csv') st.subheader("๐ŸŒ Gestione Gateway (gateway.csv)") st.info(f"Percorso file: `{csv_path}`") if not os.path.exists(csv_path): st.error("Il file gateway.csv non รจ stato trovato al percorso specificato.") if st.button("Crea file vuoto"): df_new = pd.DataFrame(columns=["Position", "Floor", "RoomName", "X", "Y", "Z", "GatewayName", "MAC"]) df_new.to_csv(csv_path, sep=';', index=False) st.rerun() return # Caricamento del CSV try: # Usiamo il separatore ';' come da tuo esempio df = pd.read_csv(csv_path, sep=';', dtype=str) except Exception as e: st.error(f"Errore nel caricamento del CSV: {e}") return # Interfaccia di editing st.write("Modifica i dati direttamente nella tabella qui sotto:") edited_df = st.data_editor( df, num_rows="dynamic", use_container_width=True, key="gateway_editor" ) col1, col2 = st.columns([1, 5]) with col1: if st.button("๐Ÿ’พ Salva Gateway"): try: edited_df.to_csv(csv_path, sep=';', index=False) st.success("File gateway.csv salvato con successo!") except Exception as e: st.error(f"Errore durante il salvataggio: {e}") with col2: st.caption("Nota: L'aggiunta di righe avviene cliccando sull'ultima riga vuota della tabella.")