Spaces:
Running
Running
| #!/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) | |