93 lines
No EOL
3.2 KiB
Python
93 lines
No EOL
3.2 KiB
Python
import streamlit as st
|
|
|
|
from functions_ui import search_cas_number
|
|
|
|
# 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
|
|
|
|
input = st.text_input("Enter CAS Number:", "")
|
|
if input:
|
|
st.caption(f"Ricerca per {input}: trovati i seguenti ingredienti.")
|
|
results = search_cas_number(input)
|
|
|
|
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]
|
|
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"):
|
|
st.session_state.selected_cas = input
|
|
st.success(f"CAS Number salvato: {input}")
|
|
|
|
# Mostra il CAS attualmente selezionato
|
|
if st.session_state.selected_cas:
|
|
st.info(f"CAS Number corrente: {st.session_state.selected_cas}")
|
|
|
|
# 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="💄")
|
|
#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]
|
|
})
|
|
|
|
pg.run() |