Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +71 -44
src/streamlit_app.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_gsheets import GSheetsConnection
|
| 3 |
import pandas as pd
|
| 4 |
-
|
| 5 |
import os
|
| 6 |
import json
|
| 7 |
-
import toml
|
| 8 |
|
| 9 |
# 1. CONFIGURATION DE LA PAGE
|
| 10 |
st.set_page_config(
|
|
@@ -14,7 +12,7 @@ st.set_page_config(
|
|
| 14 |
initial_sidebar_state="expanded"
|
| 15 |
)
|
| 16 |
|
| 17 |
-
# 2. INJECTION CSS - DESIGN GOTHAM & SPACE GROTESK
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
| 20 |
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;700&display=swap');
|
|
@@ -33,7 +31,7 @@ st.markdown("""
|
|
| 33 |
}
|
| 34 |
|
| 35 |
/* Boutons de type Palantir Cobalt */
|
| 36 |
-
.stButton>button {
|
| 37 |
background-color: #2B95D6 !important;
|
| 38 |
color: white !important;
|
| 39 |
border-radius: 2px !important;
|
|
@@ -41,6 +39,7 @@ st.markdown("""
|
|
| 41 |
font-weight: 700;
|
| 42 |
text-transform: uppercase;
|
| 43 |
letter-spacing: 1px;
|
|
|
|
| 44 |
}
|
| 45 |
|
| 46 |
/* Inputs et champs */
|
|
@@ -52,61 +51,89 @@ st.markdown("""
|
|
| 52 |
|
| 53 |
/* Titres */
|
| 54 |
h1, h2, h3 {
|
| 55 |
-
font-family: 'Space Grotesk', sans-serif;
|
| 56 |
-
font-weight: 700;
|
| 57 |
-
color: #2B95D6;
|
| 58 |
-
letter-spacing: -1px;
|
| 59 |
}
|
| 60 |
</style>
|
| 61 |
""", unsafe_allow_html=True)
|
| 62 |
|
| 63 |
-
# 3. CONNEXION À L'ONTOLOGIE
|
| 64 |
-
|
| 65 |
-
#
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
else:
|
| 76 |
-
st.error("ERREUR CRITIQUE : Identifiants GSHEETS_CREDENTIALS introuvables.")
|
| 77 |
-
st.stop()
|
| 78 |
|
| 79 |
# 4. FONCTION GÉNÉRATRICE D'ID UNIQUE (ONTOLOGIE)
|
| 80 |
def generate_ontology_id(prefix, sheet_name):
|
|
|
|
|
|
|
| 81 |
try:
|
| 82 |
data = conn.read(worksheet=sheet_name)
|
| 83 |
next_id = len(data) + 1
|
| 84 |
return f"{prefix}-{2025}-{next_id:04d}"
|
| 85 |
except:
|
|
|
|
| 86 |
return f"{prefix}-{2025}-0001"
|
| 87 |
|
| 88 |
-
# 5. INTERFACE PRINCIPALE
|
| 89 |
-
|
| 90 |
-
st.sidebar.
|
| 91 |
-
st.sidebar.
|
|
|
|
| 92 |
|
| 93 |
-
menu = st.sidebar.radio(
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
)
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
st.header("ENTITÉ : NOUVEAU CLIENT")
|
| 110 |
-
new_id = generate_ontology_id("CLI", "Clients_KYC")
|
| 111 |
-
st.subheader(f"ID : {new_id}")
|
| 112 |
-
st.write("Demain, nous coderons le formulaire complet ici.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from streamlit_gsheets import GSheetsConnection
|
| 3 |
import pandas as pd
|
|
|
|
| 4 |
import os
|
| 5 |
import json
|
|
|
|
| 6 |
|
| 7 |
# 1. CONFIGURATION DE LA PAGE
|
| 8 |
st.set_page_config(
|
|
|
|
| 12 |
initial_sidebar_state="expanded"
|
| 13 |
)
|
| 14 |
|
| 15 |
+
# 2. INJECTION CSS - DESIGN GOTHAM (Blueprint Palantir) & SPACE GROTESK
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
| 18 |
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;700&display=swap');
|
|
|
|
| 31 |
}
|
| 32 |
|
| 33 |
/* Boutons de type Palantir Cobalt */
|
| 34 |
+
div.stButton > button:first-child {
|
| 35 |
background-color: #2B95D6 !important;
|
| 36 |
color: white !important;
|
| 37 |
border-radius: 2px !important;
|
|
|
|
| 39 |
font-weight: 700;
|
| 40 |
text-transform: uppercase;
|
| 41 |
letter-spacing: 1px;
|
| 42 |
+
width: 100%;
|
| 43 |
}
|
| 44 |
|
| 45 |
/* Inputs et champs */
|
|
|
|
| 51 |
|
| 52 |
/* Titres */
|
| 53 |
h1, h2, h3 {
|
| 54 |
+
font-family: 'Space Grotesk', sans-serif !important;
|
| 55 |
+
font-weight: 700 !important;
|
| 56 |
+
color: #2B95D6 !important;
|
| 57 |
+
letter-spacing: -1px !important;
|
| 58 |
}
|
| 59 |
</style>
|
| 60 |
""", unsafe_allow_html=True)
|
| 61 |
|
| 62 |
+
# 3. CONNEXION ROBUSTE À L'ONTOLOGIE
|
| 63 |
+
def get_connection():
|
| 64 |
+
# Récupération via variable d'environnement (Secret HF)
|
| 65 |
+
raw_creds = os.environ.get("GSHEETS_JSON")
|
| 66 |
+
|
| 67 |
+
if raw_creds:
|
| 68 |
+
try:
|
| 69 |
+
creds_dict = json.loads(raw_creds)
|
| 70 |
+
# Création de la connexion sans passer par st.secrets
|
| 71 |
+
return st.connection("gsheets", type=GSheetsConnection, credentials=creds_dict)
|
| 72 |
+
except Exception as e:
|
| 73 |
+
st.error(f"Erreur de lecture du JSON : {e}")
|
| 74 |
+
return None
|
| 75 |
+
else:
|
| 76 |
+
st.error("ERREUR : Secret 'GSHEETS_JSON' introuvable. Vérifiez vos paramètres Hugging Face.")
|
| 77 |
+
return None
|
| 78 |
|
| 79 |
+
# Initialisation de la connexion
|
| 80 |
+
conn = get_connection()
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# 4. FONCTION GÉNÉRATRICE D'ID UNIQUE (ONTOLOGIE)
|
| 83 |
def generate_ontology_id(prefix, sheet_name):
|
| 84 |
+
if conn is None:
|
| 85 |
+
return f"{prefix}-ERROR"
|
| 86 |
try:
|
| 87 |
data = conn.read(worksheet=sheet_name)
|
| 88 |
next_id = len(data) + 1
|
| 89 |
return f"{prefix}-{2025}-{next_id:04d}"
|
| 90 |
except:
|
| 91 |
+
# En cas de feuille vide ou inexistante
|
| 92 |
return f"{prefix}-{2025}-0001"
|
| 93 |
|
| 94 |
+
# 5. INTERFACE PRINCIPALE & NAVIGATION
|
| 95 |
+
if conn is not None:
|
| 96 |
+
st.sidebar.title("🔺🔻 VORTEX-FLUX")
|
| 97 |
+
st.sidebar.caption("Jumeau Numérique de Trésorerie")
|
| 98 |
+
st.sidebar.divider()
|
| 99 |
|
| 100 |
+
menu = st.sidebar.radio(
|
| 101 |
+
"NAVIGATION ONTOLOGIQUE",
|
| 102 |
+
["TABLEAU DE BORD", "KYC CLIENTS", "SIMULATION PRÊTS", "FLUX & ANALYTICS"]
|
| 103 |
+
)
|
| 104 |
|
| 105 |
+
if menu == "TABLEAU DE BORD":
|
| 106 |
+
st.header("OBJECT EXPLORER")
|
| 107 |
+
st.success("Liaison établie avec le Jumeau Numérique (Google Sheets).")
|
| 108 |
+
|
| 109 |
+
col1, col2, col3 = st.columns(3)
|
| 110 |
+
col1.metric("CAPITAL DEHORS", "1.2M XOF", "+5%")
|
| 111 |
+
col2.metric("FLUX ATTENDU (J+7)", "450k XOF", "-2%")
|
| 112 |
+
col3.metric("SCORE LIQUIDITÉ", "8.5/10")
|
| 113 |
+
|
| 114 |
+
st.divider()
|
| 115 |
+
st.subheader("Vérification des données (Clients_KYC)")
|
| 116 |
+
try:
|
| 117 |
+
df = conn.read(worksheet="Clients_KYC")
|
| 118 |
+
st.dataframe(df, use_container_width=True)
|
| 119 |
+
except Exception:
|
| 120 |
+
st.info("L'onglet 'Clients_KYC' est prêt mais ne contient pas encore de données.")
|
| 121 |
+
|
| 122 |
+
elif menu == "KYC CLIENTS":
|
| 123 |
+
st.header("ENTITÉ : NOUVEL OBJET CLIENT")
|
| 124 |
+
# Génération de l'ID en temps réel
|
| 125 |
+
new_id = generate_ontology_id("CLI", "Clients_KYC")
|
| 126 |
+
|
| 127 |
+
st.info(f"Création d'un jumeau numérique avec l'identifiant : **{new_id}**")
|
| 128 |
+
st.write("Le formulaire KYC haute fidélité sera implémenté lors de la prochaine étape.")
|
| 129 |
+
|
| 130 |
+
# Les autres menus restent en attente d'implémentation
|
| 131 |
+
elif menu == "SIMULATION PRÊTS":
|
| 132 |
+
st.header("ENGINE : SIMULATION DE PRÊTS")
|
| 133 |
+
st.write("Module de calcul hebdomadaire en cours de configuration.")
|
| 134 |
+
|
| 135 |
+
elif menu == "FLUX & ANALYTICS":
|
| 136 |
+
st.header("TEMPORAL ANALYTICS")
|
| 137 |
+
st.write("Dashboard de prédiction des flux futurs.")
|
| 138 |
|
| 139 |
+
|
|
|
|
|
|
|
|
|
|
|
|