import streamlit as st import os from dotenv import load_dotenv import uuid # --- CONFIGURATION INITIALE --- st.set_page_config(page_title="Actuariat GPT", page_icon="📊") load_dotenv() # Infos utilisateur user_infos = { "username": "user123", "mdps": "pass123" } def login_page(): # --- INJECTION CSS (GRENAT & GRIS) --- st.markdown(""" """, unsafe_allow_html=True) # --- HEADER / LOGO & NAV --- header_col1, header_col2 = st.columns([2, 8]) with header_col1: try: st.image("logo Dataltist.png", width=130) except: st.markdown("

DATALTIST

", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) # --- SECTION CENTRALE : LOGIN --- left_co, cent_co, last_co = st.columns([1, 5, 1]) with cent_co: st.markdown('

Login

', unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) st.markdown("
", unsafe_allow_html=True) username = st.text_input("👤 Nom d'utilisateur", placeholder="votre email") password = st.text_input("🔑 Mot de passe", type="password", placeholder="••••••••") st.markdown("
", unsafe_allow_html=True) if st.button("Se Connecter", use_container_width=True): if username == user_infos["username"] and password == user_infos["mdps"]: st.session_state["is_logged_in"] = True st.rerun() else : st.error("Identifiants incorrects") st.markdown('', unsafe_allow_html=True) st.markdown("

", unsafe_allow_html=True) # --- INITIALISATION SESSION --- if "is_logged_in" not in st.session_state: st.session_state["is_logged_in"] = False if not st.session_state["is_logged_in"]: login_page() else: # --- INTERFACE CHATBOT --- st.markdown("""""", unsafe_allow_html=True) h_col1, h_col2 = st.columns([3, 1]) with h_col1: try: st.image("logo Dataltist.png", width=100) except: st.markdown("

DATALTIST GPT

", unsafe_allow_html=True) with h_col2: if st.button("🚪 Déconnexion"): st.session_state["is_logged_in"] = False st.rerun() st.markdown("

Assistant Expert en Actuariat

", unsafe_allow_html=True) # Logique Agent @st.cache_resource def get_agent(): from tools import create_agent return create_agent() agent_executor = get_agent() if "messages" not in st.session_state: st.session_state.messages = [] for message in st.session_state.messages: with st.chat_message(message["role"]): st.markdown(message["content"]) if prompt := st.chat_input("Posez votre question actuarielle..."): st.session_state.messages.append({"role": "user", "content": prompt}) with st.chat_message("user"): st.markdown(prompt) with st.chat_message("assistant"): with st.spinner("Analyse des mémoires..."): config = {"configurable": {"thread_id": st.session_state.get("thread_id", str(uuid.uuid4()))}} result = agent_executor.invoke({"messages": [("user", prompt)]}, config) response = result["messages"][-1].content st.markdown(response) st.session_state.messages.append({"role": "assistant", "content": response})