Spaces:
Sleeping
Sleeping
madamanastasia commited on
Commit ·
ce55b14
1
Parent(s): b9f9b5b
Modifications main.py et docs.html
Browse files
docs.html
CHANGED
|
@@ -1,99 +1,212 @@
|
|
|
|
|
| 1 |
<!doctype html>
|
| 2 |
-
<html lang="
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
| 6 |
-
<title>Getaround —
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
</style>
|
| 14 |
</head>
|
| 15 |
|
| 16 |
<body>
|
| 17 |
-
|
| 18 |
-
<
|
| 19 |
-
|
| 20 |
-
<p>
|
| 21 |
-
|
| 22 |
-
<
|
| 23 |
-
</
|
| 24 |
-
|
| 25 |
-
<
|
| 26 |
-
|
| 27 |
-
<
|
| 28 |
-
|
| 29 |
-
<
|
| 30 |
-
|
| 31 |
-
<
|
| 32 |
-
|
| 33 |
-
<
|
| 34 |
-
|
| 35 |
-
<
|
| 36 |
-
|
| 37 |
-
<
|
| 38 |
-
|
| 39 |
-
<
|
| 40 |
-
|
| 41 |
-
<
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
</
|
| 46 |
-
|
| 47 |
-
<
|
| 48 |
-
|
| 49 |
-
<
|
| 50 |
-
|
| 51 |
-
<
|
| 52 |
-
<code>
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
</
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
<
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
</
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
<
|
| 73 |
-
|
| 74 |
-
<
|
| 75 |
-
|
| 76 |
-
</
|
| 77 |
-
|
| 78 |
-
<
|
| 79 |
-
|
| 80 |
-
<
|
| 81 |
-
|
| 82 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
"input": [
|
| 84 |
["Citroën", 140411, 100, "diesel", "black", "convertible", 1, 1, 0, 0, 1, 1, 1]
|
| 85 |
]
|
| 86 |
}</code></pre>
|
| 87 |
|
| 88 |
-
<
|
| 89 |
-
|
| 90 |
-
<
|
|
|
|
| 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 |
-
<
|
| 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>
|
| 110 |
-
|
| 111 |
-
<
|
|
|
|
| 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 |
-
<
|
|
|
|
|
|
|
| 136 |
"prediction": [97.15]
|
| 137 |
}</code></pre>
|
| 138 |
|
| 139 |
-
<
|
| 140 |
-
|
| 141 |
-
</
|
| 142 |
-
|
| 143 |
-
<
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
<
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
</
|
| 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 |
|