Edu_Pilot_g / app.py
Programmes's picture
Upload app.py
3bea97a verified
raw
history blame
1.61 kB
import gradio as gr
from rag_utils import load_faiss_index, get_embedding_model, query_index, nettoyer_context, generate_answer
# Chargement des données
index, documents = load_faiss_index()
embedder = get_embedding_model()
# Fonction pour traiter la question et générer une réponse
def respond(message, history):
try:
context = query_index(message, index, documents, embedder)
cleaned_context = nettoyer_context("\n".join(context))
answer = generate_answer(message, cleaned_context)
history.append((message, answer))
return "", history
except Exception as e:
print("Erreur :", e)
history.append((message, "😓 Le conseiller IA est temporairement indisponible."))
return "", history
# Interface Gradio
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="yellow")) as demo:
gr.Markdown("# 🎓 EduPilot - Chatbot d'Orientation IA")
gr.Markdown("👋 Bonjour ! Je suis **EduPilot**, ton conseiller IA.\n\nPose-moi une question sur ton avenir scolaire, les filières, les écoles ou les métiers qui t'intéressent.")
chatbot = gr.Chatbot(label="Conseiller IA")
state = gr.State([]) # historique du chat
with gr.Row():
msg = gr.Textbox(
placeholder="Exemple : Que faire après un bac pro ?",
show_label=False,
container=True,
scale=8
)
submit = gr.Button("Envoyer", scale=1)
submit.click(respond, [msg, state], [msg, chatbot, state])
msg.submit(respond, [msg, state], [msg, chatbot, state])
demo.launch()