NathMen12 commited on
Commit
b8ae72a
Β·
verified Β·
1 Parent(s): 51a8d37

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +346 -4
README.md CHANGED
@@ -1,10 +1,352 @@
1
  ---
2
- title: Mindcraft
3
- emoji: πŸ‘€
4
  colorFrom: purple
5
  colorTo: gray
6
  sdk: docker
7
- pinned: false
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Translator-API
3
+ emoji: πŸ’»
4
  colorFrom: purple
5
  colorTo: gray
6
  sdk: docker
7
+ pinned: true
8
  ---
9
 
10
+ # 🌐 Translator API
11
+
12
+ > **Alternative gratuite Γ  Google Translate** β€” API REST sans clΓ©, auto-hΓ©bergΓ©e, avec dashboard admin temps rΓ©el.
13
+
14
+ [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
15
+ [![Docker](https://img.shields.io/badge/Docker-ready-blue.svg)](https://docker.com/)
16
+ [![License](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
17
+
18
+ ---
19
+
20
+ ## ✨ Fonctionnalités
21
+
22
+ | FonctionnalitΓ© | Description |
23
+ |---|---|
24
+ | πŸ†“ **Gratuit & Sans clΓ© API** | Pas d'inscription, pas de quota mensuel |
25
+ | ⚑ **Rate limiting** | 30 requΓͺtes/minute par IP |
26
+ | 🌍 **100+ langues** | Support complet ISO 639-1 + détection auto |
27
+ | πŸ“Š **Dashboard Admin** | MΓ©triques CPU/RAM temps rΓ©el, logs, graphiques 120s |
28
+ | βš–οΈ **Architecture distribuΓ©e** | Central (API + 1 core) + Workers (1 core) |
29
+ | πŸ” **Auth admin sΓ©curisΓ©e** | Code d'accΓ¨s via variables d'environnement |
30
+ | 🐳 **Docker ready** | Déploiement 1-click sur HuggingFace Spaces |
31
+ | πŸ“š **Wiki intΓ©grΓ©** | Exemples JS, Python, Java, cURL |
32
+
33
+ ---
34
+
35
+ ## πŸš€ DΓ©marrage rapide
36
+
37
+ ### Option 1 : Docker Compose (RecommandΓ©)
38
+
39
+ ```bash
40
+ # 1. Cloner le repo
41
+ git clone https://github.com/NathMen12/Translator-API.git
42
+ cd Translator-API
43
+
44
+ # 2. Configurer les secrets
45
+ cp .env.example .env
46
+ # Γ‰diter .env avec votre ADMIN_ACCESS_CODE
47
+
48
+ # 3. Lancer
49
+ docker-compose up -d
50
+
51
+ # 4. AccΓ©der Γ  l'API
52
+ curl -X POST http://localhost:7820/translate \
53
+ -H "Content-Type: application/json" \
54
+ -d '{"text": "Bonjour le monde", "source": "fr", "target": "en"}'
55
+ ```
56
+
57
+ ### Option 2 : DΓ©veloppement local
58
+
59
+ ```bash
60
+ # Installer les dΓ©pendances
61
+ npm install
62
+
63
+ # Lancer le central (terminal 1)
64
+ npm run dev:central
65
+
66
+ # Lancer le worker (terminal 2)
67
+ npm run dev:worker
68
+
69
+ # Test
70
+ curl -X POST http://localhost:7820/translate \
71
+ -H "Content-Type: application/json" \
72
+ -d '{"text": "Hello", "target": "fr"}'
73
+ ```
74
+
75
+ ---
76
+
77
+ ## 🌐 Déploiement sur HuggingFace Spaces
78
+
79
+ 1. **Fork ce repo** sur votre GitHub
80
+ 2. **CrΓ©ez un Space** sur [huggingface.co/new-space](https://huggingface.co/new-space)
81
+ - SDK: **Docker**
82
+ - Hardware: **CPU Basic (2 vCPU, 16 GB RAM)** βœ…
83
+ - Visibility: Public ou Private
84
+ 3. **Ajoutez les Secrets** dans Settings β†’ Repository secrets :
85
+ - `ADMIN_ACCESS_CODE` = votre mot de passe admin fort
86
+ - `TAILSCALE_API_KEY` = (optionnel) pour dΓ©couverte workers
87
+ 4. **Push** β†’ Le Space build et dΓ©ploie automatiquement !
88
+
89
+ > ⚠️ Le port **7820** est exposé. HuggingFace Spaces mappe automatiquement sur le port 7860 en externe.
90
+
91
+ ---
92
+
93
+ ## πŸ“– Utilisation de l'API
94
+
95
+ ### Endpoint principal
96
+
97
+ ```
98
+ POST /translate
99
+ Content-Type: application/json
100
+
101
+ {
102
+ "text": "Bonjour le monde",
103
+ "source": "fr", // optionnel, dΓ©faut: "auto"
104
+ "target": "en" // optionnel, dΓ©faut: "fr"
105
+ }
106
+ ```
107
+
108
+ ### RΓ©ponse
109
+
110
+ ```json
111
+ {
112
+ "translatedText": "Hello world",
113
+ "source": "fr",
114
+ "target": "en",
115
+ "duration": 245
116
+ }
117
+ ```
118
+
119
+ ### Codes d'erreur
120
+
121
+ | Code | Signification |
122
+ |------|--------------|
123
+ | 200 | Succès |
124
+ | 400 | RequΓͺte invalide (texte manquant, trop long >5000 chars) |
125
+ | 429 | Rate limit dΓ©passΓ© (30 req/min/IP) |
126
+ | 500 | Erreur serveur |
127
+
128
+ ---
129
+
130
+ ## πŸ’» Exemples d'intΓ©gration
131
+
132
+ ### JavaScript / TypeScript
133
+
134
+ ```javascript
135
+ // Fetch API (navigateur / Node 18+)
136
+ async function translate(text, source = 'auto', target = 'fr') {
137
+ const res = await fetch('https://VOTRE_SPACE.hf.space/translate', {
138
+ method: 'POST',
139
+ headers: { 'Content-Type': 'application/json' },
140
+ body: JSON.stringify({ text, source, target })
141
+ });
142
+
143
+ if (!res.ok) throw new Error((await res.json()).error);
144
+ return res.json();
145
+ }
146
+
147
+ // Utilisation
148
+ translate('Bonjour', 'fr', 'es').then(r => console.log(r.translatedText)); // "Hola"
149
+ ```
150
+
151
+ ### Python
152
+
153
+ ```python
154
+ import requests
155
+
156
+ def translate(text, source='auto', target='fr', base_url='https://VOTRE_SPACE.hf.space'):
157
+ resp = requests.post(f'{base_url}/translate',
158
+ json={'text': text, 'source': source, 'target': target}, timeout=30)
159
+ resp.raise_for_status()
160
+ return resp.json()
161
+
162
+ # Usage
163
+ print(translate('Hello world', 'en', 'fr')['translatedText']) # "Bonjour le monde"
164
+ ```
165
+
166
+ ### Java (HttpClient 11+)
167
+
168
+ ```java
169
+ var client = HttpClient.newHttpClient();
170
+ var body = "{\"text\":\"Bonjour\",\"source\":\"fr\",\"target\":\"en\"}";
171
+ var request = HttpRequest.newBuilder()
172
+ .uri(URI.create("https://VOTRE_SPACE.hf.space/translate"))
173
+ .header("Content-Type", "application/json")
174
+ .POST(HttpRequest.BodyPublishers.ofString(body))
175
+ .build();
176
+
177
+ var response = client.send(request, HttpResponse.BodyHandlers.ofString());
178
+ // Parse JSON pour obtenir translatedText
179
+ ```
180
+
181
+ ### cURL
182
+
183
+ ```bash
184
+ curl -X POST https://VOTRE_SPACE.hf.space/translate \
185
+ -H "Content-Type: application/json" \
186
+ -d '{"text": "Bonjour", "source": "fr", "target": "en"}'
187
+ ```
188
+
189
+ > πŸ“– **Plus d'exemples** : Visitez `/wiki` sur votre instance dΓ©ployΓ©e !
190
+
191
+ ---
192
+
193
+ ## πŸ” Panel Admin
194
+
195
+ AccΓ©dez Γ  `https://VOTRE_SPACE.hf.space/admin` et entrez votre `ADMIN_ACCESS_CODE`.
196
+
197
+ ### Onglets disponibles :
198
+
199
+ | Onglet | Contenu |
200
+ |--------|---------|
201
+ | πŸ–₯️ **Machines** | CPU/RAM temps rΓ©el (central + workers), jobs actifs |
202
+ | πŸ“ˆ **RequΓͺtes (120s)** | Graphique requΓͺtes/minute, stats, taux actuel |
203
+ | πŸ“‹ **Logs** | DerniΓ¨res traductions : IP, durΓ©e, langues, entrΓ©e/sortie |
204
+
205
+ ---
206
+
207
+ ## βš™οΈ Configuration
208
+
209
+ ### Central (`central/settings.json`)
210
+
211
+ ```json
212
+ {
213
+ "port": 7820,
214
+ "rateLimit": { "maxRequestsPerMinutePerIP": 30, "windowMs": 60000 },
215
+ "scanLocalWorkers": true,
216
+ "metricsWindowSeconds": 120,
217
+ "maxLocalJobs": 4
218
+ }
219
+ ```
220
+
221
+ ### Worker (`worker/settings.json`)
222
+
223
+ ```json
224
+ {
225
+ "maxConcurrentJobs": 2,
226
+ "centralHost": "localhost",
227
+ "centralPort": 7820
228
+ }
229
+ ```
230
+
231
+ ### Variables d'environnement (Secrets)
232
+
233
+ | Variable | Requis | Description |
234
+ |----------|--------|-------------|
235
+ | `ADMIN_ACCESS_CODE` | βœ… | Mot de passe admin (fort !) |
236
+ | `TAILSCALE_API_KEY` | ❌ | Clé API Tailscale pour auto-découverte workers |
237
+ | `PORT` | ❌ | Port d'écoute (défaut: 7820) |
238
+
239
+ ---
240
+
241
+ ## πŸ—οΈ Architecture
242
+
243
+ ```
244
+ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
245
+ β”‚ HUGGINGFACE SPACE β”‚
246
+ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
247
+ β”‚ β”‚ CENTRAL β”‚ β”‚ WORKER β”‚ β”‚
248
+ β”‚ β”‚ (1.5 CPU / 12GB) │◄───│ (0.5 CPU / 4GB) β”‚ β”‚
249
+ β”‚ β”‚ β€’ Express API β”‚ WS β”‚ β€’ Translation β”‚ β”‚
250
+ β”‚ β”‚ β€’ Rate Limiting β”‚ β”‚ β€’ Job Queue β”‚ β”‚
251
+ β”‚ β”‚ β€’ Job Dispatch β”‚ β”‚ β€’ Metrics Push β”‚ β”‚
252
+ β”‚ β”‚ β€’ Admin Dashboard β”‚ β”‚ β”‚ β”‚
253
+ β”‚ β”‚ β€’ Metrics Storage β”‚ β”‚ β”‚ β”‚
254
+ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
255
+ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
256
+ ```
257
+
258
+ - **Central** : Gère l'API HTTP, rate limiting, dispatch vers workers, dashboard
259
+ - **Worker** : Se connecte en WebSocket, exΓ©cute les traductions, pousse mΓ©triques
260
+ - **Communication** : WebSocket natif (ws) pour faible latence
261
+
262
+ ---
263
+
264
+ ## πŸ“¦ Structure du projet
265
+
266
+ ```
267
+ Translator-API/
268
+ β”œβ”€β”€ central/ # Machine centrale
269
+ β”‚ β”œβ”€β”€ src/index.js # Serveur Express + WS + Admin
270
+ β”‚ β”œβ”€β”€ settings.json # Config centrale
271
+ β”‚ β”œβ”€β”€ public/ # Frontend statique
272
+ β”‚ β”‚ β”œβ”€β”€ index.html # Page d'accueil + test
273
+ β”‚ β”‚ β”œβ”€β”€ admin.html # Dashboard admin (Chart.js)
274
+ β”‚ β”‚ └── wiki.html # Documentation intΓ©grΓ©e
275
+ β”‚ └── secrets/ # .env (ignorΓ© par git)
276
+ β”œβ”€β”€ worker/ # Worker de traduction
277
+ β”‚ β”œβ”€β”€ src/index.js # Client WS + file d'attente
278
+ β”‚ └── settings.json # Config worker
279
+ β”œβ”€β”€ shared/ # Code partagΓ© (futur)
280
+ β”œβ”€β”€ wiki/ # Docs markdown (source)
281
+ β”œβ”€β”€ Dockerfile # Multi-stage build
282
+ β”œβ”€β”€ docker-compose.yml # Orchestration locale
283
+ β”œβ”€β”€ .env.example # Template secrets
284
+ └── package.json # DΓ©pendances root
285
+ ```
286
+
287
+ ---
288
+
289
+ ## πŸ› οΈ DΓ©veloppement
290
+
291
+ ```bash
292
+ # Installer tout
293
+ npm run install:all
294
+
295
+ # Central en mode watch
296
+ npm run dev:central
297
+
298
+ # Worker en mode watch
299
+ npm run dev:worker
300
+
301
+ # Tests
302
+ npm test
303
+ ```
304
+
305
+ ### Logs
306
+
307
+ - Central : `central/logs/central.log`
308
+ - Worker : `worker/logs/worker.log`
309
+
310
+ ---
311
+
312
+ ## πŸ”’ SΓ©curitΓ©
313
+
314
+ - **Pas de clΓ© API publique** β€” Protection par rate limiting IP
315
+ - **Admin protΓ©gΓ©** β€” Code fort dans variable d'environnement (pas dans le code)
316
+ - **Secrets HF Spaces** β€” StockΓ©s chiffrΓ©s, injectΓ©s au runtime
317
+ - **Non-root Docker** β€” User `nodejs` (UID 1001)
318
+ - **Helmet/CORS** β€” Configurables selon besoins
319
+
320
+ ---
321
+
322
+ ## πŸ“ Licence
323
+
324
+ MIT License β€” Voir [LICENSE](LICENSE)
325
+
326
+ ---
327
+
328
+ ## 🀝 Contribution
329
+
330
+ 1. Fork le projet
331
+ 2. CrΓ©ez une branche (`git checkout -b feature/amazing`)
332
+ 3. Committez (`git commit -m 'Add amazing feature'`)
333
+ 4. Push (`git push origin feature/amazing`)
334
+ 5. Ouvrez une Pull Request
335
+
336
+ ---
337
+
338
+ ## πŸ™ Remerciements
339
+
340
+ - [@vitalets/google-translate-api](https://github.com/vitalets/google-translate-api) β€” Moteur de traduction
341
+ - [Chart.js](https://www.chartjs.org/) β€” Graphiques admin
342
+ - [HuggingFace Spaces](https://huggingface.co/spaces) β€” HΓ©bergement gratuit
343
+
344
+ ---
345
+
346
+ <div align="center">
347
+ <strong>Fait avec ❀️ par <a href="https://github.com/NathMen12">NathMen12</a></strong>
348
+ <br>
349
+ <a href="https://github.com/NathMen12/Translator-API">⭐ Star sur GitHub</a> β€’
350
+ <a href="https://github.com/NathMen12/Translator-API/issues">πŸ› Signaler un bug</a> β€’
351
+ <a href="https://github.com/NathMen12/Translator-API/discussions">πŸ’¬ Discussions</a>
352
+ </div>