Spaces:
Running
Running
import streamlit as st | |
from rag_utils import load_faiss_index, get_embedding_model, query_index, generate_answer, nettoyer_context | |
st.set_page_config(page_title="🎓 EduPilot", page_icon="🧠") | |
st.title("🎓 EduPilot ") | |
# Initialiser la mémoire de session | |
if "chat_history" not in st.session_state: | |
st.session_state.chat_history = [] | |
# Chargement des données et du modèle d'embedding | |
index, documents = load_faiss_index() | |
model_embed = get_embedding_model() | |
# Entrée utilisateur | |
user_input = st.text_input("Pose ta question ici :") | |
if user_input: | |
st.session_state.chat_history.append(f"Utilisateur : {user_input}") | |
# Recherche des documents | |
top_docs = query_index(user_input, index, documents, model_embed) | |
context = nettoyer_context("\n".join(top_docs)) | |
# Ajouter les 6 derniers échanges comme contexte | |
history = "\n".join(st.session_state.chat_history[-6:]) | |
full_prompt = f"{history}\n\nContexte :\n{context}" | |
# Génération de la réponse | |
response = generate_answer(user_input, full_prompt) | |
st.session_state.chat_history.append(f"Chatbot : {response}") | |
# Affichage | |
st.markdown("### ✨ Réponse du chatbot :") | |
st.write(response) | |
with st.expander("🧠 Historique de la conversation"): | |
for msg in st.session_state.chat_history: | |
st.write(msg) | |
st.markdown("---") | |
st.caption("🔹 Développé avec ❤️ par EduPilot") |