madamanastasia commited on
Commit
ce55b14
·
1 Parent(s): b9f9b5b

Modifications main.py et docs.html

Browse files
Files changed (2) hide show
  1. docs.html +220 -102
  2. main.py +1 -0
docs.html CHANGED
@@ -1,99 +1,212 @@
 
1
  <!doctype html>
2
- <html lang="en">
3
  <head>
4
  <meta charset="utf-8" />
5
  <meta name="viewport" content="width=device-width,initial-scale=1" />
6
- <title>Getaround — Pricing Optimization API</title>
7
  <style>
8
- body { font-family: Arial, sans-serif; margin: 40px; max-width: 900px; }
9
- h1, h2, h3 { color: #222; }
10
- code { background: #f4f4f4; padding: 2px 4px; border-radius: 4px; }
11
- pre { background: #f4f4f4; padding: 12px; border-radius: 6px; overflow-x: auto; }
12
- .note { background: #eef6ff; padding: 12px; border-left: 4px solid #3b82f6; margin: 20px 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  </style>
14
  </head>
15
 
16
  <body>
17
-
18
- <h1>Getaround — Pricing Optimization API</h1>
19
-
20
- <p>
21
- This API exposes a machine learning model that predicts
22
- <strong>rental_price_per_day</strong> for a car based on its characteristics.
23
- </p>
24
-
25
- <hr>
26
-
27
- <h2>Health Check</h2>
28
-
29
- <p><strong>GET /health</strong></p>
30
-
31
- <pre><code>curl -s http://127.0.0.1:8000/health</code></pre>
32
-
33
- <p>Response:</p>
34
-
35
- <pre><code>{"status":"ok"}</code></pre>
36
-
37
- <hr>
38
-
39
- <h2>Prediction Endpoint</h2>
40
-
41
- <p><strong>POST /predict</strong></p>
42
-
43
- <p>
44
- Returns predicted daily rental prices for one or multiple cars.
45
- </p>
46
-
47
- <h3>Accepted Input Format (JSON body)</h3>
48
-
49
- <ul>
50
- <li>
51
- <strong>Matrix format (required by evaluation)</strong>:
52
- <code>{"input": [[...], [...]]}</code>
53
- </li>
54
- <li>
55
- <strong>Dict format (optional / backward compatible)</strong>:
56
- <code>{"input": [{"feature": value, ...}]}</code>
57
- </li>
58
- </ul>
59
-
60
- <div class="note">
61
- <strong>Matrix format requirements:</strong><br><br>
62
- Each row must contain <strong>exactly 13 values</strong> in the following strict order:
63
- <br><br>
64
- <code>
65
- model_key, mileage, engine_power, fuel, paint_color, car_type,
66
- private_parking_available, has_gps, has_air_conditioning, automatic_car,
67
- has_getaround_connect, has_speed_regulator, winter_tires
68
- </code>
69
- <br><br>
70
- Types:
71
- <ul>
72
- <li><strong>model_key, fuel, paint_color, car_type</strong> strings</li>
73
- <li><strong>mileage, engine_power</strong> → numeric values</li>
74
- <li>All remaining features → 0 or 1</li>
75
- </ul>
76
- </div>
77
-
78
- <hr>
79
-
80
- <h3>Example — Matrix Format (Required)</h3>
81
-
82
- <pre><code>{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  "input": [
84
  ["Citroën", 140411, 100, "diesel", "black", "convertible", 1, 1, 0, 0, 1, 1, 1]
85
  ]
86
  }</code></pre>
87
 
88
- <h4>curl</h4>
89
-
90
- <pre><code>curl -X POST "http://127.0.0.1:8000/predict" \
 
91
  -H "Content-Type: application/json" \
92
  -d '{"input":[["Citroën",140411,100,"diesel","black","convertible",1,1,0,0,1,1,1]]}'</code></pre>
93
-
94
- <h4>Python</h4>
95
-
96
- <pre><code>import requests
97
 
98
  payload = {
99
  "input": [
@@ -103,12 +216,15 @@ payload = {
103
 
104
  r = requests.post("http://127.0.0.1:8000/predict", json=payload)
105
  print(r.json())</code></pre>
 
 
106
 
107
- <hr>
108
 
109
- <h3>Optional — Dict Format (Backward Compatible)</h3>
110
-
111
- <pre><code>{
 
112
  "input": [
113
  {
114
  "model_key": "Citroën",
@@ -128,27 +244,29 @@ print(r.json())</code></pre>
128
  ]
129
  }</code></pre>
130
 
131
- <hr>
132
-
133
- <h3>Response Format</h3>
134
 
135
- <pre><code>{
 
 
136
  "prediction": [97.15]
137
  }</code></pre>
138
 
139
- <p>
140
- If multiple rows are provided, the response will contain one prediction per row.
141
- </p>
142
-
143
- <hr>
144
-
145
- <h2>Notes</h2>
146
-
147
- <ul>
148
- <li>Unknown categorical values are handled automatically by the model.</li>
149
- <li>Invalid matrix shape (wrong number of values) will return a 422 error.</li>
150
- <li>The API is designed for batch predictions.</li>
151
- </ul>
152
-
 
153
  </body>
154
  </html>
 
 
1
+ ```html
2
  <!doctype html>
3
+ <html lang="fr">
4
  <head>
5
  <meta charset="utf-8" />
6
  <meta name="viewport" content="width=device-width,initial-scale=1" />
7
+ <title>Getaround — Documentation API Pricing</title>
8
  <style>
9
+ :root {
10
+ --text: #111827;
11
+ --muted: #4b5563;
12
+ --border: #e5e7eb;
13
+ --bg: #ffffff;
14
+ --codebg: #0b1020;
15
+ --codefg: #e6edf3;
16
+ --soft: #f9fafb;
17
+ --note: #eef6ff;
18
+ --note-border: #3b82f6;
19
+ --ok: #065f46;
20
+ --warn: #92400e;
21
+ --err: #991b1b;
22
+ }
23
+ body {
24
+ font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
25
+ margin: 32px;
26
+ max-width: 980px;
27
+ color: var(--text);
28
+ background: var(--bg);
29
+ line-height: 1.55;
30
+ }
31
+ h1 { margin: 0 0 6px 0; font-size: 28px; }
32
+ .subtitle { margin: 0 0 18px 0; color: var(--muted); }
33
+ .pill {
34
+ display: inline-block;
35
+ font-size: 12px;
36
+ padding: 2px 10px;
37
+ border-radius: 999px;
38
+ background: var(--soft);
39
+ border: 1px solid var(--border);
40
+ color: var(--muted);
41
+ vertical-align: middle;
42
+ margin-left: 8px;
43
+ }
44
+ .card {
45
+ border: 1px solid var(--border);
46
+ border-radius: 14px;
47
+ padding: 16px;
48
+ margin: 14px 0;
49
+ background: #fff;
50
+ }
51
+ .grid {
52
+ display: grid;
53
+ grid-template-columns: 1fr;
54
+ gap: 12px;
55
+ }
56
+ @media (min-width: 900px) {
57
+ .grid { grid-template-columns: 1fr 1fr; }
58
+ }
59
+ code {
60
+ background: #f3f4f6;
61
+ padding: 2px 6px;
62
+ border-radius: 6px;
63
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
64
+ font-size: 0.95em;
65
+ }
66
+ pre {
67
+ background: var(--codebg);
68
+ color: var(--codefg);
69
+ padding: 12px 14px;
70
+ border-radius: 12px;
71
+ overflow-x: auto;
72
+ border: 1px solid rgba(255,255,255,0.08);
73
+ }
74
+ pre code {
75
+ background: transparent;
76
+ padding: 0;
77
+ border-radius: 0;
78
+ font-size: 13px;
79
+ }
80
+ .note {
81
+ background: var(--note);
82
+ padding: 12px 14px;
83
+ border-left: 4px solid var(--note-border);
84
+ border-radius: 10px;
85
+ margin: 10px 0;
86
+ }
87
+ .kv { margin: 8px 0 0 0; padding: 0; list-style: none; }
88
+ .kv li { margin: 6px 0; }
89
+ .kv b { display: inline-block; min-width: 130px; }
90
+ .status { font-weight: 700; }
91
+ .status.ok { color: var(--ok); }
92
+ .status.warn { color: var(--warn); }
93
+ .status.err { color: var(--err); }
94
+ hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
95
+ a { color: #1d4ed8; text-decoration: none; }
96
+ a:hover { text-decoration: underline; }
97
+ ul { margin: 8px 0 0 18px; }
98
  </style>
99
  </head>
100
 
101
  <body>
102
+ <h1>🚗 Getaround — Documentation de l’API Pricing</h1>
103
+ <p class="subtitle">
104
+ Documentation minimale requise, accessible via <code>/docs</code> : description de chaque endpoint (méthode, entrée, sortie, exemples).
105
+ </p>
106
+
107
+ <div class="card">
108
+ <h2>Vue d’ensemble</h2>
109
+ <p>Cette API expose un modèle de Machine Learning qui prédit <code>rental_price_per_day</code> en fonction des caractéristiques du véhicule.</p>
110
+ <ul>
111
+ <li><code>GET /</code> — Page d’accueil (HTML)</li>
112
+ <li><code>GET /health</code> — Healthcheck (JSON)</li>
113
+ <li><code>POST /predict</code> — Prédiction (JSON)</li>
114
+ <li><code>GET /docs</code> — Documentation (HTML)</li>
115
+ </ul>
116
+ </div>
117
+
118
+ <div class="card">
119
+ <h2><code>GET /</code><span class="pill">HTML</span></h2>
120
+ <ul class="kv">
121
+ <li><b>Méthode</b> GET</li>
122
+ <li><b>Entrée</b> Aucune</li>
123
+ <li><b>Sortie</b> Page HTML listant les endpoints disponibles</li>
124
+ </ul>
125
+ <p><b>Exemple :</b></p>
126
+ <pre><code>curl -s http://127.0.0.1:8000/</code></pre>
127
+ </div>
128
+
129
+ <div class="card">
130
+ <h2><code>GET /health</code><span class="pill">JSON</span></h2>
131
+ <ul class="kv">
132
+ <li><b>Méthode</b> GET</li>
133
+ <li><b>Entrée</b> Aucune</li>
134
+ <li><b>Sortie</b> JSON indiquant l’état du service</li>
135
+ </ul>
136
+ <p><b>Exemple :</b></p>
137
+ <pre><code>curl -s http://127.0.0.1:8000/health</code></pre>
138
+ <p><b>Réponse attendue :</b></p>
139
+ <pre><code>{
140
+ "status": "ok"
141
+ }</code></pre>
142
+ </div>
143
+
144
+ <div class="card">
145
+ <h2><code>GET /docs</code><span class="pill">HTML</span></h2>
146
+ <ul class="kv">
147
+ <li><b>Méthode</b> GET</li>
148
+ <li><b>Entrée</b> Aucune</li>
149
+ <li><b>Sortie</b> Page HTML contenant la documentation de l’API</li>
150
+ </ul>
151
+ <p><b>Exemple :</b></p>
152
+ <pre><code>curl -s http://127.0.0.1:8000/docs</code></pre>
153
+ </div>
154
+
155
+ <div class="card">
156
+ <h2><code>POST /predict</code><span class="pill">JSON</span></h2>
157
+ <p>Retourne les prédictions de prix journalier (<code>rental_price_per_day</code>) pour une ou plusieurs lignes en entrée.</p>
158
+
159
+ <ul class="kv">
160
+ <li><b>Méthode</b> POST</li>
161
+ <li><b>Entrée</b> JSON avec une clé <code>input</code></li>
162
+ <li><b>Sortie</b> JSON <code>{"prediction": [...]}</code> (une prédiction par ligne)</li>
163
+ </ul>
164
+
165
+ <div class="note">
166
+ <div><b>Formats acceptés :</b></div>
167
+ <ul>
168
+ <li><b>Format matrice</b> (requis pour l’évaluation) : <code>{"input": [[...], [...]]}</code></li>
169
+ <li><b>Format dictionnaires</b> (optionnel / compatibilité) : <code>{"input": [{"feature": value, ...}]}</code></li>
170
+ </ul>
171
+ </div>
172
+
173
+ <hr>
174
+
175
+ <h3>1) Format matrice (requis)</h3>
176
+ <p class="subtitle" style="margin-top:6px">
177
+ Chaque ligne doit contenir <b>exactement 13 valeurs</b>, dans l’ordre strict suivant (défini par <code>feature_order.json</code>) :
178
+ </p>
179
+ <pre><code>model_key, mileage, engine_power, fuel, paint_color, car_type,
180
+ private_parking_available, has_gps, has_air_conditioning, automatic_car,
181
+ has_getaround_connect, has_speed_regulator, winter_tires</code></pre>
182
+
183
+ <div class="note">
184
+ <b>Types attendus :</b>
185
+ <ul>
186
+ <li><b>model_key, fuel, paint_color, car_type</b> → chaînes de caractères</li>
187
+ <li><b>mileage, engine_power</b> → valeurs numériques</li>
188
+ <li>Les variables booléennes → <b>true/false</b> ou <b>0/1</b></li>
189
+ </ul>
190
+ <div class="status warn">Si une ligne n’a pas 13 valeurs, l’API renvoie une erreur 422.</div>
191
+ </div>
192
+
193
+ <p><b>Exemple de requête (matrice) :</b></p>
194
+ <pre><code>{
195
  "input": [
196
  ["Citroën", 140411, 100, "diesel", "black", "convertible", 1, 1, 0, 0, 1, 1, 1]
197
  ]
198
  }</code></pre>
199
 
200
+ <div class="grid">
201
+ <div class="card">
202
+ <h4>curl</h4>
203
+ <pre><code>curl -X POST "http://127.0.0.1:8000/predict" \
204
  -H "Content-Type: application/json" \
205
  -d '{"input":[["Citroën",140411,100,"diesel","black","convertible",1,1,0,0,1,1,1]]}'</code></pre>
206
+ </div>
207
+ <div class="card">
208
+ <h4>Python</h4>
209
+ <pre><code>import requests
210
 
211
  payload = {
212
  "input": [
 
216
 
217
  r = requests.post("http://127.0.0.1:8000/predict", json=payload)
218
  print(r.json())</code></pre>
219
+ </div>
220
+ </div>
221
 
222
+ <hr>
223
 
224
+ <h3>2) Format dictionnaires (compatibilité)</h3>
225
+ <p>Ce format est accepté pour des raisons de compatibilité. Toutes les colonnes attendues doivent être présentes ; l’API réordonne ensuite selon <code>FEATURE_ORDER</code>.</p>
226
+ <p><b>Exemple de requête (dictionnaires) :</b></p>
227
+ <pre><code>{
228
  "input": [
229
  {
230
  "model_key": "Citroën",
 
244
  ]
245
  }</code></pre>
246
 
247
+ <hr>
 
 
248
 
249
+ <h3>Réponse</h3>
250
+ <p>Une prédiction par ligne.</p>
251
+ <pre><code>{
252
  "prediction": [97.15]
253
  }</code></pre>
254
 
255
+ <h3>Erreurs possibles</h3>
256
+ <ul>
257
+ <li><code>422</code> — entrée invalide (mauvaise dimension de matrice, colonnes manquantes en mode dictionnaire, JSON invalide)</li>
258
+ <li><code>500</code> — erreur interne lors de la prédiction (échec du modèle)</li>
259
+ </ul>
260
+ </div>
261
+
262
+ <div class="card">
263
+ <h2>Notes</h2>
264
+ <ul>
265
+ <li>L’API supporte des prédictions en batch (plusieurs lignes dans <code>input</code>).</li>
266
+ <li>Les catégories inconnues peuvent être gérées par le pipeline du modèle (selon l’entraînement).</li>
267
+ <li>Pour éviter les erreurs 422, respecter strictement l’ordre et le nombre de features en mode matrice.</li>
268
+ </ul>
269
+ </div>
270
  </body>
271
  </html>
272
+ ```
main.py CHANGED
@@ -88,6 +88,7 @@ def docs():
88
  ]
89
  }}</pre>
90
  """
 
91
 
92
 
93
 
 
88
  ]
89
  }}</pre>
90
  """
91
+ <li><a href="/docs">GET /docs</a> – API Documentation</li>
92
 
93
 
94