Spaces:
Sleeping
Sleeping
File size: 1,420 Bytes
3bea97a ca1537a 188192e ca1537a 188192e ca1537a 188192e ca1537a 188192e 947d949 188192e 947d949 3bea97a 730f984 3bea97a 188192e 947d949 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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):
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
# 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 : Comment devenir médecin ?",
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()
|