Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +133 -17
src/streamlit_app.py
CHANGED
|
@@ -8,15 +8,19 @@ import sys
|
|
| 8 |
import time
|
| 9 |
|
| 10 |
# --- CONFIGURATION CHEMINS ---
|
| 11 |
-
# On s'assure que le dossier src/module est accessible pour l'import de AIP.py
|
| 12 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src/module'))
|
| 13 |
|
| 14 |
-
# ---
|
| 15 |
try:
|
| 16 |
import AIP
|
| 17 |
except ImportError:
|
| 18 |
AIP = None
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
# ==============================================================================
|
| 21 |
# 1. FONCTION DE CONFIGURATION ET STYLE (GOTHAM SURVEILLANCE)
|
| 22 |
# ==============================================================================
|
|
@@ -106,21 +110,35 @@ def get_gspread_client():
|
|
| 106 |
return None
|
| 107 |
try:
|
| 108 |
creds_dict = json.loads(raw_json)
|
| 109 |
-
credentials = Credentials.from_service_account_info(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
return gspread.authorize(credentials)
|
| 111 |
except Exception as e:
|
| 112 |
st.error(f"⚠️ Erreur Auth : {e}")
|
| 113 |
return None
|
| 114 |
|
| 115 |
# ==============================================================================
|
| 116 |
-
# 3. APPLICATION PRINCIPALE
|
| 117 |
# ==============================================================================
|
| 118 |
def run_vortex_system():
|
| 119 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
apply_vortex_style()
|
| 121 |
|
| 122 |
client = get_gspread_client()
|
| 123 |
-
SHEET_NAME = "
|
| 124 |
|
| 125 |
if client:
|
| 126 |
# --- SIDEBAR ---
|
|
@@ -129,32 +147,130 @@ def run_vortex_system():
|
|
| 129 |
st.sidebar.divider()
|
| 130 |
|
| 131 |
# Menu de Navigation
|
| 132 |
-
menu = st.sidebar.radio(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
st.sidebar.divider()
|
| 135 |
-
|
|
|
|
| 136 |
for key in list(st.session_state.keys()):
|
| 137 |
del st.session_state[key]
|
| 138 |
st.rerun()
|
| 139 |
|
| 140 |
# --- LOGIQUE D'AFFICHAGE ---
|
| 141 |
-
if menu == "
|
| 142 |
-
st.markdown("<h1>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
if AIP and hasattr(AIP, 'show_terminal'):
|
| 144 |
AIP.show_terminal(client, SHEET_NAME)
|
| 145 |
else:
|
| 146 |
-
st.info("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
st.write("Bienvenue dans l'interface de surveillance. Sélectionnez le terminal AIP pour auditer les données.")
|
| 151 |
|
| 152 |
elif menu == "Indicateurs DQ":
|
| 153 |
-
st.markdown("<h1>QUALITÉ DES DONNÉES (DQ)</h1>", unsafe_allow_html=True)
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
# ==============================================================================
|
| 157 |
-
# 4. POINT D'ENTRÉE STREAMLIT
|
| 158 |
# ==============================================================================
|
| 159 |
if __name__ == "__main__":
|
| 160 |
run_vortex_system()
|
|
|
|
| 8 |
import time
|
| 9 |
|
| 10 |
# --- CONFIGURATION CHEMINS ---
|
|
|
|
| 11 |
sys.path.append(os.path.join(os.path.dirname(__file__), 'src/module'))
|
| 12 |
|
| 13 |
+
# --- IMPORTS MODULES ---
|
| 14 |
try:
|
| 15 |
import AIP
|
| 16 |
except ImportError:
|
| 17 |
AIP = None
|
| 18 |
|
| 19 |
+
try:
|
| 20 |
+
import Data_Exploration
|
| 21 |
+
except ImportError:
|
| 22 |
+
Data_Exploration = None
|
| 23 |
+
|
| 24 |
# ==============================================================================
|
| 25 |
# 1. FONCTION DE CONFIGURATION ET STYLE (GOTHAM SURVEILLANCE)
|
| 26 |
# ==============================================================================
|
|
|
|
| 110 |
return None
|
| 111 |
try:
|
| 112 |
creds_dict = json.loads(raw_json)
|
| 113 |
+
credentials = Credentials.from_service_account_info(
|
| 114 |
+
creds_dict,
|
| 115 |
+
scopes=[
|
| 116 |
+
"https://www.googleapis.com/auth/spreadsheets",
|
| 117 |
+
"https://www.googleapis.com/auth/drive"
|
| 118 |
+
]
|
| 119 |
+
)
|
| 120 |
return gspread.authorize(credentials)
|
| 121 |
except Exception as e:
|
| 122 |
st.error(f"⚠️ Erreur Auth : {e}")
|
| 123 |
return None
|
| 124 |
|
| 125 |
# ==============================================================================
|
| 126 |
+
# 3. APPLICATION PRINCIPALE
|
| 127 |
# ==============================================================================
|
| 128 |
def run_vortex_system():
|
| 129 |
+
# Configuration de la page
|
| 130 |
+
st.set_page_config(
|
| 131 |
+
page_title="VORTEX-FLUX System",
|
| 132 |
+
page_icon="🔺",
|
| 133 |
+
layout="wide",
|
| 134 |
+
initial_sidebar_state="expanded"
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
# Initialisation du style
|
| 138 |
apply_vortex_style()
|
| 139 |
|
| 140 |
client = get_gspread_client()
|
| 141 |
+
SHEET_NAME = "bdd_mvp_faker" # Nom du fichier Google Sheets
|
| 142 |
|
| 143 |
if client:
|
| 144 |
# --- SIDEBAR ---
|
|
|
|
| 147 |
st.sidebar.divider()
|
| 148 |
|
| 149 |
# Menu de Navigation
|
| 150 |
+
menu = st.sidebar.radio(
|
| 151 |
+
"Navigation",
|
| 152 |
+
["Dashboard", "Data Explorer", "AIP Terminal", "Indicateurs DQ"]
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
+
st.sidebar.divider()
|
| 156 |
+
|
| 157 |
+
# Informations système
|
| 158 |
+
st.sidebar.markdown("#### 📡 Statut Système")
|
| 159 |
+
st.sidebar.success("✅ Connexion Google Sheets OK")
|
| 160 |
+
st.sidebar.info(f"📄 Fichier: {SHEET_NAME}")
|
| 161 |
|
| 162 |
st.sidebar.divider()
|
| 163 |
+
|
| 164 |
+
if st.sidebar.button("🔄 Reset System", use_container_width=True):
|
| 165 |
for key in list(st.session_state.keys()):
|
| 166 |
del st.session_state[key]
|
| 167 |
st.rerun()
|
| 168 |
|
| 169 |
# --- LOGIQUE D'AFFICHAGE ---
|
| 170 |
+
if menu == "Dashboard":
|
| 171 |
+
st.markdown("<h1>🎯 CENTRE D'OPÉRATIONS</h1>", unsafe_allow_html=True)
|
| 172 |
+
|
| 173 |
+
col1, col2, col3 = st.columns(3)
|
| 174 |
+
|
| 175 |
+
with col1:
|
| 176 |
+
st.markdown("""
|
| 177 |
+
<div style='background: rgba(88, 166, 255, 0.1); padding: 20px; border-radius: 8px; border-left: 3px solid #58a6ff;'>
|
| 178 |
+
<h3>📊 Data Explorer</h3>
|
| 179 |
+
<p>Analyse exploratoire complète des données hospitalières</p>
|
| 180 |
+
</div>
|
| 181 |
+
""", unsafe_allow_html=True)
|
| 182 |
+
|
| 183 |
+
with col2:
|
| 184 |
+
st.markdown("""
|
| 185 |
+
<div style='background: rgba(0, 230, 118, 0.1); padding: 20px; border-radius: 8px; border-left: 3px solid #00E676;'>
|
| 186 |
+
<h3>🤖 AIP Terminal</h3>
|
| 187 |
+
<p>Intelligence artificielle pour l'analyse prédictive</p>
|
| 188 |
+
</div>
|
| 189 |
+
""", unsafe_allow_html=True)
|
| 190 |
+
|
| 191 |
+
with col3:
|
| 192 |
+
st.markdown("""
|
| 193 |
+
<div style='background: rgba(255, 107, 157, 0.1); padding: 20px; border-radius: 8px; border-left: 3px solid #ff6b9d;'>
|
| 194 |
+
<h3>📈 Indicateurs DQ</h3>
|
| 195 |
+
<p>Suivi de la qualité des données en temps réel</p>
|
| 196 |
+
</div>
|
| 197 |
+
""", unsafe_allow_html=True)
|
| 198 |
+
|
| 199 |
+
st.divider()
|
| 200 |
+
|
| 201 |
+
st.markdown("### 🚀 Démarrage Rapide")
|
| 202 |
+
st.write("""
|
| 203 |
+
1. **Data Explorer** : Explorez vos données avec des analyses interactives
|
| 204 |
+
2. **AIP Terminal** : Posez des questions en langage naturel à l'IA
|
| 205 |
+
3. **Indicateurs DQ** : Surveillez la qualité de vos données
|
| 206 |
+
""")
|
| 207 |
+
|
| 208 |
+
elif menu == "Data Explorer":
|
| 209 |
+
st.markdown("<h1>🔬 DATA EXPLORER</h1>", unsafe_allow_html=True)
|
| 210 |
+
|
| 211 |
+
if Data_Exploration and hasattr(Data_Exploration, 'show_terminal'):
|
| 212 |
+
Data_Exploration.show_terminal(client, SHEET_NAME)
|
| 213 |
+
else:
|
| 214 |
+
st.error("❌ Module Data_Exploration non disponible")
|
| 215 |
+
st.info("Vérifiez que le fichier `src/module/Data_Exploration.py` existe")
|
| 216 |
+
|
| 217 |
+
elif menu == "AIP Terminal":
|
| 218 |
+
st.markdown("<h1>🤖 INTERFACE AIP COMMAND</h1>", unsafe_allow_html=True)
|
| 219 |
+
|
| 220 |
if AIP and hasattr(AIP, 'show_terminal'):
|
| 221 |
AIP.show_terminal(client, SHEET_NAME)
|
| 222 |
else:
|
| 223 |
+
st.info("""
|
| 224 |
+
### Module AIP en Développement
|
| 225 |
+
|
| 226 |
+
**Fonctionnalités Prévues :**
|
| 227 |
+
- Analyse des anomalies (missing_value, outlier, duplicate)
|
| 228 |
+
- Requêtes en langage naturel
|
| 229 |
+
- Calculs automatiques via fonctions
|
| 230 |
|
| 231 |
+
📝 Le module sera bientôt disponible.
|
| 232 |
+
""")
|
|
|
|
| 233 |
|
| 234 |
elif menu == "Indicateurs DQ":
|
| 235 |
+
st.markdown("<h1>📊 QUALITÉ DES DONNÉES (DQ)</h1>", unsafe_allow_html=True)
|
| 236 |
+
|
| 237 |
+
st.info("""
|
| 238 |
+
### Indicateurs de Qualité Surveillés
|
| 239 |
+
|
| 240 |
+
- **Missing Values** : Valeurs manquantes
|
| 241 |
+
- **Time Inconsistency** : Incohérences temporelles
|
| 242 |
+
- **Domain Violation** : Violations de domaine
|
| 243 |
+
- **Outliers** : Valeurs aberrantes
|
| 244 |
+
- **Duplicates** : Doublons
|
| 245 |
+
""")
|
| 246 |
+
|
| 247 |
+
# Vous pouvez ajouter ici une visualisation spécifique des DQ
|
| 248 |
+
if Data_Exploration:
|
| 249 |
+
explorer = Data_Exploration.DataExplorer(client, SHEET_NAME)
|
| 250 |
+
if st.button("📥 Charger et Analyser"):
|
| 251 |
+
with st.spinner("Analyse en cours..."):
|
| 252 |
+
if explorer.load_all_sheets():
|
| 253 |
+
explorer.analyze_data_quality()
|
| 254 |
+
|
| 255 |
+
else:
|
| 256 |
+
st.error("❌ Impossible de se connecter à Google Sheets")
|
| 257 |
+
st.info("""
|
| 258 |
+
**Configuration requise :**
|
| 259 |
+
1. Créez un fichier `.streamlit/secrets.toml`
|
| 260 |
+
2. Ajoutez votre clé JSON Google Sheets :
|
| 261 |
+
```toml
|
| 262 |
+
GSHEETS_JSON = '''
|
| 263 |
+
{
|
| 264 |
+
"type": "service_account",
|
| 265 |
+
"project_id": "...",
|
| 266 |
+
...
|
| 267 |
+
}
|
| 268 |
+
'''
|
| 269 |
+
```
|
| 270 |
+
""")
|
| 271 |
|
| 272 |
# ==============================================================================
|
| 273 |
+
# 4. POINT D'ENTRÉE STREAMLIT
|
| 274 |
# ==============================================================================
|
| 275 |
if __name__ == "__main__":
|
| 276 |
run_vortex_system()
|