Spaces:
Running
Running
Commit
·
c8f14dd
1
Parent(s):
edadca0
Confirmation handled successfully !
Browse files
app.py
CHANGED
|
@@ -251,92 +251,77 @@ def is_neo4j_aura_active(retries: int, wait_seconds: int):
|
|
| 251 |
raise RuntimeError("❌ Impossible de réveiller l'instance Neo4j après plusieurs tentatives.")
|
| 252 |
|
| 253 |
def main():
|
| 254 |
-
|
| 255 |
initCarbon()
|
| 256 |
-
|
| 257 |
st.session_state['current_model'] = "mistral-large-latest"
|
| 258 |
|
| 259 |
-
if "tokens_metrics" not in st.session_state or "chat_history" not in st.session_state
|
| 260 |
initialize_conversation()
|
| 261 |
|
| 262 |
-
|
| 263 |
-
# """Point d'entrée de l'application."""
|
| 264 |
-
# Vérifier que les index Pinecone sont prêts
|
| 265 |
if not check_indexes_ready():
|
| 266 |
return
|
| 267 |
|
| 268 |
-
|
| 269 |
st.title("RAG architectures")
|
| 270 |
-
st.markdown(
|
| 271 |
-
"""
|
| 272 |
<style>
|
| 273 |
div[data-testid="stSelectbox"] {
|
| 274 |
width: 200px !important;
|
| 275 |
}
|
| 276 |
</style>
|
| 277 |
-
""",
|
| 278 |
-
unsafe_allow_html=True
|
| 279 |
-
)
|
| 280 |
|
| 281 |
st.markdown("• Basique : *Recherche sémantique*")
|
| 282 |
st.markdown("• Intermédiaire : *Rechercher hybride (sémantique + mots clés)*")
|
| 283 |
st.markdown("• Avancée : *Graph de connaissance + Recherche hybride*")
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
# Init states
|
| 288 |
if "architecture" not in st.session_state:
|
| 289 |
-
st.session_state["architecture"] =
|
| 290 |
-
if "confirmation_needed" not in st.session_state:
|
| 291 |
-
st.session_state["confirmation_needed"] = False
|
| 292 |
-
if "user_response" not in st.session_state:
|
| 293 |
-
st.session_state["user_response"] = None
|
| 294 |
if "selected_arch" not in st.session_state:
|
| 295 |
st.session_state["selected_arch"] = "Basic"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 296 |
|
| 297 |
-
#
|
| 298 |
-
|
| 299 |
"Sélectionnez une architecture RAG :",
|
| 300 |
["Basic", "Intermédiaire", "Avancée"],
|
| 301 |
index=["Basic", "Intermédiaire", "Avancée"].index(st.session_state["selected_arch"]),
|
|
|
|
| 302 |
)
|
| 303 |
|
| 304 |
-
#
|
| 305 |
-
if
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
"Intermédiaire": "B"
|
| 313 |
-
}[selection]
|
| 314 |
-
st.session_state["confirmation_needed"] = False
|
| 315 |
-
st.session_state["user_response"] = None
|
| 316 |
-
st.session_state["selected_arch"] = selection
|
| 317 |
-
|
| 318 |
-
# Popup confirmation si avancée
|
| 319 |
-
if st.session_state["confirmation_needed"]:
|
| 320 |
-
st.toast("⚠️ Attention, ce type de fonctionnement **Avancée** est plus précis, mais consomme plus de carbone. Souhaitez-vous réellement l'utiliser ?")
|
| 321 |
-
st.session_state["user_response"] = st.radio(
|
| 322 |
-
"Confirmez votre choix :",
|
| 323 |
-
options=["Oui", "Non"],
|
| 324 |
-
index=None,
|
| 325 |
-
key="confirm_radio"
|
| 326 |
-
)
|
| 327 |
-
|
| 328 |
-
# Ne rien faire tant que l'utilisateur n'a rien choisi
|
| 329 |
-
if st.session_state["user_response"] == "Oui":
|
| 330 |
st.session_state["architecture"] = "C"
|
| 331 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 332 |
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
st.session_state["user_response"] = None
|
| 338 |
-
st.success("✅ Retour à l'architecture 'Intermédiaire'.")
|
| 339 |
-
st.rerun() # 🔁 Forcer le widget à se recréer
|
| 340 |
|
| 341 |
display_sidebar()
|
| 342 |
|
|
@@ -347,7 +332,7 @@ def main():
|
|
| 347 |
if query:
|
| 348 |
if st.session_state.get("architecture") == "C":
|
| 349 |
#with st.spinner("⏳ Activation de l'instance Neo4j AuraDB en cours..."):
|
| 350 |
-
if is_neo4j_aura_active(
|
| 351 |
st.toast("✅ Neo4j AuraDB est actif.")
|
| 352 |
process_query(query, "C")
|
| 353 |
else:
|
|
|
|
| 251 |
raise RuntimeError("❌ Impossible de réveiller l'instance Neo4j après plusieurs tentatives.")
|
| 252 |
|
| 253 |
def main():
|
|
|
|
| 254 |
initCarbon()
|
|
|
|
| 255 |
st.session_state['current_model'] = "mistral-large-latest"
|
| 256 |
|
| 257 |
+
if "tokens_metrics" not in st.session_state or "chat_history" not in st.session_state:
|
| 258 |
initialize_conversation()
|
| 259 |
|
|
|
|
|
|
|
|
|
|
| 260 |
if not check_indexes_ready():
|
| 261 |
return
|
| 262 |
|
|
|
|
| 263 |
st.title("RAG architectures")
|
| 264 |
+
st.markdown("""
|
|
|
|
| 265 |
<style>
|
| 266 |
div[data-testid="stSelectbox"] {
|
| 267 |
width: 200px !important;
|
| 268 |
}
|
| 269 |
</style>
|
| 270 |
+
""", unsafe_allow_html=True)
|
|
|
|
|
|
|
| 271 |
|
| 272 |
st.markdown("• Basique : *Recherche sémantique*")
|
| 273 |
st.markdown("• Intermédiaire : *Rechercher hybride (sémantique + mots clés)*")
|
| 274 |
st.markdown("• Avancée : *Graph de connaissance + Recherche hybride*")
|
| 275 |
+
|
| 276 |
+
# Initialisation des états
|
|
|
|
|
|
|
| 277 |
if "architecture" not in st.session_state:
|
| 278 |
+
st.session_state["architecture"] = "A"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
if "selected_arch" not in st.session_state:
|
| 280 |
st.session_state["selected_arch"] = "Basic"
|
| 281 |
+
if "first_time_advanced" not in st.session_state:
|
| 282 |
+
st.session_state["first_time_advanced"] = True
|
| 283 |
+
if "advanced_info_shown" not in st.session_state:
|
| 284 |
+
st.session_state["advanced_info_shown"] = False
|
| 285 |
|
| 286 |
+
# Selectbox
|
| 287 |
+
new_selection = st.selectbox(
|
| 288 |
"Sélectionnez une architecture RAG :",
|
| 289 |
["Basic", "Intermédiaire", "Avancée"],
|
| 290 |
index=["Basic", "Intermédiaire", "Avancée"].index(st.session_state["selected_arch"]),
|
| 291 |
+
key="arch_selection"
|
| 292 |
)
|
| 293 |
|
| 294 |
+
# Si la sélection change
|
| 295 |
+
if new_selection != st.session_state["selected_arch"]:
|
| 296 |
+
if new_selection == "Avancée":
|
| 297 |
+
# Message de confirmation pour première fois
|
| 298 |
+
if st.session_state["first_time_advanced"]:
|
| 299 |
+
st.info("⚠️ Attention, ce type de fonctionnement est plus précis mais consomme plus de carbone. Souhaitez-vous réellement l'utiliser ?")
|
| 300 |
+
col1, col2 = st.columns(2)
|
| 301 |
+
if col1.button("✅ Confirmer"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
st.session_state["architecture"] = "C"
|
| 303 |
+
st.session_state["selected_arch"] = "Avancée"
|
| 304 |
+
st.session_state["first_time_advanced"] = False
|
| 305 |
+
st.session_state["advanced_info_shown"] = True
|
| 306 |
+
st.toast("Mode avancé activé")
|
| 307 |
+
st.rerun()
|
| 308 |
+
if col2.button("❌ Annuler"):
|
| 309 |
+
st.session_state["selected_arch"] = "Intermédiaire"
|
| 310 |
+
st.rerun()
|
| 311 |
+
return
|
| 312 |
+
else:
|
| 313 |
+
st.session_state["architecture"] = "C"
|
| 314 |
+
st.session_state["selected_arch"] = "Avancée"
|
| 315 |
+
st.session_state["advanced_info_shown"] = True
|
| 316 |
+
else:
|
| 317 |
+
st.session_state["architecture"] = "A" if new_selection == "Basic" else "B"
|
| 318 |
+
st.session_state["selected_arch"] = new_selection
|
| 319 |
+
st.rerun()
|
| 320 |
|
| 321 |
+
# Affichage du message d'information persistant
|
| 322 |
+
if st.session_state["selected_arch"] == "Avancée" and st.session_state["advanced_info_shown"]:
|
| 323 |
+
st.info("ℹ️ Vous utilisez actuellement l'architecture avancée. Cette option est optimisée pour la précision mais nécessite davantage de ressources.")
|
| 324 |
+
|
|
|
|
|
|
|
|
|
|
| 325 |
|
| 326 |
display_sidebar()
|
| 327 |
|
|
|
|
| 332 |
if query:
|
| 333 |
if st.session_state.get("architecture") == "C":
|
| 334 |
#with st.spinner("⏳ Activation de l'instance Neo4j AuraDB en cours..."):
|
| 335 |
+
if is_neo4j_aura_active(3, 10): # 3 retries, 10 seconds each
|
| 336 |
st.toast("✅ Neo4j AuraDB est actif.")
|
| 337 |
process_query(query, "C")
|
| 338 |
else:
|