133 lines
No EOL
5.1 KiB
Python
133 lines
No EOL
5.1 KiB
Python
import streamlit as st
|
|
|
|
from functions_ui import search_cas_inci
|
|
|
|
# Configure page
|
|
st.set_page_config(
|
|
page_title="LMB App",
|
|
page_icon="🔬",
|
|
layout="wide"
|
|
)
|
|
|
|
# Password protection
|
|
def check_password():
|
|
"""Returns `True` if the user had the correct password."""
|
|
|
|
def password_entered():
|
|
"""Checks whether a password entered by the user is correct."""
|
|
if st.session_state["password"] == st.secrets["passwords"]["app_password"]:
|
|
st.session_state["password_correct"] = True
|
|
del st.session_state["password"] # Don't store password
|
|
else:
|
|
st.session_state["password_correct"] = False
|
|
|
|
# First run, show input for password
|
|
if "password_correct" not in st.session_state:
|
|
st.text_input(
|
|
"Password", type="password", on_change=password_entered, key="password"
|
|
)
|
|
return False
|
|
# Password not correct, show input + error
|
|
elif not st.session_state["password_correct"]:
|
|
st.text_input(
|
|
"Password", type="password", on_change=password_entered, key="password"
|
|
)
|
|
st.error("😕 Password incorrect")
|
|
return False
|
|
# Password correct
|
|
else:
|
|
return True
|
|
|
|
if not check_password():
|
|
st.stop()
|
|
|
|
# Define home page function
|
|
def home():
|
|
st.title("LMB App: PIF & Toxicological Data Viewer")
|
|
|
|
# Inizializza session_state per il CAS number se non esiste
|
|
if 'selected_cas' not in st.session_state:
|
|
st.session_state.selected_cas = None
|
|
|
|
# choose between cas or inci
|
|
type = st.radio("Search by:", ("CAS Number", "INCI Name"), index=0, key="search_mode")
|
|
input = st.text_input("Enter input:", "")
|
|
if input:
|
|
st.caption(f"Ricerca per {input}: trovati i seguenti ingredienti.")
|
|
if type == "CAS Number":
|
|
results = search_cas_inci(input, type='cas')
|
|
else:
|
|
results = search_cas_inci(input, type='inci')
|
|
|
|
if results:
|
|
# Crea le stringhe per la selectbox: "CAS - INCI"
|
|
display_options = [f"{cas} - {inci}" for cas, inci in results]
|
|
|
|
# Selectbox con i risultati formattati
|
|
selected_display = st.selectbox("Results", options=[""] + display_options, key="cas_selectbox")
|
|
|
|
# Salva solo il CAS selezionato nel session_state (estrae la parte prima del " - ")
|
|
if selected_display and selected_display != "":
|
|
selected_cas = selected_display.split(" - ")[0]
|
|
if ";" in selected_cas:
|
|
selected_cas = st.selectbox(options=selected_cas.split(";"), label="Multiple CAS found, please select one:")
|
|
elif "/" in selected_cas:
|
|
selected_cas = st.selectbox(options=selected_cas.split("/"), label="Multiple CAS found, please select one:")
|
|
st.session_state.selected_cas = selected_cas
|
|
st.success(f"CAS Number selezionato: {selected_cas}")
|
|
else:
|
|
# Nessun risultato trovato: permetti di usare l'input manuale
|
|
st.warning("Nessun risultato trovato nel database.")
|
|
if st.button("Usa questo CAS Number") and type == "CAS Number":
|
|
st.session_state.selected_cas = input
|
|
st.success(f"CAS Number salvato: {input}")
|
|
else:
|
|
st.info("INCI non trovato, scegli per CAS o modifica l'input.")
|
|
|
|
# Mostra il CAS attualmente selezionato
|
|
if st.session_state.selected_cas:
|
|
st.info(f"CAS Number corrente: {st.session_state.selected_cas}")
|
|
|
|
# Changelog section
|
|
st.divider()
|
|
with st.expander("📝 Registro degli aggiornamenti"):
|
|
# Placeholder for future versions
|
|
st.markdown("""
|
|
### Versione 0.2.0 | 2026-01-15
|
|
- Aggiunta ricerca per nome INCI
|
|
- Possibilità di filtrare per singoli CAS in caso di multipli per stesso INCI
|
|
- Verifica se il link al download esiste prima di generare il PDF
|
|
- Aggiunta pagina per verificare i valori per determinare il DAP (da PubChem)
|
|
- La ricerca per ingrediente su ECHA non va più in errore se almeno uno dei tre dossier esiste
|
|
- Filtrati i dossier ECHA se sono di tipo 'full' e sono di tipo 'Lead' (sempre Active)
|
|
---
|
|
""")
|
|
|
|
st.markdown("""
|
|
### Versione 0.1.0 | 2025-12-18
|
|
- Release iniziale
|
|
- Funzionalità di ricerca per Numero CAS
|
|
- Integrazione con ECHA
|
|
- Integrazione con CosIng
|
|
- Protezione con password
|
|
- Sistema di navigazione multi-pagina
|
|
- Download del PDF ECHA dossier
|
|
- Visualizzazione dati tossicologici ECHA e CosIng
|
|
""")
|
|
|
|
|
|
# Navigation
|
|
home_page = st.Page(home, title="Home", icon="🏠", default=True)
|
|
echa_page = st.Page("pages/echa.py", title="ECHA Database", icon="🧪")
|
|
cosing_page = st.Page("pages/cosing.py", title="CosIng", icon="💄")
|
|
dap_page = st.Page("pages/dap.py", title="DAP", icon="🧬")
|
|
#pubchem_page = st.Page("pages/pubchem.py", title="PubChem", icon="🧬")
|
|
#cir_page = st.Page("pages/cir.py", title="CIR", icon="📊")
|
|
|
|
|
|
pg = st.navigation({
|
|
"Ricerca": [home_page],
|
|
"Database": [echa_page, cosing_page, dap_page]
|
|
})
|
|
|
|
pg.run() |