File size: 1,246 Bytes
ca1537a
 
 
 
 
 
188192e
ff6c924
ca1537a
 
 
ff6c924
 
 
 
ca1537a
947d949
ff6c924
 
947d949
 
ff6c924
 
3bea97a
ff6c924
 
3bea97a
ff6c924
188192e
947d949
ff6c924
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
import gradio as gr
from rag_utils import load_faiss_index, get_embedding_model, query_index, nettoyer_context, generate_answer

index, documents = load_faiss_index()
embedder = get_embedding_model()

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)
    except Exception as e:
        answer = f"❌ Erreur : {str(e)}"
    history.append((message, answer))
    return "", history

with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="yellow")) as demo:
    gr.Markdown("# 🎓 EduPilot – Chatbot d'Orientation IA")
    gr.Markdown("👋 Bienvenue ! Je suis **EduPilot**, ton conseiller scolaire IA. Pose-moi une question sur les métiers ou les formations.")

    chatbot = gr.Chatbot(label="Conseiller IA")
    state = gr.State([])
    
    with gr.Row():
        msg = gr.Textbox(placeholder="Exemple : Comment devenir vétérinaire ?", show_label=False, scale=8)
        btn = gr.Button("Envoyer", scale=1)

    btn.click(respond, [msg, state], [msg, chatbot, state])
    msg.submit(respond, [msg, state], [msg, chatbot, state])

demo.launch()