Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- exemples/demo_unitaire.py +129 -87
- exemples/demo_unitaire_hf.py +167 -108
exemples/demo_unitaire.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
๐ฎ Prรฉdiction UNITAIRE -
|
| 4 |
|
| 5 |
Usage: python demo_unitaire.py
|
| 6 |
"""
|
|
@@ -10,71 +10,109 @@ import requests
|
|
| 10 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 11 |
# CONFIGURATION
|
| 12 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
|
| 20 |
print("โ ๐ฎ PRรDICTION UNITAIRE - Risque de dรฉpart employรฉ โ")
|
|
|
|
| 21 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n")
|
| 22 |
|
| 23 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 24 |
-
# COLLECTE DES DONNรES
|
| 25 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 26 |
|
| 27 |
-
print("
|
| 28 |
-
|
| 29 |
-
# === SONDAGE ===
|
| 30 |
print("๐ DONNรES SONDAGE")
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
"
|
| 37 |
-
)
|
| 38 |
-
ayant_enfants = input("A des enfants? (Y/N): ").upper()
|
| 39 |
-
frequence_deplacement = input("Frรฉquence dรฉplacement (Aucun, Occasionnel, Frequent): ")
|
| 40 |
-
annees_depuis_la_derniere_promotion = int(input("Annรฉes depuis derniรจre promotion: "))
|
| 41 |
-
annes_sous_responsable_actuel = int(input("Annรฉes sous responsable actuel (0-17): "))
|
| 42 |
-
|
| 43 |
-
# === รVALUATION ===
|
| 44 |
-
print("\n๐ DONNรES รVALUATION")
|
| 45 |
-
satisfaction_employee_environnement = int(input("Satisfaction environnement (1-4): "))
|
| 46 |
-
note_evaluation_precedente = int(input("Note รฉvaluation prรฉcรฉdente (1-4): "))
|
| 47 |
-
niveau_hierarchique_poste = int(input("Niveau hiรฉrarchique (1-5): "))
|
| 48 |
-
satisfaction_employee_nature_travail = int(input("Satisfaction nature travail (1-4): "))
|
| 49 |
-
satisfaction_employee_equipe = int(input("Satisfaction รฉquipe (1-4): "))
|
| 50 |
-
satisfaction_employee_equilibre_pro_perso = int(
|
| 51 |
-
input("Satisfaction รฉquilibre pro/perso (1-4): ")
|
| 52 |
-
)
|
| 53 |
-
note_evaluation_actuelle = int(input("Note รฉvaluation actuelle (3-4): "))
|
| 54 |
-
heure_supplementaires = input("Heures supplรฉmentaires? (Oui/Non): ")
|
| 55 |
-
augementation_salaire_precedente = float(
|
| 56 |
-
input("Augmentation salaire prรฉcรฉdente en % (0-100): ")
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 75 |
-
#
|
| 76 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 77 |
-
|
| 78 |
employee_data = {
|
| 79 |
"nombre_participation_pee": nombre_participation_pee,
|
| 80 |
"nb_formations_suivies": nb_formations_suivies,
|
|
@@ -84,63 +122,67 @@ employee_data = {
|
|
| 84 |
"domaine_etude": domaine_etude,
|
| 85 |
"ayant_enfants": ayant_enfants,
|
| 86 |
"frequence_deplacement": frequence_deplacement,
|
| 87 |
-
"annees_depuis_la_derniere_promotion":
|
| 88 |
-
"annes_sous_responsable_actuel":
|
| 89 |
-
"satisfaction_employee_environnement":
|
| 90 |
-
"note_evaluation_precedente":
|
| 91 |
-
"niveau_hierarchique_poste":
|
| 92 |
-
"satisfaction_employee_nature_travail":
|
| 93 |
-
"satisfaction_employee_equipe":
|
| 94 |
-
"satisfaction_employee_equilibre_pro_perso":
|
| 95 |
-
"note_evaluation_actuelle":
|
| 96 |
"heure_supplementaires": heure_supplementaires,
|
| 97 |
-
"augementation_salaire_precedente":
|
| 98 |
"age": age,
|
| 99 |
"genre": genre,
|
| 100 |
"revenu_mensuel": revenu_mensuel,
|
| 101 |
"statut_marital": statut_marital,
|
| 102 |
"departement": departement,
|
| 103 |
"poste": poste,
|
| 104 |
-
"nombre_experiences_precedentes":
|
| 105 |
"nombre_heures_travailless": 80,
|
| 106 |
-
"annee_experience_totale":
|
| 107 |
-
"annees_dans_l_entreprise":
|
| 108 |
-
"annees_dans_le_poste_actuel":
|
| 109 |
}
|
| 110 |
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
headers["X-API-Key"] = API_KEY
|
| 116 |
|
| 117 |
try:
|
| 118 |
response = requests.post(
|
| 119 |
-
f"{API_URL}/predict",
|
|
|
|
|
|
|
|
|
|
| 120 |
)
|
| 121 |
response.raise_for_status()
|
| 122 |
result = response.json()
|
| 123 |
|
| 124 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 125 |
-
# AFFICHAGE DU RรSULTAT
|
| 126 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 127 |
-
|
| 128 |
print("\n" + "โ" * 60)
|
| 129 |
-
print("
|
| 130 |
print("โ" * 60)
|
| 131 |
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
else:
|
| 135 |
-
print("\nโ
PRรDICTION:
|
| 136 |
|
| 137 |
-
print(f"\n
|
| 138 |
-
print(f"
|
| 139 |
-
print(f" Probabilitรฉ de partir: {result['probability_1']:.1%}")
|
| 140 |
|
| 141 |
-
|
|
|
|
| 142 |
|
| 143 |
-
except requests.exceptions.
|
| 144 |
-
print(
|
| 145 |
-
|
| 146 |
-
|
|
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
๐ฎ Prรฉdiction UNITAIRE - Interface simple avec entrรฉes numรฉriques uniquement
|
| 4 |
|
| 5 |
Usage: python demo_unitaire.py
|
| 6 |
"""
|
|
|
|
| 10 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 11 |
# CONFIGURATION
|
| 12 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 13 |
+
API_URL = "http://127.0.0.1:7860" # API locale
|
| 14 |
|
| 15 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 16 |
+
# OPTIONS ร AFFICHER (pour rรฉfรฉrence utilisateur)
|
| 17 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 18 |
+
DOMAINES = {
|
| 19 |
+
1: "Infra & Cloud",
|
| 20 |
+
2: "Transformation Digitale",
|
| 21 |
+
3: "Marketing",
|
| 22 |
+
4: "Entrepreunariat",
|
| 23 |
+
5: "Ressources Humaines",
|
| 24 |
+
6: "Autre",
|
| 25 |
+
}
|
| 26 |
+
FREQUENCES = {1: "Aucun", 2: "Occasionnel", 3: "Frequent"}
|
| 27 |
+
STATUTS = {1: "Cรฉlibataire", 2: "Mariรฉ(e)", 3: "Divorcรฉ(e)"}
|
| 28 |
+
DEPARTEMENTS = {1: "Commercial", 2: "Consulting", 3: "Ressources Humaines"}
|
| 29 |
+
POSTES = {
|
| 30 |
+
1: "Cadre Commercial",
|
| 31 |
+
2: "Assistant de Direction",
|
| 32 |
+
3: "Consultant",
|
| 33 |
+
4: "Tech Lead",
|
| 34 |
+
5: "Manager",
|
| 35 |
+
6: "Senior Manager",
|
| 36 |
+
7: "Reprรฉsentant Commercial",
|
| 37 |
+
8: "Directeur Technique",
|
| 38 |
+
9: "Ressources Humaines",
|
| 39 |
+
}
|
| 40 |
|
| 41 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
|
| 42 |
print("โ ๐ฎ PRรDICTION UNITAIRE - Risque de dรฉpart employรฉ โ")
|
| 43 |
+
print("โ (API locale - Entrรฉes numรฉriques uniquement) โ")
|
| 44 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n")
|
| 45 |
|
| 46 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 47 |
+
# COLLECTE DES DONNรES - Tout en nombres !
|
| 48 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 49 |
|
| 50 |
+
print("โ" * 60)
|
|
|
|
|
|
|
| 51 |
print("๐ DONNรES SONDAGE")
|
| 52 |
+
print("โ" * 60)
|
| 53 |
+
nombre_participation_pee = int(input("Participations PEE [0-3]: "))
|
| 54 |
+
nb_formations_suivies = int(input("Formations suivies [0-6]: "))
|
| 55 |
+
distance_domicile_travail = int(input("Distance domicile-travail km [1-30]: "))
|
| 56 |
+
niveau_education = int(
|
| 57 |
+
input("Niveau รฉducation [1=Bac, 2=Bac+2, 3=Licence, 4=Master, 5=Doctorat]: ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
)
|
| 59 |
|
| 60 |
+
print(f"\nDomaine d'รฉtude: {DOMAINES}")
|
| 61 |
+
domaine_choix = int(input("Choix [1-6]: "))
|
| 62 |
+
domaine_etude = DOMAINES.get(domaine_choix, "Autre")
|
| 63 |
+
|
| 64 |
+
ayant_enfants_choix = int(input("A des enfants? [0=Non, 1=Oui]: "))
|
| 65 |
+
ayant_enfants = "Y" if ayant_enfants_choix == 1 else "N"
|
| 66 |
+
|
| 67 |
+
print(f"\nFrรฉquence dรฉplacement: {FREQUENCES}")
|
| 68 |
+
freq_choix = int(input("Choix [1-3]: "))
|
| 69 |
+
frequence_deplacement = FREQUENCES.get(freq_choix, "Aucun")
|
| 70 |
+
|
| 71 |
+
annees_depuis_promo = int(input("Annรฉes depuis derniรจre promotion [0-15]: "))
|
| 72 |
+
annees_sous_responsable = int(input("Annรฉes sous responsable actuel [0-17]: "))
|
| 73 |
+
|
| 74 |
+
print("\n" + "โ" * 60)
|
| 75 |
+
print("๐ DONNรES รVALUATION")
|
| 76 |
+
print("โ" * 60)
|
| 77 |
+
satisfaction_environnement = int(input("Satisfaction environnement [1-4]: "))
|
| 78 |
+
note_eval_precedente = int(input("Note รฉvaluation prรฉcรฉdente [1-4]: "))
|
| 79 |
+
niveau_hierarchique = int(input("Niveau hiรฉrarchique [1-5]: "))
|
| 80 |
+
satisfaction_travail = int(input("Satisfaction nature travail [1-4]: "))
|
| 81 |
+
satisfaction_equipe = int(input("Satisfaction รฉquipe [1-4]: "))
|
| 82 |
+
satisfaction_equilibre = int(input("Satisfaction รฉquilibre pro/perso [1-4]: "))
|
| 83 |
+
note_eval_actuelle = int(input("Note รฉvaluation actuelle [3-4]: "))
|
| 84 |
+
heures_sup_choix = int(input("Heures supplรฉmentaires? [0=Non, 1=Oui]: "))
|
| 85 |
+
heure_supplementaires = "Oui" if heures_sup_choix == 1 else "Non"
|
| 86 |
+
augmentation_salaire = float(input("Augmentation salaire prรฉcรฉdente % [0-25]: "))
|
| 87 |
+
|
| 88 |
+
print("\n" + "โ" * 60)
|
| 89 |
+
print("๐ผ DONNรES RH (SIRH)")
|
| 90 |
+
print("โ" * 60)
|
| 91 |
+
age = int(input("รge [18-60]: "))
|
| 92 |
+
genre_choix = int(input("Genre [1=Homme, 2=Femme]: "))
|
| 93 |
+
genre = "M" if genre_choix == 1 else "F"
|
| 94 |
+
revenu_mensuel = float(input("Revenu mensuel โฌ [1000-20000]: "))
|
| 95 |
+
|
| 96 |
+
print(f"\nStatut marital: {STATUTS}")
|
| 97 |
+
statut_choix = int(input("Choix [1-3]: "))
|
| 98 |
+
statut_marital = STATUTS.get(statut_choix, "Cรฉlibataire")
|
| 99 |
+
|
| 100 |
+
print(f"\nDรฉpartement: {DEPARTEMENTS}")
|
| 101 |
+
dept_choix = int(input("Choix [1-3]: "))
|
| 102 |
+
departement = DEPARTEMENTS.get(dept_choix, "Commercial")
|
| 103 |
+
|
| 104 |
+
print(f"\nPoste: {POSTES}")
|
| 105 |
+
poste_choix = int(input("Choix [1-9]: "))
|
| 106 |
+
poste = POSTES.get(poste_choix, "Consultant")
|
| 107 |
+
|
| 108 |
+
nombre_exp_precedentes = int(input("Expรฉriences prรฉcรฉdentes [0-9]: "))
|
| 109 |
+
annees_exp_totale = int(input("Annรฉes expรฉrience totale [0-40]: "))
|
| 110 |
+
annees_entreprise = int(input("Annรฉes dans l'entreprise [0-40]: "))
|
| 111 |
+
annees_poste = int(input("Annรฉes dans le poste actuel [0-18]: "))
|
| 112 |
|
| 113 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 114 |
+
# CONSTRUCTION DE LA REQUรTE
|
| 115 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
| 116 |
employee_data = {
|
| 117 |
"nombre_participation_pee": nombre_participation_pee,
|
| 118 |
"nb_formations_suivies": nb_formations_suivies,
|
|
|
|
| 122 |
"domaine_etude": domaine_etude,
|
| 123 |
"ayant_enfants": ayant_enfants,
|
| 124 |
"frequence_deplacement": frequence_deplacement,
|
| 125 |
+
"annees_depuis_la_derniere_promotion": annees_depuis_promo,
|
| 126 |
+
"annes_sous_responsable_actuel": annees_sous_responsable,
|
| 127 |
+
"satisfaction_employee_environnement": satisfaction_environnement,
|
| 128 |
+
"note_evaluation_precedente": note_eval_precedente,
|
| 129 |
+
"niveau_hierarchique_poste": niveau_hierarchique,
|
| 130 |
+
"satisfaction_employee_nature_travail": satisfaction_travail,
|
| 131 |
+
"satisfaction_employee_equipe": satisfaction_equipe,
|
| 132 |
+
"satisfaction_employee_equilibre_pro_perso": satisfaction_equilibre,
|
| 133 |
+
"note_evaluation_actuelle": note_eval_actuelle,
|
| 134 |
"heure_supplementaires": heure_supplementaires,
|
| 135 |
+
"augementation_salaire_precedente": augmentation_salaire,
|
| 136 |
"age": age,
|
| 137 |
"genre": genre,
|
| 138 |
"revenu_mensuel": revenu_mensuel,
|
| 139 |
"statut_marital": statut_marital,
|
| 140 |
"departement": departement,
|
| 141 |
"poste": poste,
|
| 142 |
+
"nombre_experiences_precedentes": nombre_exp_precedentes,
|
| 143 |
"nombre_heures_travailless": 80,
|
| 144 |
+
"annee_experience_totale": annees_exp_totale,
|
| 145 |
+
"annees_dans_l_entreprise": annees_entreprise,
|
| 146 |
+
"annees_dans_le_poste_actuel": annees_poste,
|
| 147 |
}
|
| 148 |
|
| 149 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 150 |
+
# PRรDICTION
|
| 151 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 152 |
+
print("\nโณ Envoi de la requรชte ร l'API locale...")
|
|
|
|
| 153 |
|
| 154 |
try:
|
| 155 |
response = requests.post(
|
| 156 |
+
f"{API_URL}/predict",
|
| 157 |
+
json=employee_data,
|
| 158 |
+
headers={"Content-Type": "application/json"},
|
| 159 |
+
timeout=30,
|
| 160 |
)
|
| 161 |
response.raise_for_status()
|
| 162 |
result = response.json()
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
print("\n" + "โ" * 60)
|
| 165 |
+
print("๐ RรSULTAT DE LA PRรDICTION")
|
| 166 |
print("โ" * 60)
|
| 167 |
|
| 168 |
+
prediction = result.get("prediction", "N/A")
|
| 169 |
+
prob_stay = result.get("probability_stay", 0) * 100
|
| 170 |
+
prob_leave = result.get("probability_leave", 0) * 100
|
| 171 |
+
risk = result.get("risk_level", "N/A")
|
| 172 |
+
|
| 173 |
+
if prediction == 1:
|
| 174 |
+
print("\n๐จ PRรDICTION: VA PARTIR")
|
| 175 |
else:
|
| 176 |
+
print("\nโ
PRรDICTION: VA RESTER")
|
| 177 |
|
| 178 |
+
print(f"\n๐ Probabilitรฉ de rester: {prob_stay:.1f}%")
|
| 179 |
+
print(f"๐ Probabilitรฉ de partir: {prob_leave:.1f}%")
|
|
|
|
| 180 |
|
| 181 |
+
risk_emoji = {"Low": "๐ข", "Medium": "๐ ", "High": "๐ด"}.get(risk, "โช")
|
| 182 |
+
print(f"\n{risk_emoji} Niveau de risque: {risk}")
|
| 183 |
|
| 184 |
+
except requests.exceptions.ConnectionError:
|
| 185 |
+
print("\nโ Impossible de se connecter ร l'API locale.")
|
| 186 |
+
print(" Lancez d'abord: ./lancer_api.sh")
|
| 187 |
+
except Exception as e:
|
| 188 |
+
print(f"\nโ Erreur: {e}")
|
exemples/demo_unitaire_hf.py
CHANGED
|
@@ -1,131 +1,190 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
-
๐ฎ Prรฉdiction UNITAIRE via
|
| 4 |
|
| 5 |
Usage: python demo_unitaire_hf.py
|
| 6 |
-
|
| 7 |
-
- Envoie la requรชte ร la Space HF
|
| 8 |
-
- Affiche la prรฉdiction
|
| 9 |
-
|
| 10 |
-
Option: dรฉfinir HF_API_URL pour surcharger l'URL par dรฉfaut.
|
| 11 |
"""
|
| 12 |
|
| 13 |
import os
|
| 14 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
API_URL = os.getenv("HF_API_URL", "https://asi-engineer-oc-p5.hf.space")
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
|
| 19 |
-
print("โ ๐ฎ
|
|
|
|
| 20 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n")
|
| 21 |
print(f"๐ API: {API_URL}\n")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
)
|
| 34 |
-
ayant_enfants = input("A des enfants? (Y/N): ").upper()
|
| 35 |
-
frequence_deplacement = input("Frรฉquence dรฉplacement (Aucun, Occasionnel, Frequent): ")
|
| 36 |
-
annees_depuis_la_derniere_promotion = int(input("Annรฉes depuis derniรจre promotion: "))
|
| 37 |
-
annes_sous_responsable_actuel = int(input("Annรฉes sous responsable actuel (0-17): "))
|
| 38 |
-
|
| 39 |
-
# === รVALUATION ===
|
| 40 |
-
satisfaction_employee_environnement = int(input("Satisfaction environnement (1-4): "))
|
| 41 |
-
note_evaluation_precedente = int(input("Note รฉvaluation prรฉcรฉdente (1-4): "))
|
| 42 |
-
niveau_hierarchique_poste = int(input("Niveau hiรฉrarchique (1-5): "))
|
| 43 |
-
satisfaction_employee_nature_travail = int(input("Satisfaction nature travail (1-4): "))
|
| 44 |
-
satisfaction_employee_equipe = int(input("Satisfaction รฉquipe (1-4): "))
|
| 45 |
-
satisfaction_employee_equilibre_pro_perso = int(
|
| 46 |
-
input("Satisfaction รฉquilibre pro/perso (1-4): ")
|
| 47 |
)
|
| 48 |
-
note_evaluation_actuelle = int(input("Note รฉvaluation actuelle (3-4): "))
|
| 49 |
-
heure_supplementaires = input("Heures supplรฉmentaires? (Oui/Non): ")
|
| 50 |
-
augementation_salaire_precedente = float(input("Augmentation salaire prรฉcรฉdente (%): "))
|
| 51 |
-
|
| 52 |
-
# === SIRH ===
|
| 53 |
-
age = int(input("รge (18-60): "))
|
| 54 |
-
genre = input("Genre (M/F): ").upper()
|
| 55 |
-
revenu_mensuel = float(input("Revenu mensuel (โฌ): "))
|
| 56 |
-
statut_marital = input("Statut marital (Cรฉlibataire, Mariรฉ(e), Divorcรฉ(e)): ")
|
| 57 |
-
departement = input("Dรฉpartement (Commercial, Consulting, Ressources Humaines): ")
|
| 58 |
-
poste = input("Poste: ")
|
| 59 |
-
nombre_experiences_precedentes = int(input("Nb expรฉriences prรฉcรฉdentes (0-9): "))
|
| 60 |
-
annee_experience_totale = int(input("Annรฉes expรฉrience totale: "))
|
| 61 |
-
annees_dans_l_entreprise = int(input("Annรฉes dans l'entreprise (0-40): "))
|
| 62 |
-
annees_dans_le_poste_actuel = int(input("Annรฉes dans le poste actuel (0-18): "))
|
| 63 |
-
|
| 64 |
-
employee_data = {
|
| 65 |
-
"nombre_participation_pee": nombre_participation_pee,
|
| 66 |
-
"nb_formations_suivies": nb_formations_suivies,
|
| 67 |
-
"nombre_employee_sous_responsabilite": 1,
|
| 68 |
-
"distance_domicile_travail": distance_domicile_travail,
|
| 69 |
-
"niveau_education": niveau_education,
|
| 70 |
-
"domaine_etude": domaine_etude,
|
| 71 |
-
"ayant_enfants": ayant_enfants,
|
| 72 |
-
"frequence_deplacement": frequence_deplacement,
|
| 73 |
-
"annees_depuis_la_derniere_promotion": annees_depuis_la_derniere_promotion,
|
| 74 |
-
"annes_sous_responsable_actuel": annes_sous_responsable_actuel,
|
| 75 |
-
"satisfaction_employee_environnement": satisfaction_employee_environnement,
|
| 76 |
-
"note_evaluation_precedente": note_evaluation_precedente,
|
| 77 |
-
"niveau_hierarchique_poste": niveau_hierarchique_poste,
|
| 78 |
-
"satisfaction_employee_nature_travail": satisfaction_employee_nature_travail,
|
| 79 |
-
"satisfaction_employee_equipe": satisfaction_employee_equipe,
|
| 80 |
-
"satisfaction_employee_equilibre_pro_perso": satisfaction_employee_equilibre_pro_perso,
|
| 81 |
-
"note_evaluation_actuelle": note_evaluation_actuelle,
|
| 82 |
-
"heure_supplementaires": heure_supplementaires,
|
| 83 |
-
"augementation_salaire_precedente": augementation_salaire_precedente,
|
| 84 |
-
"age": age,
|
| 85 |
-
"genre": genre,
|
| 86 |
-
"revenu_mensuel": revenu_mensuel,
|
| 87 |
-
"statut_marital": statut_marital,
|
| 88 |
-
"departement": departement,
|
| 89 |
-
"poste": poste,
|
| 90 |
-
"nombre_experiences_precedentes": nombre_experiences_precedentes,
|
| 91 |
-
"nombre_heures_travailless": 80,
|
| 92 |
-
"annee_experience_totale": annee_experience_totale,
|
| 93 |
-
"annees_dans_l_entreprise": annees_dans_l_entreprise,
|
| 94 |
-
"annees_dans_le_poste_actuel": annees_dans_le_poste_actuel,
|
| 95 |
-
}
|
| 96 |
|
| 97 |
-
print("\
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
try:
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
)
|
| 108 |
-
if r.status_code == 404:
|
| 109 |
-
print(
|
| 110 |
-
"\nโ Endpoint HF introuvable (/predict). Vรฉrifiez que la Space expose l'API FastAPI."
|
| 111 |
-
)
|
| 112 |
-
print(" Sinon, utilisez l'API locale (lancer_api.sh) ou GRADIO.")
|
| 113 |
-
raise SystemExit(1)
|
| 114 |
-
r.raise_for_status()
|
| 115 |
-
result = r.json()
|
| 116 |
|
| 117 |
print("\n" + "โ" * 60)
|
| 118 |
-
print("
|
| 119 |
print("โ" * 60)
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
+
๐ฎ Prรฉdiction UNITAIRE via Hugging Face - Entrรฉes numรฉriques uniquement
|
| 4 |
|
| 5 |
Usage: python demo_unitaire_hf.py
|
| 6 |
+
Prรฉrequis: pip install gradio_client
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
"""
|
| 8 |
|
| 9 |
import os
|
| 10 |
+
import sys
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
from gradio_client import Client
|
| 14 |
+
except ImportError:
|
| 15 |
+
print("โ gradio_client non installรฉ. Installez-le avec:")
|
| 16 |
+
print(" pip install gradio_client")
|
| 17 |
+
sys.exit(1)
|
| 18 |
|
| 19 |
API_URL = os.getenv("HF_API_URL", "https://asi-engineer-oc-p5.hf.space")
|
| 20 |
|
| 21 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 22 |
+
# OPTIONS ร AFFICHER (pour rรฉfรฉrence utilisateur)
|
| 23 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 24 |
+
DOMAINES = {
|
| 25 |
+
1: "Infra & Cloud",
|
| 26 |
+
2: "Transformation Digitale",
|
| 27 |
+
3: "Marketing",
|
| 28 |
+
4: "Entrepreunariat",
|
| 29 |
+
5: "Ressources Humaines",
|
| 30 |
+
6: "Autre",
|
| 31 |
+
}
|
| 32 |
+
FREQUENCES = {1: "Aucun", 2: "Occasionnel", 3: "Frequent"}
|
| 33 |
+
STATUTS = {1: "Cรฉlibataire", 2: "Mariรฉ(e)", 3: "Divorcรฉ(e)"}
|
| 34 |
+
DEPARTEMENTS = {1: "Commercial", 2: "Consulting", 3: "Ressources Humaines"}
|
| 35 |
+
POSTES = {
|
| 36 |
+
1: "Cadre Commercial",
|
| 37 |
+
2: "Assistant de Direction",
|
| 38 |
+
3: "Consultant",
|
| 39 |
+
4: "Tech Lead",
|
| 40 |
+
5: "Manager",
|
| 41 |
+
6: "Senior Manager",
|
| 42 |
+
7: "Reprรฉsentant Commercial",
|
| 43 |
+
8: "Directeur Technique",
|
| 44 |
+
9: "Ressources Humaines",
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ")
|
| 48 |
+
print("โ ๐ฎ PRรDICTION UNITAIRE - Hugging Face Spaces โ")
|
| 49 |
+
print("โ (Entrรฉes numรฉriques uniquement) โ")
|
| 50 |
print("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n")
|
| 51 |
print(f"๐ API: {API_URL}\n")
|
| 52 |
|
| 53 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 54 |
+
# COLLECTE DES DONNรES - Tout en nombres !
|
| 55 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 56 |
|
| 57 |
+
print("โ" * 60)
|
| 58 |
+
print("๐ DONNรES SONDAGE")
|
| 59 |
+
print("โ" * 60)
|
| 60 |
+
nombre_participation_pee = int(input("Participations PEE [0-3]: "))
|
| 61 |
+
nb_formations_suivies = int(input("Formations suivies [0-6]: "))
|
| 62 |
+
distance_domicile_travail = int(input("Distance domicile-travail km [1-30]: "))
|
| 63 |
+
niveau_education = int(
|
| 64 |
+
input("Niveau รฉducation [1=Bac, 2=Bac+2, 3=Licence, 4=Master, 5=Doctorat]: ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
print(f"\nDomaine d'รฉtude: {DOMAINES}")
|
| 68 |
+
domaine_choix = int(input("Choix [1-6]: "))
|
| 69 |
+
domaine_etude = DOMAINES.get(domaine_choix, "Autre")
|
| 70 |
+
|
| 71 |
+
ayant_enfants_choix = int(input("A des enfants? [0=Non, 1=Oui]: "))
|
| 72 |
+
ayant_enfants = "Y" if ayant_enfants_choix == 1 else "N"
|
| 73 |
+
|
| 74 |
+
print(f"\nFrรฉquence dรฉplacement: {FREQUENCES}")
|
| 75 |
+
freq_choix = int(input("Choix [1-3]: "))
|
| 76 |
+
frequence_deplacement = FREQUENCES.get(freq_choix, "Aucun")
|
| 77 |
+
|
| 78 |
+
annees_depuis_promo = int(input("Annรฉes depuis derniรจre promotion [0-15]: "))
|
| 79 |
+
annees_sous_responsable = int(input("Annรฉes sous responsable actuel [0-17]: "))
|
| 80 |
+
|
| 81 |
+
print("\n" + "โ" * 60)
|
| 82 |
+
print("๐ DONNรES รVALUATION")
|
| 83 |
+
print("โ" * 60)
|
| 84 |
+
satisfaction_environnement = int(input("Satisfaction environnement [1-4]: "))
|
| 85 |
+
note_eval_precedente = int(input("Note รฉvaluation prรฉcรฉdente [1-4]: "))
|
| 86 |
+
niveau_hierarchique = int(input("Niveau hiรฉrarchique [1-5]: "))
|
| 87 |
+
satisfaction_travail = int(input("Satisfaction nature travail [1-4]: "))
|
| 88 |
+
satisfaction_equipe = int(input("Satisfaction รฉquipe [1-4]: "))
|
| 89 |
+
satisfaction_equilibre = int(input("Satisfaction รฉquilibre pro/perso [1-4]: "))
|
| 90 |
+
note_eval_actuelle = int(input("Note รฉvaluation actuelle [3-4]: "))
|
| 91 |
+
heures_sup_choix = int(input("Heures supplรฉmentaires? [0=Non, 1=Oui]: "))
|
| 92 |
+
heure_supplementaires = "Oui" if heures_sup_choix == 1 else "Non"
|
| 93 |
+
augmentation_salaire = float(input("Augmentation salaire prรฉcรฉdente % [0-25]: "))
|
| 94 |
+
|
| 95 |
+
print("\n" + "โ" * 60)
|
| 96 |
+
print("๐ผ DONNรES RH (SIRH)")
|
| 97 |
+
print("โ" * 60)
|
| 98 |
+
age = int(input("รge [18-60]: "))
|
| 99 |
+
genre_choix = int(input("Genre [1=Homme, 2=Femme]: "))
|
| 100 |
+
genre = "M" if genre_choix == 1 else "F"
|
| 101 |
+
revenu_mensuel = float(input("Revenu mensuel โฌ [1000-20000]: "))
|
| 102 |
+
|
| 103 |
+
print(f"\nStatut marital: {STATUTS}")
|
| 104 |
+
statut_choix = int(input("Choix [1-3]: "))
|
| 105 |
+
statut_marital = STATUTS.get(statut_choix, "Cรฉlibataire")
|
| 106 |
+
|
| 107 |
+
print(f"\nDรฉpartement: {DEPARTEMENTS}")
|
| 108 |
+
dept_choix = int(input("Choix [1-3]: "))
|
| 109 |
+
departement = DEPARTEMENTS.get(dept_choix, "Commercial")
|
| 110 |
+
|
| 111 |
+
print(f"\nPoste: {POSTES}")
|
| 112 |
+
poste_choix = int(input("Choix [1-9]: "))
|
| 113 |
+
poste = POSTES.get(poste_choix, "Consultant")
|
| 114 |
+
|
| 115 |
+
nombre_exp_precedentes = int(input("Expรฉriences prรฉcรฉdentes [0-9]: "))
|
| 116 |
+
annees_exp_totale = int(input("Annรฉes expรฉrience totale [0-40]: "))
|
| 117 |
+
annees_entreprise = int(input("Annรฉes dans l'entreprise [0-40]: "))
|
| 118 |
+
annees_poste = int(input("Annรฉes dans le poste actuel [0-18]: "))
|
| 119 |
+
|
| 120 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
+
# PRรDICTION VIA GRADIO CLIENT
|
| 122 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 123 |
+
print("\nโณ Connexion ร l'API Gradio HF...")
|
| 124 |
|
| 125 |
try:
|
| 126 |
+
client = Client(API_URL)
|
| 127 |
+
print("โ
Connectรฉ\n")
|
| 128 |
+
print("โณ Envoi de la prรฉdiction...")
|
| 129 |
+
|
| 130 |
+
result = client.predict(
|
| 131 |
+
nombre_participation_pee=nombre_participation_pee,
|
| 132 |
+
nb_formations_suivies=nb_formations_suivies,
|
| 133 |
+
nombre_employee_sous_responsabilite=1,
|
| 134 |
+
distance_domicile_travail=distance_domicile_travail,
|
| 135 |
+
niveau_education=niveau_education,
|
| 136 |
+
domaine_etude=domaine_etude,
|
| 137 |
+
ayant_enfants=ayant_enfants,
|
| 138 |
+
frequence_deplacement=frequence_deplacement,
|
| 139 |
+
annees_depuis_la_derniere_promotion=annees_depuis_promo,
|
| 140 |
+
annes_sous_responsable_actuel=annees_sous_responsable,
|
| 141 |
+
satisfaction_employee_environnement=satisfaction_environnement,
|
| 142 |
+
note_evaluation_precedente=note_eval_precedente,
|
| 143 |
+
niveau_hierarchique_poste=niveau_hierarchique,
|
| 144 |
+
satisfaction_employee_nature_travail=satisfaction_travail,
|
| 145 |
+
satisfaction_employee_equipe=satisfaction_equipe,
|
| 146 |
+
satisfaction_employee_equilibre_pro_perso=satisfaction_equilibre,
|
| 147 |
+
note_evaluation_actuelle=note_eval_actuelle,
|
| 148 |
+
heure_supplementaires=heure_supplementaires,
|
| 149 |
+
augementation_salaire_precedente=augmentation_salaire,
|
| 150 |
+
age=age,
|
| 151 |
+
genre=genre,
|
| 152 |
+
revenu_mensuel=revenu_mensuel,
|
| 153 |
+
statut_marital=statut_marital,
|
| 154 |
+
departement=departement,
|
| 155 |
+
poste=poste,
|
| 156 |
+
nombre_experiences_precedentes=nombre_exp_precedentes,
|
| 157 |
+
nombre_heures_travailless=80,
|
| 158 |
+
annee_experience_totale=annees_exp_totale,
|
| 159 |
+
annees_dans_l_entreprise=annees_entreprise,
|
| 160 |
+
annees_dans_le_poste_actuel=annees_poste,
|
| 161 |
+
api_name="/predict",
|
| 162 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
print("\n" + "โ" * 60)
|
| 165 |
+
print("๐ RรSULTAT DE LA PRรDICTION (HF)")
|
| 166 |
print("โ" * 60)
|
| 167 |
+
|
| 168 |
+
# Le rรฉsultat Gradio peut รชtre un dict ou une string
|
| 169 |
+
if isinstance(result, dict):
|
| 170 |
+
prediction = result.get("prediction", "N/A")
|
| 171 |
+
prob_stay = result.get("probability_stay", 0) * 100
|
| 172 |
+
prob_leave = result.get("probability_leave", 0) * 100
|
| 173 |
+
risk = result.get("risk_level", "N/A")
|
| 174 |
+
|
| 175 |
+
if prediction == 1:
|
| 176 |
+
print("\n๐จ PRรDICTION: VA PARTIR")
|
| 177 |
+
else:
|
| 178 |
+
print("\nโ
PRรDICTION: VA RESTER")
|
| 179 |
+
|
| 180 |
+
print(f"\n๐ Probabilitรฉ de rester: {prob_stay:.1f}%")
|
| 181 |
+
print(f"๐ Probabilitรฉ de partir: {prob_leave:.1f}%")
|
| 182 |
+
|
| 183 |
+
risk_emoji = {"Low": "๐ข", "Medium": "๐ ", "High": "๐ด"}.get(risk, "โช")
|
| 184 |
+
print(f"\n{risk_emoji} Niveau de risque: {risk}")
|
| 185 |
+
else:
|
| 186 |
+
print(f"\n๐ Rรฉsultat: {result}")
|
| 187 |
+
|
| 188 |
+
except Exception as e:
|
| 189 |
+
print(f"\nโ Erreur: {e}")
|
| 190 |
+
sys.exit(1)
|