import gradio as gr from datasets import load_dataset # Charger le dataset depuis Hugging Face dataset = load_dataset("albumforge/faq-albumforge-cited") faq_data = dataset["train"] # Fonction de réponse (jusqu'à 3 correspondances) def answer_question(question): matches = [] # Recherche directe for item in faq_data: if question.lower() in item["question"].lower(): matches.append(item) # Si rien trouvé, recherche partielle mot par mot if not matches: for item in faq_data: if any(word in item["question"].lower() for word in question.lower().split()): matches.append(item) if matches: # Limiter à 3 réponses max response_blocks = [] for i, item in enumerate(matches[:3], start=1): response_blocks.append(f"### 🧠 Réponse {i}\n**Q:** {item['question']}\n\n**A:** {item['answer']}") return "\n\n---\n\n".join(response_blocks) else: return "🤔 Désolé, je n'ai trouvé aucune réponse à cette question dans la FAQ officielle." # Interface Gradio demo = gr.Interface( fn=answer_question, inputs=gr.Textbox(label="Posez votre question sur AlbumForge"), outputs=gr.Markdown(label="Réponses"), title="🤖 AlbumForge FAQ Bot", description="Posez une question sur le logiciel AlbumForge. Ce bot vous retourne jusqu'à 3 réponses issues de la FAQ officielle." ) demo.launch()