ASI-Engineer commited on
Commit
55d3e4c
ยท
verified ยท
1 Parent(s): 7cc1222

Upload folder using huggingface_hub

Browse files
CLEANUP_COMPLETION_REPORT.md DELETED
@@ -1,252 +0,0 @@
1
- # ๐Ÿ”„ Cleanup Completion Report - PR devโ†’main
2
-
3
- ## Executive Summary
4
- **All 8 sub-steps of the comprehensive project cleanup have been completed successfully.** The project is now clean, well-organized, and evaluator-ready with 100% test pass rate and 75.63% code coverage maintained throughout.
5
-
6
- ---
7
-
8
- ## Cleanup Completion Status
9
-
10
- ### โœ… Sub-Step 1: Audit & Backup Branch
11
- - Created backup-post-audit branch with safety checkpoint
12
- - Generated pre-cleanup structure snapshot (docs/structure_pre_clean.txt)
13
- - Documented all findings in 7 professional audit reports
14
-
15
- ### โœ… Sub-Step 2: Validation Phase 1
16
- - Verified .gitignore completeness
17
- - Validated 86/86 tests passing (100% pass rate)
18
- - Confirmed 70.27%+ code coverage
19
- - Black/Flake8 linting successful
20
-
21
- ### โœ… Sub-Step 3: Clean Root Files
22
- - Merged README_HF.md content โ†’ README.md (new HuggingFace section)
23
- - Renamed requirements_full.txt โ†’ requirements_dev.txt (prod/dev distinction)
24
- - Archived etapes.txt โ†’ docs/etapes_archive.txt (preserved educational context)
25
- - Updated .gitignore accordingly
26
-
27
- ### โœ… Sub-Step 4: Documentation Consolidation
28
- - **API Docs**: 3 sources (API.md, api/guide.md, API_GUIDE.md) โ†’ **1 source (API_GUIDE.md)**
29
- - **Model Docs**: 2 sources (model/technical.md, MODEL_TECHNICAL.md) โ†’ **1 source (MODEL_TECHNICAL.md)**
30
- - Removed redundant directories: docs/api/ and docs/model/
31
- - Updated mkdocs.yml navigation
32
- - Result: **-883 lines duplicated** (-39% reduction)
33
-
34
- ### โœ… Sub-Step 5: Optimize docs/ Navigation
35
- - Enhanced docs/index.md with comprehensive "๐Ÿ“š Navigation Documentation" hub
36
- - Organized 18 documents into 8 categories
37
- - Generated pytest coverage HTML report (docs/coverage_report/)
38
- - Added clear navigation tips for users/developers/evaluators
39
- - MkDocs builds successfully (0.81s)
40
-
41
- ### โœ… Sub-Step 6: Refine src/tests Structure
42
- - Reorganized tests/ from flat โ†’ hierarchical structure:
43
- - test_api/ (5 test files: auth, demo, health, predict, validation)
44
- - test_database/ (database operations tests)
45
- - test_functional/ (end-to-end tests)
46
- - test_model/ (ML model tests)
47
- - Added __init__.py to each subdirectory (Python packages)
48
- - Fixed monkeypatch reference in test_functional.py (import path update)
49
- - Created tests/README.md with structure & fixture documentation
50
- - Result: **86/86 tests passing**, 75.63% coverage maintained
51
-
52
- ### โœ… Sub-Step 7: Clean Other Folders
53
- - Removed redundant root files (README_HF.md, etapes.txt duplicate)
54
- - Removed .vscode/ directory (personal IDE config)
55
- - Archived logs/ โ†’ docs/logs_archive/ (api.log, error.log preserved)
56
- - Result: **Cleaner root directory** with only essential files
57
-
58
- ### โœ… Sub-Step 8: Finalize CI/CD & Prepare Merge
59
- - Created composite GitHub Action (.github/actions/setup-poetry/action.yml)
60
- - Refactored CI/CD workflow to eliminate duplicate setup steps (-60% duplication)
61
- - Added MkDocs documentation build validation before HF deployments
62
- - Optimized job dependencies (cleaner DAG)
63
- - Improved job naming for clarity
64
- - Result: **Production-ready CI/CD** with enhanced reliability
65
-
66
- ---
67
-
68
- ## Quantified Impact
69
-
70
- | Metric | Before | After | Change |
71
- |--------|--------|-------|--------|
72
- | **Python Files** | 24 | 24 | No loss of function โœ… |
73
- | **Root Files** | 11 | 8 | -3 (cleaner) |
74
- | **Tests** | 86/86 passed | 86/86 passed | 100% maintained โœ… |
75
- | **Coverage** | 75.63% | 75.63% | Maintained โœ… |
76
- | **Documentation Files** | 18 | 18 | Consolidated (no loss) |
77
- | **Duplicate Lines** | 883 | 0 | -883 (-39%) |
78
- | **CI/CD Setup Duplication** | 60% | 20% | -67% (optimized) |
79
- | **Root Folders** | 13 | 12 | -1 (logs archived) |
80
-
81
- ---
82
-
83
- ## Testing & Quality Assurance
84
-
85
- ### Final Validation
86
- ```
87
- โœ… 86 tests passed
88
- โœ… 11 tests skipped (expected - API integration & rate limiting)
89
- โœ… 75.63% code coverage (exceeds 70% requirement)
90
- โœ… Black linting: OK
91
- โœ… Flake8 linting: OK
92
- โœ… MkDocs build: 0.81s (successful)
93
- โœ… Import integrity: All modules loading correctly
94
- โœ… Git history: Clean, pedagogical commits throughout
95
- ```
96
-
97
- ### Test Results Summary
98
- - **Total**: 97 tests
99
- - **Passed**: 86 โœ…
100
- - **Skipped**: 11 (intentional)
101
- - **Failed**: 0 โœ…
102
- - **Pass Rate**: 100%
103
-
104
- ---
105
-
106
- ## Git Commit History
107
-
108
- ### Cleanup Commits (dev branch)
109
- ```
110
- 21d4cb3 ci: optimize CI/CD pipeline with composite action and documentation build
111
- d46bcee chore: clean root and archive non-essential folders
112
- 92ff10b refactor: reorganize tests directory into modular structure
113
- a6460c0 docs: optimize docs/ with comprehensive navigation index
114
- 8ce38b2 docs: rapport sous-รฉtape 4 - consolidation documentation
115
- 941a4dd docs: consolidate API and Model documentation
116
- 727d10c docs: rapport sous-รฉtape 3 - clean racine complรฉtรฉ
117
- 9aa0dbb refactor: clean root files while keeping history visible
118
- cd0bc36 docs: sous-รฉtape 2 - validations phase 1 complรฉtรฉes
119
- debc614 docs: ajoute รฉtat prรฉ-sous-รฉtape-2 pour continuitรฉ du cleanup
120
- ```
121
-
122
- **Total commits in cleanup**: 10 (from backup-post-audit)
123
-
124
- ---
125
-
126
- ## Project Structure (Final State)
127
-
128
- ```
129
- OC_P5/
130
- โ”œโ”€โ”€ docs/ # โœ… Optimized documentation
131
- โ”‚ โ”œโ”€โ”€ index.md # Navigation hub (8 categories)
132
- โ”‚ โ”œโ”€โ”€ API_GUIDE.md # Consolidated API docs
133
- โ”‚ โ”œโ”€โ”€ MODEL_TECHNICAL.md # Consolidated model docs
134
- โ”‚ โ”œโ”€โ”€ etapes_archive.txt # Educational context
135
- โ”‚ โ”œโ”€โ”€ logs_archive/ # Archived logs
136
- โ”‚ โ””โ”€โ”€ coverage_report/ # Pytest coverage HTML
137
- โ”œโ”€โ”€ src/ # โœ… Core modules (unchanged)
138
- โ”‚ โ”œโ”€โ”€ __init__.py
139
- โ”‚ โ”œโ”€โ”€ auth.py
140
- โ”‚ โ”œโ”€โ”€ config.py
141
- โ”‚ โ”œโ”€โ”€ models.py
142
- โ”‚ โ”œโ”€โ”€ schemas.py
143
- โ”‚ โ”œโ”€โ”€ preprocessing.py
144
- โ”‚ โ”œโ”€โ”€ logger.py
145
- โ”‚ โ”œโ”€โ”€ rate_limit.py
146
- โ”‚ โ””โ”€โ”€ gradio_ui.py
147
- โ”œโ”€โ”€ tests/ # โœ… Reorganized hierarchy
148
- โ”‚ โ”œโ”€โ”€ conftest.py
149
- โ”‚ โ”œโ”€โ”€ README.md # Structure documentation
150
- โ”‚ โ”œโ”€โ”€ test_api/ # 5 API test files
151
- โ”‚ โ”œโ”€โ”€ test_database/ # Database tests
152
- โ”‚ โ”œโ”€โ”€ test_functional/ # End-to-end tests
153
- โ”‚ โ””โ”€โ”€ test_model/ # ML model tests
154
- โ”œโ”€โ”€ ml_model/ # โœ… Training scripts (preserved)
155
- โ”œโ”€โ”€ scripts/ # โœ… Utilities (preserved)
156
- โ”œโ”€โ”€ .github/ # โœ… CI/CD optimized
157
- โ”‚ โ”œโ”€โ”€ workflows/ci-cd.yml # Optimized pipeline
158
- โ”‚ โ””โ”€โ”€ actions/setup-poetry/ # Reusable composite action
159
- โ”œโ”€โ”€ README.md # โœ… Enriched (HF integration)
160
- โ”œโ”€โ”€ pyproject.toml # โœ… Dependency management
161
- โ”œโ”€โ”€ mkdocs.yml # โœ… Documentation config
162
- โ””โ”€โ”€ .gitignore # โœ… Complete
163
- ```
164
-
165
- ---
166
-
167
- ## Key Achievements
168
-
169
- ### ๐ŸŽฏ Code Quality
170
- - โœ… Zero functional loss - all tests passing
171
- - โœ… Zero regressions detected
172
- - โœ… Code coverage maintained above requirement
173
- - โœ… Clean, pedagogical commit messages
174
-
175
- ### ๐ŸŽฏ Organization
176
- - โœ… Eliminated 883 lines of duplication (-39%)
177
- - โœ… Single source of truth for each documentation topic
178
- - โœ… Hierarchical test organization for clarity
179
- - โœ… Clean root directory (removed non-essential files)
180
-
181
- ### ๐ŸŽฏ DevOps & CI/CD
182
- - โœ… Composite GitHub Action created (DRY principle)
183
- - โœ… 60% reduction in setup code duplication
184
- - โœ… Automatic documentation validation before deployment
185
- - โœ… Production-ready pipeline
186
-
187
- ### ๐ŸŽฏ Evaluator Experience
188
- - โœ… Clear navigation (docs/index.md with 8 categories)
189
- - โœ… Comprehensive audit trail (git history)
190
- - โœ… Before/after documentation
191
- - โœ… Educational context preserved (etapes_archive.txt)
192
- - โœ… Repo structure optimized for understanding
193
-
194
- ---
195
-
196
- ## Recommendations for Merge
197
-
198
- ### โœ… Pre-Merge Checklist
199
- - [x] All tests passing (86/86)
200
- - [x] Coverage requirement met (75.63% โ‰ฅ 70%)
201
- - [x] Code review: Clean commits with pedagogical messages
202
- - [x] Linting: Black + Flake8 passing
203
- - [x] Documentation: MkDocs builds successfully
204
- - [x] Git history: Clean and traceable
205
- - [x] No breaking changes: Zero functional loss
206
- - [x] CI/CD: Optimized and ready for production
207
-
208
- ### Merge Strategy
209
- 1. This PR represents **completion of the comprehensive cleanup project**
210
- 2. No functional code was modified - only organization
211
- 3. All sub-steps have been validated and documented
212
- 4. Ready for immediate merge to main branch
213
-
214
- ### Post-Merge Steps
215
- 1. Tag release (e.g., v3.4.0-cleanup-complete)
216
- 2. Deploy to HF Spaces production (automatic via CI/CD)
217
- 3. Archive this PR as final cleanup documentation
218
- 4. Maintain tags for evaluator reference
219
-
220
- ---
221
-
222
- ## Impact on Project
223
-
224
- ### Before Cleanup
225
- - 11 redundant root files (duplicates of archived versions)
226
- - 5 sources for core documentation (API & Model)
227
- - Flat test directory (difficult to navigate)
228
- - 60% duplication in CI/CD workflow
229
- - Logs directory in root (not archived)
230
- - .vscode/ with personal IDE settings
231
-
232
- ### After Cleanup
233
- - 8 essential root files (clean)
234
- - 1 source for each documentation topic (single truth)
235
- - Hierarchical test organization (modular)
236
- - 20% duplication in CI/CD (67% improvement)
237
- - Logs archived in docs/ (preserved but organized)
238
- - .vscode/ removed (shared repo only)
239
-
240
- ---
241
-
242
- ## Conclusion
243
-
244
- This cleanup project has successfully transformed the OC_P5 Employee Turnover Prediction API from a functional project into a **professional, evaluator-ready codebase** with excellent organization, comprehensive documentation, and optimized CI/CD pipeline. All work has been completed without functional loss, with every change documented and validated through automated testing.
245
-
246
- **Status: โœ… READY FOR MERGE TO MAIN**
247
-
248
- ---
249
-
250
- *Prepared for: OpenClassrooms Evaluation*
251
- *Date: January 2, 2025*
252
- *All 8 cleanup sub-steps completed and validated*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
HF_DEPLOYMENT.md DELETED
@@ -1,168 +0,0 @@
1
- # Dรฉploiement sur HuggingFace Spaces
2
-
3
- ## Architecture dรฉployรฉe
4
-
5
- L'application lance **2 services simultanรฉment** :
6
-
7
- 1. **FastAPI** (port 8000) : API REST complรจte
8
- 2. **Gradio** (port 7860) : Interface web interactive
9
-
10
- ## URLs d'accรจs
11
-
12
- Sur HuggingFace Spaces, l'application sera accessible ร  :
13
-
14
- - **Interface Gradio** : `https://votre-space.hf.space/` (port public 7860)
15
- - **API FastAPI** : Accessible en interne via `http://localhost:8000`
16
-
17
- โš ๏ธ **Note importante** : HuggingFace Spaces n'expose publiquement que le port 7860 (Gradio). L'API FastAPI est accessible uniquement en interne ou via l'interface Gradio.
18
-
19
- ## Configuration requise sur HF Spaces
20
-
21
- ### 1. Variables d'environnement (Secrets)
22
-
23
- Dans les paramรจtres de votre Space, configurez ces secrets :
24
-
25
- ```bash
26
- API_KEY=votre-clรฉ-api-production
27
- DEBUG=false
28
- LOG_LEVEL=INFO
29
- GRADIO_ENABLED=true
30
- ```
31
-
32
- ### 2. Fichiers nรฉcessaires
33
-
34
- Ces fichiers doivent รชtre prรฉsents dans le repository :
35
-
36
- ```
37
- .
38
- โ”œโ”€โ”€ app.py # Lance FastAPI + Gradio
39
- โ”œโ”€โ”€ api.py # Code FastAPI
40
- โ”œโ”€โ”€ db_models.py # Modรจles BDD (optionnel sur HF)
41
- โ”œโ”€โ”€ pyproject.toml # Dรฉpendances Poetry
42
- โ”œโ”€โ”€ poetry.lock # Lock des versions
43
- โ”œโ”€โ”€ README.md # Documentation + metadata HF
44
- โ””โ”€โ”€ src/
45
- โ”œโ”€โ”€ __init__.py
46
- โ”œโ”€โ”€ auth.py
47
- โ”œโ”€โ”€ config.py
48
- โ”œโ”€โ”€ gradio_ui.py # Interface Gradio
49
- โ”œโ”€โ”€ logger.py
50
- โ”œโ”€โ”€ models.py
51
- โ”œโ”€โ”€ preprocessing.py
52
- โ”œโ”€โ”€ rate_limit.py
53
- โ””โ”€โ”€ schemas.py
54
- ```
55
-
56
- ### 3. Metadata HF dans README.md
57
-
58
- Assurez-vous que le header YAML dans `README.md` contient :
59
-
60
- ```yaml
61
- ---
62
- title: Employee Turnover Prediction API
63
- emoji: ๐Ÿš€
64
- colorFrom: blue
65
- colorTo: green
66
- sdk: gradio
67
- sdk_version: "5.9.1"
68
- app_file: app.py
69
- pinned: false
70
- ---
71
- ```
72
-
73
- ## Comment l'application dรฉmarre
74
-
75
- 1. `app.py` dรฉmarre FastAPI sur le port 8000 (background)
76
- 2. Attend que FastAPI soit opรฉrationnel (health check)
77
- 3. Lance Gradio sur le port 7860 (foreground)
78
- 4. Les deux services communiquent en interne
79
-
80
- ## Test local
81
-
82
- Pour tester localement avant dรฉploiement :
83
-
84
- ```bash
85
- # Activer l'environnement virtuel
86
- source .venv/bin/activate
87
-
88
- # Lancer l'application
89
- python app.py
90
- ```
91
-
92
- Puis accรฉdez ร  :
93
- - Gradio : http://localhost:7860
94
- - FastAPI : http://localhost:8000/docs
95
-
96
- ## Utilisation de l'API depuis l'extรฉrieur
97
-
98
- ### Option 1 : Via l'interface Gradio (recommandรฉ)
99
-
100
- Utilisez l'interface web directement sur `https://votre-space.hf.space/`
101
-
102
- ### Option 2 : Via l'API Gradio (pour scripts externes)
103
-
104
- Gradio expose automatiquement une API pour ses fonctions :
105
-
106
- ```python
107
- from gradio_client import Client
108
-
109
- client = Client("https://votre-space.hf.space/")
110
- result = client.predict(
111
- nombre_participation_pee=0,
112
- nb_formations_suivies=2,
113
- # ... autres paramรจtres
114
- api_name="/predict"
115
- )
116
- print(result)
117
- ```
118
-
119
- ### Option 3 : FastAPI (uniquement en local ou si proxy configurรฉ)
120
-
121
- L'API FastAPI n'est pas directement accessible depuis l'extรฉrieur sur HF Spaces.
122
-
123
- ## Dรฉpannage
124
-
125
- ### Le Space ne dรฉmarre pas
126
-
127
- 1. Vรฉrifiez les logs dans l'onglet "Logs" de HF Spaces
128
- 2. Vรฉrifiez que `pyproject.toml` et `poetry.lock` sont ร  jour
129
- 3. Vรฉrifiez que toutes les dรฉpendances sont installables
130
-
131
- ### FastAPI ne dรฉmarre pas
132
-
133
- - Vรฉrifiez que `uvicorn` est dans les dรฉpendances
134
- - Vรฉrifiez les logs pour les erreurs de port
135
- - Assurez-vous que le modรจle est bien tรฉlรฉchargeable depuis HF Hub
136
-
137
- ### Gradio ne rรฉpond pas
138
-
139
- - Vรฉrifiez que le port 7860 n'est pas bloquรฉ
140
- - Vรฉrifiez que `sdk: gradio` est bien dans le README
141
- - Vรฉrifiez que `app_file: app.py` pointe vers le bon fichier
142
-
143
- ## Logs et monitoring
144
-
145
- Les logs sont visibles dans l'onglet "Logs" de HF Spaces. Format :
146
-
147
- ```
148
- 2026-01-12 03:22:01,905 - INFO - ๐Ÿš€ Dรฉmarrage de l'application complรจte
149
- 2026-01-12 03:22:02,256 - INFO - [FastAPI] Application startup complete
150
- 2026-01-12 03:22:04,855 - INFO - โœ… FastAPI dรฉmarrรฉ et opรฉrationnel
151
- 2026-01-12 03:22:06,717 - INFO - ๐ŸŒ Lancement du serveur sur 0.0.0.0:7860...
152
- ```
153
-
154
- ## Mise ร  jour du dรฉploiement
155
-
156
- Pour mettre ร  jour l'application :
157
-
158
- 1. Committez vos changements sur GitHub
159
- 2. HF Spaces se synchronise automatiquement
160
- 3. Le Space redรฉmarre avec les nouveaux fichiers
161
- 4. Vรฉrifiez les logs pour confirmer le bon dรฉmarrage
162
-
163
- ## Support
164
-
165
- En cas de problรจme :
166
- 1. Consultez les logs HF Spaces
167
- 2. Testez localement avec `python app.py`
168
- 3. Vรฉrifiez la documentation : https://huggingface.co/docs/hub/spaces
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
HF_TROUBLESHOOTING.md DELETED
@@ -1,137 +0,0 @@
1
- # ๐Ÿ”ง Guide de Dรฉpannage - HuggingFace Spaces
2
-
3
- ## Erreur : "No module named 'slowapi'"
4
-
5
- ### Cause
6
- FastAPI n'a pas pu dรฉmarrer parce que la dรฉpendance `slowapi` n'a pas รฉtรฉ installรฉe lors du build Docker.
7
-
8
- ### Raisons possibles
9
- 1. **Cache de dรฉpendances** - HF Spaces a peut-รชtre mis en cache une ancienne version
10
- 2. **Installation incomplรจte** - Poetry n'a pas installรฉ toutes les dรฉpendances
11
- 3. **Timeout lors du build** - Le build a peut-รชtre expirรฉ
12
-
13
- ### Solutions (dans l'ordre)
14
-
15
- #### โœ… **Solution 1 : Factory Reboot (Recommandรฉ)**
16
-
17
- 1. Allez sur votre HF Space : https://huggingface.co/spaces/votre-username/oc-p5-dev
18
- 2. Cliquez sur **Settings** (โš™๏ธ)
19
- 3. Scrollez jusqu'ร  **"Reboot"**
20
- 4. Cliquez sur **"Factory reboot"**
21
- 5. Attendez 3-5 minutes que le Space se reconstruise
22
-
23
- Cela efface le cache et force HF ร  tรฉlรฉcharger toutes les dรฉpendances depuis zรฉro.
24
-
25
- #### โœ… **Solution 2 : Vรฉrifier que poetry.lock est ร  jour**
26
-
27
- Localement :
28
- ```bash
29
- cd /home/valentin/Env_Python/OC_P5
30
- poetry lock
31
- git add poetry.lock
32
- git commit -m "sync: update poetry.lock"
33
- git push origin main
34
- ```
35
-
36
- Attendez 2-3 minutes que HF Spaces se synchronise, puis attendez le rebuild.
37
-
38
- #### โœ… **Solution 3 : Ajouter une รฉtape de diagnostic dans le Dockerfile**
39
-
40
- Le Dockerfile a รฉtรฉ mis ร  jour pour vรฉrifier que les dรฉpendances critiques sont bien installรฉes :
41
-
42
- ```dockerfile
43
- RUN python -c "import slowapi; import fastapi; import gradio; print('All critical dependencies installed โœ“')"
44
- ```
45
-
46
- Si cette รฉtape รฉchoue, le build Docker รฉchouera immรฉdiatement avec un message clair.
47
-
48
- #### โœ… **Solution 4 : Forcer un build sans cache**
49
-
50
- Sur HF Spaces :
51
- 1. Settings โ†’ Advanced settings
52
- 2. Cochez l'option "Disable cache" ou similaire
53
- 3. Cliquez sur "Restart" ou "Rebuild"
54
-
55
- ## Symptรดmes et solutions
56
-
57
- ### Symptรดme : "Error: No API found"
58
-
59
- **Signifie** : Gradio dรฉmarre mais FastAPI n'a pas pu dรฉmarrer.
60
-
61
- **Solution** :
62
- 1. Vรฉrifiez les logs HF Spaces
63
- 2. Recherchez "ModuleNotFoundError: No module named 'slowapi'"
64
- 3. Si oui, appliquez "Solution 1" (Factory reboot)
65
-
66
- ### Symptรดme : "502 Bad Gateway"
67
-
68
- **Signifie** : Gradio n'a pas pu dรฉmarrer ou le port 7860 est occupรฉ.
69
-
70
- **Solution** :
71
- 1. Attendez 2-3 minutes (premier dรฉmarrage peut รชtre lent)
72
- 2. Appliquez "Solution 1" (Factory reboot)
73
- 3. Vรฉrifiez les logs pour les erreurs Gradio
74
-
75
- ### Symptรดme : "Connection refused" sur le health check
76
-
77
- **Signifie** : FastAPI a crashรฉ aprรจs son dรฉmarrage.
78
-
79
- **Solution** :
80
- 1. Cherchez "Traceback" dans les logs
81
- 2. Identifiez l'erreur Python
82
- 3. Corrigez le code et poussez une nouvelle version
83
-
84
- ## Vรฉrification locale
85
-
86
- Avant de dรฉployer, testez toujours localement :
87
-
88
- ```bash
89
- # Lancer le test complet
90
- ./test_deployment.sh
91
-
92
- # Ou tester individuellement
93
- poetry run uvicorn api:app --host 0.0.0.0 --port 8000 &
94
- python app.py
95
- ```
96
-
97
- ## Fichiers importants
98
-
99
- - `pyproject.toml` - Dรฉclare toutes les dรฉpendances
100
- - `poetry.lock` - Versions exactes des dรฉpendances (DOIT รชtre synchronisรฉ)
101
- - `src/Dockerfile` - Build image pour HF Spaces
102
- - `app.py` - Lance FastAPI + Gradio
103
-
104
- ## Logs ร  surveiller
105
-
106
- Sur HF Spaces, dans l'onglet "Logs", recherchez ces patterns :
107
-
108
- ```
109
- โœ“ "[FastAPI] Application startup complete" - FastAPI a dรฉmarrรฉ
110
- โœ“ "Running on local URL: http://0.0.0.0:7860" - Gradio a dรฉmarrรฉ
111
- โœ— "ModuleNotFoundError: No module named 'slowapi'" - Dรฉpendance manquante
112
- โœ— "Traceback" - Erreur Python
113
- ```
114
-
115
- ## Points clรฉs
116
-
117
- - `slowapi` est une dรฉpendance de **production** (en development dependencies)
118
- - `poetry.lock` DOIT รชtre ร  jour (gรฉnรฉrรฉ avec `poetry lock`)
119
- - HF Spaces peut mettre en cache โ†’ utiliser Factory reboot si nรฉcessaire
120
- - Le premier build peut prendre 5-10 minutes
121
-
122
- ## Questions frรฉquentes
123
-
124
- **Q : Pourquoi รงa fonctionne en local mais pas sur HF ?**
125
- A : Probablement un problรจme d'installation des dรฉpendances lors du build Docker. Utilisez Factory reboot.
126
-
127
- **Q : Combien de temps รงa prend ร  dรฉployer ?**
128
- A : Gรฉnรฉralement 3-10 minutes aprรจs un push sur GitHub.
129
-
130
- **Q : Pourquoi je vois "API not found" ?**
131
- A : FastAPI n'a pas dรฉmarrรฉ. Vรฉrifiez les logs pour "ModuleNotFoundError" ou "Traceback".
132
-
133
- ## Contact & Support
134
-
135
- - Documentation HF : https://huggingface.co/docs/hub/spaces
136
- - Documentation Gradio : https://gradio.app/docs/
137
- - Documentation FastAPI : https://fastapi.tiangolo.com/
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
QUICK_DEPLOY.md DELETED
@@ -1,139 +0,0 @@
1
- # Guide de dรฉploiement rapide sur HuggingFace Spaces
2
-
3
- ## โœ… Prรฉrequis
4
-
5
- Votre application est maintenant configurรฉe pour dรฉployer **FastAPI + Gradio** ensemble.
6
-
7
- ## ๐Ÿš€ Dรฉploiement en 3 รฉtapes
8
-
9
- ### ร‰tape 1 : Tester localement
10
-
11
- ```bash
12
- # Lancer le script de test
13
- ./test_deployment.sh
14
- ```
15
-
16
- Si tous les tests passent โœ…, passez ร  l'รฉtape 2.
17
-
18
- ### ร‰tape 2 : Commiter les changements
19
-
20
- ```bash
21
- # Voir les fichiers modifiรฉs
22
- git status
23
-
24
- # Ajouter tous les fichiers
25
- git add app.py src/Dockerfile HF_DEPLOYMENT.md test_deployment.sh QUICK_DEPLOY.md
26
-
27
- # Commiter
28
- git commit -m "Deploy: FastAPI + Gradio on HuggingFace Spaces"
29
-
30
- # Pousser sur GitHub
31
- git push origin main
32
- ```
33
-
34
- ### ร‰tape 3 : Synchroniser HuggingFace Spaces
35
-
36
- HuggingFace Spaces se synchronise automatiquement avec votre repo GitHub.
37
-
38
- 1. Allez sur https://huggingface.co/spaces/votre-username/votre-space
39
- 2. Cliquez sur l'onglet **"Settings"**
40
- 3. Dans "Repository", vรฉrifiez que le lien GitHub est configurรฉ
41
- 4. Le Space va se rebuilder automatiquement
42
- 5. Vรฉrifiez les logs dans l'onglet **"Logs"**
43
-
44
- ## ๐Ÿ“‹ Checklist de vรฉrification
45
-
46
- - [ ] Les tests locaux passent (`./test_deployment.sh`)
47
- - [ ] Le fichier `README.md` contient le header YAML avec `sdk: gradio`
48
- - [ ] Les dรฉpendances sont ร  jour dans `pyproject.toml`
49
- - [ ] Les secrets sont configurรฉs sur HF Spaces (API_KEY, DEBUG, etc.)
50
- - [ ] Le repository GitHub est synchronisรฉ
51
-
52
- ## ๐Ÿ” Vรฉrification aprรจs dรฉploiement
53
-
54
- Une fois le Space dรฉployรฉ, vรฉrifiez :
55
-
56
- 1. **Interface Gradio** : Accรฉdez ร  `https://votre-space.hf.space/`
57
- - Testez une prรฉdiction unitaire
58
- - Testez une prรฉdiction batch
59
-
60
- 2. **Logs** : Consultez les logs sur HF Spaces
61
- ```
62
- โœ… Recherchez ces messages :
63
- - "๐Ÿš€ Dรฉmarrage de l'application complรจte"
64
- - "[FastAPI] Application startup complete"
65
- - "โœ… FastAPI dรฉmarrรฉ et opรฉrationnel"
66
- - "๐ŸŒ Lancement du serveur sur 0.0.0.0:7860"
67
- ```
68
-
69
- 3. **API interne** : L'API FastAPI tourne en interne (non accessible publiquement)
70
-
71
- ## โš ๏ธ Problรจmes courants
72
-
73
- ### Le Space ne dรฉmarre pas
74
-
75
- **Symptรดmes** : Le Space affiche "Building" indรฉfiniment ou erreur au dรฉmarrage
76
-
77
- **Solutions** :
78
- 1. Vรฉrifiez les logs HF Spaces
79
- 2. Vรฉrifiez que `pyproject.toml` et `poetry.lock` sont synchronisรฉs
80
- 3. Vรฉrifiez que toutes les dรฉpendances sont installables
81
- 4. Essayez de rebuilder manuellement : Settings โ†’ Factory reboot
82
-
83
- ### FastAPI ne dรฉmarre pas
84
-
85
- **Symptรดmes** : Dans les logs, erreur au dรฉmarrage de uvicorn
86
-
87
- **Solutions** :
88
- 1. Vรฉrifiez que `uvicorn` est dans `pyproject.toml`
89
- 2. Vรฉrifiez que `api.py` est bien copiรฉ (voir `src/Dockerfile`)
90
- 3. Vรฉrifiez que le modรจle est tรฉlรฉchargeable depuis HF Hub
91
-
92
- ### Gradio ne rรฉpond pas
93
-
94
- **Symptรดmes** : "502 Bad Gateway" ou page blanche
95
-
96
- **Solutions** :
97
- 1. Vรฉrifiez que `sdk: gradio` est dans le header YAML du README
98
- 2. Vรฉrifiez que `app_file: app.py` pointe vers le bon fichier
99
- 3. Attendez 2-3 minutes (le premier dรฉmarrage est long)
100
-
101
- ### "API not found" dans l'interface
102
-
103
- **Symptรดmes** : L'interface s'affiche mais les prรฉdictions รฉchouent
104
-
105
- **Solutions** :
106
- 1. Vรฉrifiez que FastAPI a bien dรฉmarrรฉ (logs)
107
- 2. Vรฉrifiez que le port 8000 n'est pas bloquรฉ
108
- 3. Augmentez le temps d'attente dans `app.py` (ligne avec `sleep(5)`)
109
-
110
- ## ๐Ÿ”„ Mise ร  jour du Space
111
-
112
- Pour mettre ร  jour votre Space aprรจs modification :
113
-
114
- ```bash
115
- # 1. Modifier vos fichiers
116
- # 2. Commiter
117
- git add .
118
- git commit -m "Update: description des changements"
119
- git push origin main
120
-
121
- # 3. HF Spaces se met ร  jour automatiquement (1-2 minutes)
122
- ```
123
-
124
- ## ๐Ÿ“ž Support
125
-
126
- - Documentation HF : https://huggingface.co/docs/hub/spaces
127
- - Documentation Gradio : https://gradio.app/docs/
128
- - Documentation FastAPI : https://fastapi.tiangolo.com/
129
-
130
- ## ๐ŸŽ‰ Vous รชtes prรชt !
131
-
132
- Votre application est maintenant prรชte ร  รชtre dรฉployรฉe avec :
133
- - โœ… API REST complรจte (FastAPI)
134
- - โœ… Interface web interactive (Gradio)
135
- - โœ… Prรฉdictions unitaires et batch
136
- - โœ… Documentation automatique
137
- - โœ… Monitoring et logs
138
-
139
- Bon dรฉploiement ! ๐Ÿš€
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
exemples/GUIDE_DEMO.txt DELETED
@@ -1,89 +0,0 @@
1
- โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
2
- โ•‘ โ•‘
3
- โ•‘ ๐Ÿš€ GUIDE Dร‰MONSTRATION - Employee Turnover API โ•‘
4
- โ•‘ Par dรฉfaut : API locale http://127.0.0.1:7860 โ•‘
5
- โ•‘ โ•‘
6
- โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
7
-
8
- โš™๏ธ CONFIGURATION DE L'URL
9
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
10
- Par dรฉfaut, les scripts utilisent l'API locale : http://127.0.0.1:7860
11
-
12
- Pour utiliser l'API Hugging Face Spaces, utilisez les scripts dรฉdiรฉs :
13
- - demo_unitaire_hf.py
14
- - demo_batch_hf.py
15
-
16
- Optionnel : surcharger l'URL via la variable d'environnement :
17
- HF_API_URL="https://asi-engineer-oc-p5.hf.space"
18
- Optionnel : si la Space protรจge les endpoints, ajouter une API key :
19
- HF_API_KEY="votre-cle"
20
-
21
- Si FastAPI n'est pas exposรฉ sur la Space, le script batch tentera automatiquement l'API Gradio `/api/predict_batch` (nรฉcessite l'onglet Batch activรฉ dans l'interface).
22
-
23
- ๐Ÿ“‹ INSTALLATION (une seule fois)
24
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
25
- pip install requests pandas
26
-
27
-
28
- ๐Ÿš€ LANCER L'API LOCALE (nรฉcessaire pour la dรฉmo)
29
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
30
- ./lancer_api.sh
31
-
32
- Ou manuellement depuis le dossier racine :
33
- cd ..
34
- poetry run uvicorn api:app --host 127.0.0.1 --port 7860
35
-
36
- L'API sera accessible sur http://127.0.0.1:7860
37
-
38
-
39
- ๐Ÿ”ฎ Dร‰MO 1 : PRร‰DICTION UNITAIRE (1 employรฉ)
40
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
41
- python demo_unitaire.py
42
-
43
- โ†’ Le script pose des questions sur l'employรฉ
44
- โ†’ Affiche directement le rรฉsultat de prรฉdiction
45
-
46
-
47
- ๐Ÿ“ฆ Dร‰MO 2 : PRร‰DICTION BATCH (plusieurs employรฉs)
48
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
49
- python demo_batch.py
50
-
51
- โ†’ Demande 3 fichiers CSV (sondage, eval, sirh)
52
- โ†’ Gรฉnรจre un fichier CSV avec tous les rรฉsultats
53
- โ†’ Nom du fichier : predictions_batch_YYYYMMDD_HHMMSS.csv
54
-
55
-
56
- โœ… TEST RAPIDE (avec fichiers d'exemple fournis)
57
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
58
- Quand demo_batch.py demande si vous voulez utiliser les fichiers
59
- d'exemple, tapez simplement "O" ou appuyez sur Entrรฉe.
60
-
61
- Les 3 fichiers d'exemple (10 employรฉs) seront utilisรฉs automatiquement :
62
- - 02_predict_batch_sondage.csv
63
- - 02_predict_batch_eval.csv
64
- - 02_predict_batch_sirh.csv
65
-
66
-
67
- ๐ŸŽฏ JOUR J - CHECKLIST
68
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
69
- โ–ก Lancer l'API locale : poetry run uvicorn api:app --host 127.0.0.1 --port 7860
70
- (depuis le dossier racine du projet, ou ./lancer_api.sh depuis exemples/)
71
- โ–ก Ou configurer l'URL HF Spaces dans les scripts
72
- (via HF_API_URL avec demo_unitaire_hf.py / demo_batch_hf.py)
73
- โ–ก Prรฉparer les 3 fichiers CSV batch si nรฉcessaire
74
- โ–ก Tester : python demo_batch.py
75
- โ–ก Vรฉrifier le CSV de sortie est bien gรฉnรฉrรฉ
76
-
77
-
78
- ๐Ÿ“„ FICHIERS DANS CE DOSSIER
79
- โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
80
- lancer_api.sh โ†’ Lance l'API locale facilement
81
- demo_unitaire.py โ†’ Script dรฉmo prรฉdiction 1 employรฉ
82
- demo_batch.py โ†’ Script dรฉmo prรฉdiction batch
83
- demo_unitaire_hf.py โ†’ Script dรฉmo unitaire via Hugging Face
84
- demo_batch_hf.py โ†’ Script dรฉmo batch via Hugging Face
85
- 02_predict_batch_*.csv โ†’ Fichiers d'exemple (10 employรฉs)
86
- README.md โ†’ Documentation dรฉtaillรฉe
87
-
88
-
89
- C'EST TOUT ! ๐ŸŽ‰
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
exemples/README.md DELETED
@@ -1,138 +0,0 @@
1
- # ๐Ÿš€ Dร‰MONSTRATION API Employee Turnover
2
-
3
- **Par dรฉfaut** : API locale `http://127.0.0.1:7860`
4
- **Production** : Hugging Face Spaces `https://asi-engineer-oc-p5.hf.space`
5
-
6
- ## โš™๏ธ Configuration
7
-
8
- Les scripts locaux utilisent par dรฉfaut l'API locale. Pour la Space Hugging Face, des scripts dรฉdiรฉs sont fournis et acceptent `HF_API_URL` comme variable d'environnement.
9
-
10
- ## ๐Ÿ“‹ Installation
11
-
12
- ```bash
13
- pip install requests pandas
14
- ```
15
-
16
- ## ๐Ÿš€ Lancer l'API locale
17
-
18
- **Option 1** : Script automatique
19
- ```bash
20
- ./lancer_api.sh
21
- ```
22
-
23
- **Option 2** : Commande manuelle
24
- ```bash
25
- cd .. # Retour au dossier racine
26
- poetry run uvicorn api:app --host 127.0.0.1 --port 7860
27
- ```
28
-
29
- L'API sera disponible sur `http://127.0.0.1:7860`
30
-
31
- ## ๐Ÿ”ฎ Prรฉdiction UNITAIRE (1 employรฉ)
32
-
33
- **Usage ultra-simple** : Le script pose toutes les questions une par une.
34
-
35
- ```bash
36
- python demo_unitaire.py
37
- ```
38
-
39
- Le script demande les informations de l'employรฉ, interroge l'API et affiche le rรฉsultat immรฉdiatement.
40
-
41
- **Exemple de sortie** :
42
- ```
43
- ๐Ÿ“Š Rร‰SULTAT
44
- โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
45
- โœ… PRร‰DICTION: L'EMPLOYร‰ VA RESTER
46
- ๐ŸŽฏ Niveau de risque: Low
47
- Probabilitรฉ de rester: 85.2%
48
- Probabilitรฉ de partir: 14.8%
49
- ```
50
-
51
- ---
52
-
53
- ## ๐Ÿ“ฆ Prรฉdiction BATCH (fichiers CSV)
54
-
55
- **Usage ultra-simple** : Fournit 3 fichiers CSV, obtient 1 CSV de rรฉsultats.
56
-
57
- ```bash
58
- python demo_batch.py
59
- ```
60
-
61
- Le script demande les chemins des 3 fichiers CSV :
62
- 1. Fichier sondage
63
- 2. Fichier รฉvaluation
64
- 3. Fichier SIRH
65
-
66
- **Il gรฉnรจre automatiquement** : `predictions_batch_YYYYMMDD_HHMMSS.csv` dans le dossier courant.
67
-
68
- **Exemple de sortie** :
69
- ```
70
- ๐Ÿ“Š Rร‰SUMร‰
71
- โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
72
- โœ… Employรฉs qui vont RESTER: 8
73
- ๐Ÿƒ Employรฉs qui vont PARTIR: 2
74
- ๐Ÿ”ด Risque ร‰LEVร‰: 1
75
- ๐ŸŸก Risque MOYEN: 2
76
- ๐ŸŸข Risque FAIBLE: 7
77
-
78
- ๐Ÿ’พ Rรฉsultats sauvegardรฉs dans: predictions_batch_20260111_234530.csv
79
- ```
80
-
81
- ---
82
-
83
- ## โ˜๏ธ Utiliser l'API Hugging Face (Space)
84
-
85
- Deux scripts ciblent directement la Space HF:
86
-
87
- ```bash
88
- python demo_unitaire_hf.py
89
- python demo_batch_hf.py
90
- ```
91
-
92
- Optionnel: surcharger l'URL via `HF_API_URL`:
93
-
94
- ```bash
95
- HF_API_URL="https://asi-engineer-oc-p5.hf.space" python demo_batch_hf.py
96
- ```
97
-
98
- Optionnel: si la Space protรจge les endpoints, ajouter une API key:
99
-
100
- ```bash
101
- HF_API_KEY="votre-cle" python demo_unitaire_hf.py
102
- HF_API_KEY="votre-cle" python demo_batch_hf.py
103
- ```
104
-
105
- Note: si la Space n'expose pas FastAPI, le script batch basculera automatiquement sur l'API Gradio (`/api/predict_batch`) si l'onglet Batch est activรฉ. Sinon, utilisez l'API locale avec `lancer_api.sh`.
106
-
107
- ---
108
-
109
- ## ๐Ÿ“‚ Fichiers d'exemple fournis
110
-
111
- Pour tester rapidement, 4 fichiers d'exemple sont fournis :
112
-
113
- - **`01_predict_single_employee.json`** - Exemple d'employรฉ pour test unitaire
114
- - **`02_predict_batch_sondage.csv`** - 10 employรฉs (donnรฉes sondage)
115
- - **`02_predict_batch_eval.csv`** - 10 employรฉs (donnรฉes รฉvaluation)
116
- - **`02_predict_batch_sirh.csv`** - 10 employรฉs (donnรฉes SIRH)
117
-
118
- **Utilisation** : Indiquez simplement ces chemins quand `demo_batch.py` vous les demande.
119
-
120
- ---
121
-
122
- ## ๐ŸŽฏ Jour J - Checklist
123
-
124
- 1. โœ… Installer les dรฉpendances : `pip install requests pandas`
125
- 2. โœ… Tester unitaire : `python demo_unitaire.py`
126
- 3. โœ… Tester batch : `python demo_batch.py` (utiliser les fichiers `02_predict_batch_*.csv`)
127
- 4. โœ… Vรฉrifier que les CSV de rรฉsultats sont gรฉnรฉrรฉs
128
-
129
- **C'est tout !** ๐ŸŽ‰
130
-
131
- ---
132
-
133
- ## ๐Ÿ“– Documentation complรจte
134
-
135
- Pour plus d'informations sur l'API, les formats de donnรฉes, etc., voir :
136
- - [API Documentation](../docs/api_documentation.md)
137
- - [Architecture](../docs/architecture.md)
138
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
exemples/lancer_api.sh DELETED
@@ -1,44 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # ๐Ÿš€ Script de lancement de l'API locale pour la dรฉmo
4
- #
5
- # Usage: ./lancer_api.sh
6
- #
7
-
8
- cd "$(dirname "$0")/.."
9
-
10
- echo "โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—"
11
- echo "โ•‘ ๐Ÿš€ Lancement de l'API Employee Turnover โ•‘"
12
- echo "โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•"
13
- echo ""
14
-
15
- # Vรฉrifier que poetry est installรฉ
16
- if ! command -v poetry &> /dev/null; then
17
- echo "โŒ poetry n'est pas installรฉ"
18
- echo " Installation : pip install poetry"
19
- exit 1
20
- fi
21
-
22
- # Vรฉrifier que le fichier api.py existe
23
- if [ ! -f "api.py" ]; then
24
- echo "โŒ Fichier api.py introuvable"
25
- echo " Assurez-vous d'รชtre dans le bon dossier"
26
- exit 1
27
- fi
28
-
29
- echo "โœ… Dรฉmarrage de l'API sur http://127.0.0.1:7860"
30
- echo ""
31
- echo "๐Ÿ“– Documentation disponible sur:"
32
- echo " - http://127.0.0.1:7860/docs (Swagger)"
33
- echo " - http://127.0.0.1:7860/redoc (ReDoc)"
34
- echo ""
35
- echo "๐Ÿ”ฎ Interface Gradio (si activรฉe):"
36
- echo " - http://127.0.0.1:7860/"
37
- echo ""
38
- echo "๐Ÿ’ก Pour arrรชter l'API : Ctrl+C"
39
- echo ""
40
- echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”"
41
- echo ""
42
-
43
- # Lancer l'API avec poetry en mode DEBUG (sans API key)
44
- DEBUG=True poetry run uvicorn api:app --host 127.0.0.1 --port 7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
exemples/{predictions_batch_20260111_235739.csv โ†’ predictions_batch_20260112_043228.csv} RENAMED
File without changes
exemples/predictions_batch_hf_20260112_043238.csv ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ๏ปฟemployee_id,prediction,prediction_code,risk_level,probability_stay,probability_leave
2
+ 1,VA PARTIR,1,High,16.41%,83.59%
3
+ 2,VA RESTER,0,Low,88.46%,11.54%
4
+ 3,VA PARTIR,1,Medium,35.19%,64.81%
5
+ 4,VA PARTIR,1,High,24.39%,75.61%
6
+ 5,VA PARTIR,1,Medium,32.16%,67.84%
7
+ 6,VA RESTER,0,Low,95.30%,4.70%
8
+ 7,VA RESTER,0,Low,81.61%,18.39%
9
+ 8,VA PARTIR,1,High,20.77%,79.23%
10
+ 9,VA RESTER,0,Low,96.22%,3.78%
11
+ 10,VA RESTER,0,Low,92.47%,7.53%