sekpona kokou commited on
Commit
e2fccf2
·
1 Parent(s): cf3b8a9

Rewrite README in English

Browse files
Files changed (1) hide show
  1. README.md +71 -71
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Data Analyst Mcp
3
  emoji: 🚀
4
  colorFrom: green
5
  colorTo: purple
@@ -7,58 +7,58 @@ sdk: gradio
7
  sdk_version: 6.12.0
8
  app_file: app.py
9
  pinned: false
10
- short_description: Analyse and generate stats and graphs from sql database
11
  ---
12
 
13
  # Data Analyst agent with MCP
14
 
15
- Assistant data orienté analyse de table `surveyData`, avec génération automatique de graphiques.
16
 
17
- ## Ce que fait l’app
18
 
19
- - Pose des questions en langage naturel sur les données du survey.
20
- - Exécute les requêtes via des tools MCP.
21
- - Génère des graphiques (`bar`, `pie`, `line`) quand c’est pertinent.
22
- - Affiche les résultats dans une interface Gradio compatible Hugging Face Spaces.
23
 
24
- ## Stack technique
25
 
26
  - Python 3.11+
27
  - [Gradio 6.12.0](https://www.gradio.app/)
28
- - `smolagents` + client MCP (transport SSE)
29
- - Azure OpenAI (modèle configurable)
30
- - `matplotlib` + `seaborn` pour les charts
31
 
32
- ## Structure du projet
33
 
34
  ```text
35
  .
36
- ├── app.py # UI Gradio + orchestration agent
37
- ├── tools.py # Tool local generate_chart(...)
38
- ├── prompt.py # Instructions système de l’agent
39
- ├── charts/ # Images PNG générées
40
  ├── requirements.txt
41
  └── README.md
42
  ```
43
 
44
- ## Pré-requis
45
 
46
- - Un endpoint MCP accessible en SSE.
47
- - Un déploiement Azure OpenAI configuré.
48
- - Un fichier `.env` (au niveau parent du dossier projet, comme dans le code actuel).
49
 
50
- ## Variables d’environnement
51
 
52
- Variables utilisées par `app.py` :
53
 
54
- - `MCP_SERVER_URL` (ex: `https://.../gradio_api/mcp/sse`)
55
  - `AZURE_OPENAI_ENDPOINT`
56
  - `AZURE_OPENAI_API_KEY`
57
- - `AZURE_OPENAI_API_VERSION` (défaut: `2024-12-01-preview`)
58
- - `AZURE_OPENAI_MODEL` (défaut: `gpt-4o`)
59
- - `PORT` (défaut: `7860`)
60
 
61
- Exemple `.env` minimal :
62
 
63
  ```env
64
  MCP_SERVER_URL=https://your-mcp-server/gradio_api/mcp/sse
@@ -68,7 +68,7 @@ AZURE_OPENAI_API_VERSION=2024-12-01-preview
68
  AZURE_OPENAI_MODEL=gpt-4o
69
  ```
70
 
71
- ## Installation locale
72
 
73
  ```bash
74
  python3 -m venv venv
@@ -77,83 +77,83 @@ pip install -r requirements.txt
77
  python app.py
78
  ```
79
 
80
- Puis ouvrir `http://localhost:7860`.
81
 
82
- ## Déploiement Hugging Face Spaces
83
 
84
- Ce repo est déjà configuré en Space Gradio via le front-matter en haut du README.
85
 
86
- Workflow simple :
87
 
88
- 1. Modifier le code.
89
- 2. Commit sur `main`.
90
- 3. Push vers le remote Space:
91
 
92
  ```bash
93
  git push origin main
94
  ```
95
 
96
- Le Space rebuild automatiquement.
97
 
98
- ## Logique fonctionnelle (résumé)
99
 
100
- 1. L’utilisateur pose une question.
101
- 2. `ToolCallingAgent` appelle les tools MCP (et `generate_chart` si utile).
102
- 3. Si un chart est généré, il est encodé en base64 et affiché inline.
103
- 4. La réponse texte de l’agent est affichée dans le chat.
104
 
105
- ## Prompting / règles data importantes
106
 
107
- Dans `prompt.py`, une contrainte est imposée:
108
 
109
- - la table SQL cible est **toujours** `"surveyData"` (avec `D` majuscule)
110
 
111
- Si le backend SQL évolue, commence par mettre à jour cette partie.
112
 
113
- ## Exemples de questions utiles
114
 
115
- - `Le nombre de questions qu'on a`
116
  - `Sub-options per question`
117
  - `Distribution by question type`
118
  - `Top 5 questions by number of sub options`
119
- - `Pourcentage de répartition des questions`
120
 
121
- ## Dépannage
122
 
123
  ### 1) `SSE Stream ended` / `httpx.ConnectError`
124
 
125
- Cause fréquente: endpoint MCP inaccessible (URL fausse, serveur en sleep, problème réseau).
126
 
127
- À vérifier:
128
 
129
- - `MCP_SERVER_URL` correct
130
- - endpoint joignable depuis l’environnement de déploiement
131
- - serveur MCP bien démarré
132
 
133
- ### 2) Erreurs Gradio au startup
134
 
135
- Exemples déjà rencontrés:
136
 
137
- - argument `type` non supporté sur `gr.Chatbot`
138
- - argument `bubble_full_width` non supporté
139
 
140
- Si ça revient, vérifie la version exacte de Gradio dans `requirements.txt` et adapte les paramètres du composant.
141
 
142
- ### 3) Interface qui s’allonge à l’infini dans Space
143
 
144
- Le projet utilise désormais un layout Gradio natif + CSS minimal pour éviter ce bug d’iframe HF.
145
 
146
- ### 4) Aucune clé API Azure
147
 
148
- Sans `AZURE_OPENAI_API_KEY`, l’agent ne peut pas répondre.
149
- Vérifie les Secrets dans Space Settings.
150
 
151
- ## Notes de maintenance
152
 
153
- - Les images de charts sont stockées dans `charts/`.
154
- - `generate_chart` crée des PNG avec un nom dérivé du titre.
155
- - Si besoin de nettoyage disque, supprimer périodiquement les anciens fichiers dans `charts/`.
156
 
157
- ## Référence utile
158
 
159
- - Config Spaces: https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Data Analyst MCP
3
  emoji: 🚀
4
  colorFrom: green
5
  colorTo: purple
 
7
  sdk_version: 6.12.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: Analyze survey data and generate stats and charts from SQL
11
  ---
12
 
13
  # Data Analyst agent with MCP
14
 
15
+ A data analysis assistant focused on the `surveyData` table, with automatic chart generation.
16
 
17
+ ## What this app does
18
 
19
+ - Answers natural-language questions about survey data.
20
+ - Runs data queries through MCP tools.
21
+ - Generates charts (`bar`, `pie`, `line`) when useful.
22
+ - Displays results in a Gradio UI that works well on Hugging Face Spaces.
23
 
24
+ ## Tech stack
25
 
26
  - Python 3.11+
27
  - [Gradio 6.12.0](https://www.gradio.app/)
28
+ - `smolagents` + MCP client (SSE transport)
29
+ - Azure OpenAI (configurable model)
30
+ - `matplotlib` + `seaborn` for charts
31
 
32
+ ## Project structure
33
 
34
  ```text
35
  .
36
+ ├── app.py # Gradio UI + agent orchestration
37
+ ├── tools.py # Local tool: generate_chart(...)
38
+ ├── prompt.py # Agent system instructions
39
+ ├── charts/ # Generated PNG files
40
  ├── requirements.txt
41
  └── README.md
42
  ```
43
 
44
+ ## Prerequisites
45
 
46
+ - An MCP endpoint reachable over SSE.
47
+ - An Azure OpenAI deployment.
48
+ - A `.env` file (currently loaded from the parent directory of this project).
49
 
50
+ ## Environment variables
51
 
52
+ Used by `app.py`:
53
 
54
+ - `MCP_SERVER_URL` (example: `https://.../gradio_api/mcp/sse`)
55
  - `AZURE_OPENAI_ENDPOINT`
56
  - `AZURE_OPENAI_API_KEY`
57
+ - `AZURE_OPENAI_API_VERSION` (default: `2024-12-01-preview`)
58
+ - `AZURE_OPENAI_MODEL` (default: `gpt-4o`)
59
+ - `PORT` (default: `7860`)
60
 
61
+ Minimal `.env` example:
62
 
63
  ```env
64
  MCP_SERVER_URL=https://your-mcp-server/gradio_api/mcp/sse
 
68
  AZURE_OPENAI_MODEL=gpt-4o
69
  ```
70
 
71
+ ## Run locally
72
 
73
  ```bash
74
  python3 -m venv venv
 
77
  python app.py
78
  ```
79
 
80
+ Then open `http://localhost:7860`.
81
 
82
+ ## Deploy to Hugging Face Spaces
83
 
84
+ This repository is already configured as a Gradio Space through the front-matter at the top of this README.
85
 
86
+ Simple workflow:
87
 
88
+ 1. Make your code changes.
89
+ 2. Commit on `main`.
90
+ 3. Push to the Space remote:
91
 
92
  ```bash
93
  git push origin main
94
  ```
95
 
96
+ The Space rebuilds automatically.
97
 
98
+ ## Runtime flow (high level)
99
 
100
+ 1. User asks a question.
101
+ 2. `ToolCallingAgent` calls MCP tools (and `generate_chart` when relevant).
102
+ 3. If a chart is generated, it is encoded in base64 and rendered inline.
103
+ 4. The assistant answer is shown in chat.
104
 
105
+ ## Prompting / important data rule
106
 
107
+ In `prompt.py`, one strict rule is enforced:
108
 
109
+ - the SQL table is always **`"surveyData"`** (capital `D`)
110
 
111
+ If your SQL backend changes, update this part first.
112
 
113
+ ## Useful example questions
114
 
115
+ - `How many questions do we have?`
116
  - `Sub-options per question`
117
  - `Distribution by question type`
118
  - `Top 5 questions by number of sub options`
119
+ - `Percentage distribution of questions`
120
 
121
+ ## Troubleshooting
122
 
123
  ### 1) `SSE Stream ended` / `httpx.ConnectError`
124
 
125
+ Common cause: MCP endpoint is unreachable (wrong URL, sleeping service, network issue).
126
 
127
+ Check:
128
 
129
+ - `MCP_SERVER_URL` is correct
130
+ - endpoint is reachable from the deployment environment
131
+ - MCP server is actually running
132
 
133
+ ### 2) Gradio startup errors
134
 
135
+ Examples already encountered:
136
 
137
+ - unsupported `type` argument on `gr.Chatbot`
138
+ - unsupported `bubble_full_width` argument
139
 
140
+ If this happens again, confirm the Gradio version in `requirements.txt` and align component parameters accordingly.
141
 
142
+ ### 3) UI page growing infinitely on Spaces
143
 
144
+ The app now uses a native Gradio layout + minimal CSS to avoid iframe-related layout issues.
145
 
146
+ ### 4) Missing Azure key
147
 
148
+ Without `AZURE_OPENAI_API_KEY`, the assistant cannot answer.
149
+ Set it in Space Settings > Secrets.
150
 
151
+ ## Maintenance notes
152
 
153
+ - Generated charts are stored in `charts/`.
154
+ - `generate_chart` saves PNG files with a title-derived filename.
155
+ - If needed, clean old files in `charts/` periodically.
156
 
157
+ ## Helpful reference
158
 
159
+ - Spaces config docs: https://huggingface.co/docs/hub/spaces-config-reference