Skip to content

Commit 5a5efc3

Browse files
authored
Merge pull request #9 from SalimM21/SALIM
Documentation 1
2 parents fb0f709 + d7f0d75 commit 5a5efc3

1 file changed

Lines changed: 134 additions & 0 deletions

File tree

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,136 @@
11
# SentimentAPI_HuggingFaceProject
22
Développement d’une API d’analyse de sentiments recevant un texte et retournant, automatiquement et clairement, un résultat positif ou négatif accompagné d’un score de confiance. L’API est conteneurisée (Docker) et déployée publiquement en ligne sur Hugging Face Spaces ; une page HTML minimale permet de la tester rapidement.
3+
4+
# 🚀 Sentiment Analysis API (FastAPI + Hugging Face)
5+
6+
Cette application fournit une **API REST** et une **page web de test** pour analyser le sentiment (positif/négatif) d’un texte en utilisant un modèle Hugging Face (`distilbert-base-uncased-finetuned-sst-2-english`).
7+
8+
---
9+
10+
## 📂 Structure du projet
11+
12+
```
13+
├── app/
14+
│ ├── main.py # Application FastAPI
15+
│ └── static/
16+
│ └── index.html # Page test frontend
17+
├── requirements.txt # Dépendances Python
18+
├── Dockerfile # Image Docker
19+
├── README.md # Documentation
20+
```
21+
22+
---
23+
24+
## ⚙️ Installation locale
25+
26+
### 1. Créer un environnement virtuel
27+
```bash
28+
python3 -m venv venv
29+
source venv/bin/activate
30+
```
31+
32+
### 2. Installer les dépendances
33+
```bash
34+
pip install --upgrade pip
35+
pip install -r requirements.txt
36+
```
37+
38+
### 3. Lancer l’API
39+
```bash
40+
uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
41+
```
42+
43+
---
44+
45+
## 🐳 Déploiement avec Docker
46+
47+
### 1. Construire l’image
48+
```bash
49+
docker build -t sentiment-api .
50+
```
51+
52+
### 2. Lancer le conteneur
53+
```bash
54+
docker run -p 8000:8000 sentiment-api
55+
```
56+
57+
L’API sera accessible sur :
58+
👉 [http://localhost:8000](http://localhost:8000)
59+
60+
---
61+
62+
## 🌐 Déploiement sur Hugging Face Spaces
63+
64+
### 1. Créer un nouveau Space
65+
- Aller sur [Hugging Face Spaces](https://huggingface.co/spaces)
66+
- Créer un espace **type Docker**
67+
- Uploader les fichiers du projet (`app/`, `requirements.txt`, `Dockerfile`, `README.md`)
68+
69+
### 2. Configurer le cache Hugging Face
70+
Le code utilise un dossier **accessible en écriture** pour le cache :
71+
```python
72+
CACHE_DIR = "/tmp/hf_cache"
73+
os.environ["TRANSFORMERS_CACHE"] = CACHE_DIR
74+
os.makedirs(CACHE_DIR, exist_ok=True)
75+
```
76+
77+
Cela évite l’erreur `PermissionError: /.cache`.
78+
79+
### 3. Build & Run
80+
Une fois le Space lancé, Hugging Face va automatiquement :
81+
- Construire l’image Docker
82+
- Démarrer l’API FastAPI
83+
- Fournir un endpoint public
84+
85+
---
86+
87+
## 📡 Endpoints disponibles
88+
89+
### 🔹 Health Check
90+
```
91+
GET /health
92+
```
93+
**Réponse :**
94+
```json
95+
{ "status": "ok", "model": "distilbert-base-uncased-finetuned-sst-2-english" }
96+
```
97+
98+
### 🔹 Prédiction de sentiment
99+
```
100+
POST /predict
101+
```
102+
**Entrée :**
103+
```json
104+
{ "text": "I love FastAPI and Hugging Face!" }
105+
```
106+
107+
**Sortie :**
108+
```json
109+
{
110+
"label": "positive",
111+
"confidence": 0.9998,
112+
"model": "distilbert-base-uncased-finetuned-sst-2-english"
113+
}
114+
```
115+
116+
---
117+
118+
## 🖼️ Page de test (Frontend)
119+
120+
L’application expose aussi une **page HTML minimaliste** :
121+
👉 [http://localhost:8000/static/index.html](http://localhost:8000/static/index.html)
122+
123+
---
124+
125+
## ✅ TODO
126+
127+
- [ ] Ajouter un modèle multilingue (par ex. `nlptown/bert-base-multilingual-uncased-sentiment`)
128+
- [ ] Ajouter une UI Gradio pour la démo
129+
- [ ] Intégrer des tests unitaires
130+
131+
---
132+
133+
## 📜 Licence
134+
135+
Ce projet est sous licence MIT.
136+
Le modèle appartient à Hugging Face et ses contributeurs.

0 commit comments

Comments
 (0)