File size: 9,619 Bytes
25f8116
 
e6211d5
25f8116
 
e6211d5
25f8116
 
e6211d5
 
 
 
 
 
 
 
 
25f8116
 
 
 
e6211d5
25f8116
e6211d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25f8116
 
e6211d5
 
 
25f8116
 
 
 
 
e6211d5
25f8116
e6211d5
 
 
 
 
 
25f8116
 
e6211d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25f8116
 
 
 
e6211d5
25f8116
 
e6211d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25f8116
 
 
 
 
 
e6211d5
25f8116
 
e6211d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25f8116
e6211d5
25f8116
e6211d5
25f8116
e6211d5
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python3
"""
๐Ÿ”ฎ Prรฉdiction UNITAIRE - API locale (Gradio)

Usage: python demo_unitaire.py
Prรฉrequis: Lancer l'API locale avec `python app.py`
"""

import re
import sys

try:
    from gradio_client import Client
except ImportError:
    print("โŒ gradio_client non installรฉ. Installez-le avec:")
    print("   pip install gradio_client")
    sys.exit(1)

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# CONFIGURATION
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
API_URL = "http://127.0.0.1:7860"

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# OPTIONS (menus numรฉrotรฉs)
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
DOMAINES = {
    1: "Infra & Cloud",
    2: "Transformation Digitale",
    3: "Marketing",
    4: "Entrepreunariat",
    5: "Ressources Humaines",
    6: "Autre",
}
FREQUENCES = {1: "Aucun", 2: "Occasionnel", 3: "Frequent"}
STATUTS = {1: "Cรฉlibataire", 2: "Mariรฉ(e)", 3: "Divorcรฉ(e)"}
DEPARTEMENTS = {1: "Commercial", 2: "Consulting", 3: "Ressources Humaines"}
POSTES = {
    1: "Cadre Commercial",
    2: "Assistant de Direction",
    3: "Consultant",
    4: "Tech Lead",
    5: "Manager",
    6: "Senior Manager",
    7: "Reprรฉsentant Commercial",
    8: "Directeur Technique",
    9: "Ressources Humaines",
}

print("โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—")
print("โ•‘  ๐Ÿ”ฎ PRร‰DICTION UNITAIRE - API Locale                     โ•‘")
print("โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•")
print(f"\n๐ŸŒ API: {API_URL}\n")

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# COLLECTE DES DONNร‰ES
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

print("โ•" * 60)
print("๐Ÿ“‹ DONNร‰ES SONDAGE")
print("โ•" * 60)
nombre_participation_pee = int(input("Participations PEE [0-3]: "))
nb_formations_suivies = int(input("Formations suivies [0-6]: "))
distance_domicile_travail = int(input("Distance domicile-travail km [1-30]: "))
niveau_education = int(
    input("Niveau รฉducation [1=Bac, 2=Bac+2, 3=Licence, 4=Master, 5=Doctorat]: ")
)

print(f"\nDomaine d'รฉtude: {DOMAINES}")
domaine_choix = int(input("Choix [1-6]: "))
domaine_etude = DOMAINES.get(domaine_choix, "Autre")

ayant_enfants_choix = int(input("A des enfants? [0=Non, 1=Oui]: "))
ayant_enfants = "Y" if ayant_enfants_choix == 1 else "N"

print(f"\nFrรฉquence dรฉplacement: {FREQUENCES}")
freq_choix = int(input("Choix [1-3]: "))
frequence_deplacement = FREQUENCES.get(freq_choix, "Aucun")

annees_depuis_promo = int(input("Annรฉes depuis derniรจre promotion [0-15]: "))
annees_sous_responsable = int(input("Annรฉes sous responsable actuel [0-17]: "))

print("\n" + "โ•" * 60)
print("๐Ÿ“Š DONNร‰ES ร‰VALUATION")
print("โ•" * 60)
satisfaction_environnement = int(input("Satisfaction environnement [1-4]: "))
note_eval_precedente = int(input("Note รฉvaluation prรฉcรฉdente [1-4]: "))
niveau_hierarchique = int(input("Niveau hiรฉrarchique [1-5]: "))
satisfaction_travail = int(input("Satisfaction nature travail [1-4]: "))
satisfaction_equipe = int(input("Satisfaction รฉquipe [1-4]: "))
satisfaction_equilibre = int(input("Satisfaction รฉquilibre pro/perso [1-4]: "))
note_eval_actuelle = int(input("Note รฉvaluation actuelle [3-4]: "))
heures_sup_choix = int(input("Heures supplรฉmentaires? [0=Non, 1=Oui]: "))
heure_supplementaires = "Oui" if heures_sup_choix == 1 else "Non"
augmentation_salaire = float(input("Augmentation salaire prรฉcรฉdente % [0-25]: "))

print("\n" + "โ•" * 60)
print("๐Ÿ’ผ DONNร‰ES RH (SIRH)")
print("โ•" * 60)
age = int(input("ร‚ge [18-60]: "))
genre_choix = int(input("Genre [1=Homme, 2=Femme]: "))
genre = "M" if genre_choix == 1 else "F"
revenu_mensuel = float(input("Revenu mensuel โ‚ฌ [1000-20000]: "))

print(f"\nStatut marital: {STATUTS}")
statut_choix = int(input("Choix [1-3]: "))
statut_marital = STATUTS.get(statut_choix, "Cรฉlibataire")

print(f"\nDรฉpartement: {DEPARTEMENTS}")
dept_choix = int(input("Choix [1-3]: "))
departement = DEPARTEMENTS.get(dept_choix, "Commercial")

print(f"\nPoste: {POSTES}")
poste_choix = int(input("Choix [1-9]: "))
poste = POSTES.get(poste_choix, "Consultant")

nombre_exp_precedentes = int(input("Expรฉriences prรฉcรฉdentes [0-9]: "))
annees_exp_totale = int(input("Annรฉes expรฉrience totale [0-40]: "))
annees_entreprise = int(input("Annรฉes dans l'entreprise [0-40]: "))
annees_poste = int(input("Annรฉes dans le poste actuel [0-18]: "))

# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
# PRร‰DICTION
# โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
print("\nโณ Connexion ร  l'API...")

try:
    client = Client(API_URL)
    print("โœ… Connectรฉ")
    print("โณ Envoi de la prรฉdiction...")

    result = client.predict(
        nombre_participation_pee=nombre_participation_pee,
        nb_formations_suivies=nb_formations_suivies,
        nombre_employee_sous_responsabilite=1,
        distance_domicile_travail=distance_domicile_travail,
        niveau_education=niveau_education,
        domaine_etude=domaine_etude,
        ayant_enfants=ayant_enfants,
        frequence_deplacement=frequence_deplacement,
        annees_depuis_la_derniere_promotion=annees_depuis_promo,
        annes_sous_responsable_actuel=annees_sous_responsable,
        satisfaction_employee_environnement=satisfaction_environnement,
        note_evaluation_precedente=note_eval_precedente,
        niveau_hierarchique_poste=niveau_hierarchique,
        satisfaction_employee_nature_travail=satisfaction_travail,
        satisfaction_employee_equipe=satisfaction_equipe,
        satisfaction_employee_equilibre_pro_perso=satisfaction_equilibre,
        note_evaluation_actuelle=note_eval_actuelle,
        heure_supplementaires=heure_supplementaires,
        augementation_salaire_precedente=augmentation_salaire,
        age=age,
        genre=genre,
        revenu_mensuel=revenu_mensuel,
        statut_marital=statut_marital,
        departement=departement,
        poste=poste,
        nombre_experiences_precedentes=nombre_exp_precedentes,
        nombre_heures_travailless=80,
        annee_experience_totale=annees_exp_totale,
        annees_dans_l_entreprise=annees_entreprise,
        annees_dans_le_poste_actuel=annees_poste,
        api_name="/predict",
    )

    # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    # AFFICHAGE DU Rร‰SULTAT
    # โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
    print("\n" + "โ•" * 60)
    print("๐Ÿ“Š Rร‰SULTAT DE LA PRร‰DICTION")
    print("โ•" * 60)

    if isinstance(result, str):
        # Extraire les probabilitรฉs du Markdown
        prob_depart = re.search(r"Probabilitรฉ de dรฉpart[^:]*:\s*([\d.]+)%", result)
        prob_maintien = re.search(r"Probabilitรฉ de maintien[^:]*:\s*([\d.]+)%", result)
        confiance = re.search(r"Confiance[^:]*:\s*([\d.]+)%", result)

        # Niveau de risque
        if "RISQUE ร‰LEVร‰" in result:
            print("\n๐Ÿ”ด Niveau de risque: ร‰LEVร‰")
        elif "RISQUE MOYEN" in result:
            print("\n๐ŸŸ  Niveau de risque: MOYEN")
        else:
            print("\n๐ŸŸข Niveau de risque: FAIBLE")

        # Probabilitรฉs
        if prob_maintien:
            print(f"\n๐Ÿ“ˆ Probabilitรฉ de rester:  {prob_maintien.group(1)}%")
        if prob_depart:
            print(f"๐Ÿ“‰ Probabilitรฉ de partir: {prob_depart.group(1)}%")
        if confiance:
            print(f"๐ŸŽฏ Confiance du modรจle:   {confiance.group(1)}%")

        # Prรฉdiction finale
        print("\n" + "โ”€" * 60)
        if "Dรฉpart probable" in result:
            print("๐Ÿšจ PRร‰DICTION FINALE: VA PARTIR")
        else:
            print("โœ… PRร‰DICTION FINALE: VA RESTER")
        print("โ”€" * 60)
    else:
        print(f"\n๐Ÿ“‹ Rรฉsultat: {result}")

    print("\nโœ… Prรฉdiction unitaire terminรฉe avec succรจs!")

except ConnectionError:
    print("\nโŒ Impossible de se connecter ร  l'API locale.")
    print("   Lancez d'abord: python app.py")
    sys.exit(1)
except Exception as e:
    print(f"\nโŒ Erreur: {e}")
    sys.exit(1)