klydekushy commited on
Commit
8e2cc26
·
verified ·
1 Parent(s): 6ea973b

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 (GOOGLE SHEETS)
64
-
65
- # Tentative de récupération des credentials
66
- creds = None
67
- if "GSHEETS_CREDENTIALS" in st.secrets:
68
- creds = st.secrets["GSHEETS_CREDENTIALS"]
69
- elif "GSHEETS_CREDENTIALS" in os.environ:
70
- # Si c'est stocké comme une chaîne de caractères dans l'OS
71
- creds = toml.loads(os.environ["GSHEETS_CREDENTIALS"])
 
 
 
 
 
 
 
72
 
73
- if creds:
74
- conn = st.connection("gsheets", type=GSheetsConnection, credentials=creds)
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
- st.sidebar.title("🌀 VORTEX-FLUX")
90
- st.sidebar.caption("Jumeau Numérique de Trésorerie")
91
- st.sidebar.divider()
 
92
 
93
- menu = st.sidebar.radio(
94
- "NAVIGATION",
95
- ["TABLEAU DE BORD", "KYC CLIENTS", "SIMULATION PRÊTS", "FLUX & ANALYTICS"]
96
- )
97
 
98
- # CONTENU TEMPORAIRE POUR TESTER LE DESIGN
99
- if menu == "TABLEAU DE BORD":
100
- st.header("OBJECT EXPLORER")
101
- col1, col2, col3 = st.columns(3)
102
- col1.metric("CAPITAL DEHORS", "1.2M XOF", "+5%")
103
- col2.metric("FLUX ATTENDU (J+7)", "450k XOF", "-2%")
104
- col3.metric("SCORE LIQUIDITÉ", "8.5/10")
105
-
106
- st.info("Système Vortex-Flux prêt pour l'ontologie.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
- elif menu == "KYC CLIENTS":
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
+