klydekushy commited on
Commit
243f650
·
verified ·
1 Parent(s): 19ad9ee

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +41 -19
src/streamlit_app.py CHANGED
@@ -5,15 +5,15 @@ from google.oauth2.service_account import Credentials
5
  import os
6
  import json
7
  import sys
 
8
 
9
- # Ajout du chemin pour trouver les modules
10
  sys.path.append(os.path.join(os.path.dirname(__file__), 'modules'))
 
11
 
12
- # IMPORT DU NOUVEAU MODULE
13
  try:
14
  from modules import kyc_form, map_dashboard, loans_engine, ml_dashboard, notifications, ontology_graph, repayments, forecasting, Check_Up_Loans
15
  except ImportError:
16
- # Fallback si l'import direct échoue (structure de dossier simple)
17
  import kyc_form
18
  import map_dashboard
19
  import loans_engine
@@ -24,26 +24,48 @@ except ImportError:
24
  import forecasting
25
  import Check_Up_Loans
26
 
 
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  # ==============================================================================
30
- # 1. CONFIGURATION DU "DIRECT DRIVER" & DESIGN
31
  # ==============================================================================
32
- st.set_page_config(
33
- page_title="Vortex-Flux | Ontology",
34
- page_icon="🔺",
35
- layout="wide",
36
- initial_sidebar_state="expanded"
37
- )
38
-
39
- # Nom exact de votre fichier Google Sheets (Doit être partagé avec l'email du bot)
40
- SHEET_NAME = "Vortex-Flux"
41
-
42
- # Scopes requis pour l'accès Google Drive/Sheets
43
- SCOPES = [
44
- "https://www.googleapis.com/auth/spreadsheets",
45
- "https://www.googleapis.com/auth/drive"
46
- ]
47
 
48
  # ==============================================================================
49
  # 2. INJECTION CSS GOTHAM SURVEILLANCE - STYLE GLOBAL (FINAL)
 
5
  import os
6
  import json
7
  import sys
8
+ import toml
9
 
10
+ # Ajout des chemins
11
  sys.path.append(os.path.join(os.path.dirname(__file__), 'modules'))
12
+ sys.path.append(os.path.join(os.path.dirname(__file__), 'Algorithms'))
13
 
 
14
  try:
15
  from modules import kyc_form, map_dashboard, loans_engine, ml_dashboard, notifications, ontology_graph, repayments, forecasting, Check_Up_Loans
16
  except ImportError:
 
17
  import kyc_form
18
  import map_dashboard
19
  import loans_engine
 
24
  import forecasting
25
  import Check_Up_Loans
26
 
27
+ # 1. CONFIGURATION
28
+ st.set_page_config(page_title="Vortex-Flux | Ontology", page_icon="🔺", layout="wide", initial_sidebar_state="expanded")
29
 
30
+ # --- RECUPERATION ROBUSTE DES SECRETS ---
31
+ SHEET_NAME = "Vortex-Flux"
32
+ SCOPES = ["https://www.googleapis.com/auth/spreadsheets", "https://www.googleapis.com/auth/drive"]
33
+
34
+ @st.cache_resource
35
+ def get_gspread_client():
36
+ creds_dict = None
37
+
38
+ # CAS A : Tu utilises le format [gcp_service_account] (Ton cas actuel)
39
+ if "gcp_service_account" in st.secrets:
40
+ # st.secrets convertit déjà la section TOML en dictionnaire Python
41
+ creds_dict = dict(st.secrets["gcp_service_account"])
42
+
43
+ # CAS B : Tu utilises le format GSHEETS_JSON (String)
44
+ elif "GSHEETS_JSON" in st.secrets:
45
+ try:
46
+ creds_dict = json.loads(st.secrets["GSHEETS_JSON"])
47
+ except: pass
48
+ elif os.environ.get("GSHEETS_JSON"):
49
+ try:
50
+ creds_dict = json.loads(os.environ.get("GSHEETS_JSON"))
51
+ except: pass
52
+
53
+ if not creds_dict:
54
+ st.error("🛑 Credentials Google introuvables (ni [gcp_service_account] ni GSHEETS_JSON).")
55
+ return None
56
+
57
+ try:
58
+ # On crée le client directement depuis le dictionnaire (plus propre que le fichier temp)
59
+ credentials = Credentials.from_service_account_info(creds_dict, scopes=SCOPES)
60
+ client = gspread.authorize(credentials)
61
+ return client
62
+ except Exception as e:
63
+ st.error(f"⚠️ Erreur d'authentification GSpread : {e}")
64
+ return None
65
 
66
  # ==============================================================================
67
+ # LE RESTE DU FICHIER (CSS, FONCTIONS, NAVIGATION) RESTE IDENTIQUE...
68
  # ==============================================================================
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
  # ==============================================================================
71
  # 2. INJECTION CSS GOTHAM SURVEILLANCE - STYLE GLOBAL (FINAL)