import gradio as gr from data import coefficients_C, coefficients_D, filieres, students from utils import ( get_student_by_id, calculer_moyennes, calculer_scores_selection, selectionner_meilleures_matieres, compter_occurrences_meilleures_matieres, selectionner_top_matieres, proposer_filieres ) def analyser_etudiant(student_id): # Vérifier si l'étudiant existe student = get_student_by_id(students, student_id) if not student: return ["Étudiant introuvable"] + ["N/A"] * 14 # Retourner des valeurs par défaut pour chaque champ # Définir les coefficients et les biais coefficients = coefficients_C if student.serie == "C" else coefficients_D biais = { "Mathématiques": 5, "Physique-Chimie": 4, "Informatique": 3, "Français": 2, "Philosophie": 1, "Anglais": 2 } # Étape 1 : Calcul des moyennes (hors Baccalauréat) moyennes = calculer_moyennes(student.resultats) moyennes_seconde = "\n".join([f"- {matiere}: {moyenne}" for matiere, moyenne in moyennes.get("Seconde", {}).items()]) moyennes_premiere = "\n".join([f"- {matiere}: {moyenne}" for matiere, moyenne in moyennes.get("Première", {}).items()]) moyennes_terminale = "\n".join([f"- {matiere}: {moyenne}" for matiere, moyenne in moyennes.get("Terminale", {}).items()]) # Étape 2 : Calcul des scores (hors Baccalauréat) scores = calculer_scores_selection(moyennes, coefficients, biais) scores_seconde = "\n".join([f"- {matiere}: {score}" for matiere, score in scores.get("Seconde", {}).items()]) scores_premiere = "\n".join([f"- {matiere}: {score}" for matiere, score in scores.get("Première", {}).items()]) scores_terminale = "\n".join([f"- {matiere}: {score}" for matiere, score in scores.get("Terminale", {}).items()]) # Étape 3 : Calcul des scores pour le Baccalauréat scores_bac = {} for matiere, note in student.resultats.get("Baccalauréat", {}).items(): coef = coefficients.get_coefficient(matiere) score_bac = (note * coef) + note + biais.get(matiere, 0) scores_bac[matiere] = score_bac # Ajout des scores du Baccalauréat aux scores globaux scores["Baccalauréat"] = scores_bac scores_bac_str = "\n".join([f"- {matiere}: {score}" for matiere, score in scores_bac.items()]) # Étape 4 : Sélection des meilleures matières par année (y compris Baccalauréat) meilleures_matieres = selectionner_meilleures_matieres(scores) meilleures_seconde = "\n".join([f"- {matiere}" for matiere in meilleures_matieres.get("Seconde", [])]) meilleures_premiere = "\n".join([f"- {matiere}" for matiere in meilleures_matieres.get("Première", [])]) meilleures_terminale = "\n".join([f"- {matiere}" for matiere in meilleures_matieres.get("Terminale", [])]) meilleures_bac = "\n".join([f"- {matiere}" for matiere in meilleures_matieres.get("Baccalauréat", [])]) # Étape 5 : Comptage des occurrences des meilleures matières occurrences = compter_occurrences_meilleures_matieres(meilleures_matieres) occurrences_str = "\n".join([f"- {matiere}: {count}" for matiere, count in occurrences.items()]) # Étape 6 : Sélection des quatre meilleures matières top_matieres = selectionner_top_matieres(occurrences, biais) top_matieres_str = "\n".join([f"- {matiere}" for matiere in top_matieres]) # Étape 7 : Proposition des filières propositions = proposer_filieres(top_matieres, filieres, student.serie) propositions_str = "\n".join([f"- {filiere.nom}" for filiere in propositions]) # Retourner toutes les étapes (15 valeurs) return [ f"Étudiant : {student.nom}", # Informations étudiant moyennes_seconde, moyennes_premiere, moyennes_terminale, # Moyennes par année scores_seconde, scores_premiere, scores_terminale, # Scores par année scores_bac_str, # Scores du Baccalauréat meilleures_seconde, meilleures_premiere, meilleures_terminale, meilleures_bac, # Meilleures matières par année occurrences_str, # Occurrences des meilleures matières top_matieres_str, # Quatre meilleures matières propositions_str # Filières proposées ] # Interface Gradio stylisée avec années séparées with gr.Blocks(theme=gr.themes.Soft()) as interface: gr.Markdown("# 🎓 ALGORITHME DE RECOOMANDATION VERSION 1🎓") gr.Markdown("Notre algorithme de recommandation de filières est conçu pour aider les étudiants à identifier les domaines d'études les plus adaptés à leurs compétences et performances académiques.") with gr.Row(): with gr.Column(): student_id_input = gr.Textbox(label="🔍 Identifiant Étudiant", placeholder="E001", lines=1) analyze_button = gr.Button("🚀 Analyser", variant="primary") with gr.Column(): student_info = gr.Textbox(label="👤 Informations Étudiant", interactive=False) with gr.Tab("📊 Moyennes et Scores"): with gr.Row(): with gr.Column(): gr.Markdown("### 📈 Moyennes par Année") with gr.Group(): gr.Markdown("#### Seconde") moyennes_seconde = gr.Textbox(label="", interactive=False, lines=4) gr.Markdown("#### Première") moyennes_premiere = gr.Textbox(label="", interactive=False, lines=4) gr.Markdown("#### Terminale") moyennes_terminale = gr.Textbox(label="", interactive=False, lines=4) with gr.Column(): gr.Markdown("### 📊 Scores par Année") with gr.Group(): gr.Markdown("#### Seconde") scores_seconde = gr.Textbox(label="", interactive=False, lines=4) gr.Markdown("#### Première") scores_premiere = gr.Textbox(label="", interactive=False, lines=4) gr.Markdown("#### Terminale") scores_terminale = gr.Textbox(label="", interactive=False, lines=4) with gr.Column(): gr.Markdown("### 🏆 Scores du Baccalauréat") scores_bac_output = gr.Textbox(label="", interactive=False, lines=6) with gr.Tab("🏅 Meilleures Matières"): with gr.Row(): with gr.Column(): gr.Markdown("### 🥇 Meilleures Matières par Année") with gr.Group(): gr.Markdown("#### Seconde") meilleures_seconde = gr.Textbox(label="", interactive=False, lines=3) gr.Markdown("#### Première") meilleures_premiere = gr.Textbox(label="", interactive=False, lines=3) gr.Markdown("#### Terminale") meilleures_terminale = gr.Textbox(label="", interactive=False, lines=3) gr.Markdown("#### Baccalauréat") meilleures_bac = gr.Textbox(label="", interactive=False, lines=3) with gr.Column(): gr.Markdown("### 🔢 Occurrences des Meilleures Matières") occurrences_output = gr.Textbox(label="", interactive=False, lines=6) with gr.Column(): gr.Markdown("### 🏅 Quatre Meilleures Matières") top_matieres_output = gr.Textbox(label="", interactive=False, lines=4) with gr.Tab("🎓 Filières Proposées"): gr.Markdown("### 📚 Filières Proposées") propositions_output = gr.Textbox(label="", interactive=False, lines=6) # Lier le bouton à la fonction analyze_button.click( analyser_etudiant, inputs=[student_id_input], outputs=[ student_info, moyennes_seconde, moyennes_premiere, moyennes_terminale, scores_seconde, scores_premiere, scores_terminale, scores_bac_output, meilleures_seconde, meilleures_premiere, meilleures_terminale, meilleures_bac, occurrences_output, top_matieres_output, propositions_output ] ) # Lancer l'application if __name__ == "__main__": interface.launch(server_port=7860) # Spécifier un port pour éviter les conflits