| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- 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("""
- <style>
- .stApp {
- background-color: #F2F2F2;
- }
-
- .login-box {
- background-color: white;
- padding: 40px;
- border-radius: 15px;
- box-shadow: 0 4px 20px rgba(0,0,0,0.08);
- border-top: 5px solid #6B0D0D;
- margin-bottom: 20px;
- }
-
- .main-title {
- color: #6B0D0D;
- font-family: 'Helvetica Neue', sans-serif;
- font-weight: 700;
- text-align: center;
- margin-bottom: 30px;
- }
-
- .stat-card {
- background: white;
- padding: 20px;
- border-radius: 12px;
- box-shadow: 0 2px 8px rgba(0,0,0,0.05);
- text-align: center;
- border-bottom: 4px solid #4A4A4A;
- }
- .stat-val {
- font-size: 26px;
- font-weight: bold;
- color: #6B0D0D;
- }
- .stat-label {
- font-size: 14px;
- color: #4A4A4A;
- font-weight: 500;
- }
- /* Style des boutons de navigation du Header */
- /* Style des boutons de navigation du Header */
- .nav-button {
- background-color: #6B0D0D; /* Fond Grenat par défaut */
- color: white !important; /* Texte blanc */
- border: none;
- padding: 8px 18px;
- border-radius: 20px;
- text-decoration: none !important; /* SUPPRIME LE SOULIGNÉ */
- font-size: 14px;
- font-weight: 500;
- transition: 0.3s;
- margin-left: 10px;
- display: inline-block;
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
- }
- .nav-button:hover {
- background-color: #4A0808; /* Grenat plus foncé au survol */
- color: white !important;
- text-decoration: none !important;
- transform: translateY(-1px); /* Petit effet de levier */
- }
- /* Bouton Connexion */
- div.stButton > button:first-child {
- background-color: #6B0D0D !important;
- color: white !important;
- border: none;
- padding: 10px 20px;
- border-radius: 8px;
- transition: 0.3s;
- }
- div.stButton > button:first-child:hover {
- background-color: #4A0808 !important;
- }
- </style>
- """, 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("<h3 style='color:#6B0D0D; margin:0;'>DATALTIST</h3>", unsafe_allow_html=True)
-
- st.markdown("<br>", unsafe_allow_html=True)
- # --- SECTION CENTRALE : LOGIN ---
- left_co, cent_co, last_co = st.columns([1, 5, 1])
-
- with cent_co:
-
- st.markdown('<h2 class="main-title"> Login </h2>', unsafe_allow_html=True)
- st.markdown("<br>", unsafe_allow_html=True)
- st.markdown("<br>", 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("<br>", 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('</div>', unsafe_allow_html=True)
- st.markdown("<br><br>", 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("""<style>.stApp { background-color: #F2F2F2; }</style>""", 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("<h3 style='color:#6B0D0D; margin:0;'>DATALTIST GPT</h3>", unsafe_allow_html=True)
- with h_col2:
- if st.button("🚪 Déconnexion"):
- st.session_state["is_logged_in"] = False
- st.rerun()
-
- st.markdown("<h2 style='color:#4A4A4A; text-align:center;'> Assistant Expert en Actuariat</h2>", 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})
|