Spaces:
Sleeping
Sleeping
File size: 5,254 Bytes
2c1dae0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 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 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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | # API λͺ
μΈμ (v1)
Base URL
```
/api/v1
```
μμ½
- μ£Όμ 리μμ€: /posts, /predict, /uploads, /stats
- μλ΅ ν¬λ§·: JSON (HTML νμ΄μ§λ μΉ λΌμ°νΈλ‘ λ³λ μ 곡)
- νλ λ€μ΄λ°: snake_case
- λ μ§/μκ°: ISO 8601 (μ: 2026-04-28T12:34:56Z)
κ³΅ν΅ μλ¬ μλ΅ (μμ)
```json
{
"success": false,
"error": {
"code": 400,
"message": "Bad Request",
"details": null
}
}
```
μΈμ¦ / Rate limiting
- μΈμ¦: μ ν(μ: JWT Authorization: Bearer <token>), νμν μλν¬μΈνΈμ νκΈ°
- Rate limit: μμ - 60 requests/min (λ¬Έμν κΆμ₯)
λͺ¨λΈ λ©νλ°μ΄ν°(κΆμ₯ μλ΅ νλ)
- model_name, model_version, inference_time_ms
---
## 1. μΉ νμ΄μ§ λΌμ°ν
(HTML)
(μΉ μλ² ν
νλ¦Ώμ©; API Base URL μ μ© μμ)
- GET / β 200 HTML (index.html)
- GET /board β 200 HTML (board.html)
- GET /posts/{post_id} β 200 HTML (post detail)
---
## 2. μ΄λ―Έμ§ λΆλ₯ API (routers/predict.py)
### [POST] μ΄λ―Έμ§ λΆλ₯
POST /api/v1/predict
Headers:
- Content-Type: multipart/form-data
Request (form-data):
- file: (required) image file, field name `file` (max 10MB, allowed: .jpg, .jpeg, .png)
Response 200:
```json
{
"success": true,
"filename": "cat.jpg",
"predicted_class": "cat",
"confidence": 0.9821,
"top_k": [
{"label":"cat","score":0.9821},
{"label":"dog","score":0.0121}
],
"model": {
"name": "classifier",
"version": "v1.0.0"
},
"inference_time_ms": 123
}
```
Errors:
- 400: missing file / invalid file type
- 413: payload too large
- 500: model inference failure
---
### [POST] μ΄λ―Έμ§ μ
λ‘λ + λΆλ₯ + κ²μκΈ μλ μμ±
POST /api/v1/predict/upload
Headers:
- Content-Type: multipart/form-data
Request (form-data):
- title: string (required)
- content: string (optional)
- image: file (required) field name `image`
Response 201:
```json
{
"success": true,
"post_id": 15,
"prediction": "cat",
"confidence": 0.98,
"model": {"name":"classifier","version":"v1.0.0"}
}
```
---
### [GET] λͺ¨λΈ λΌλ²¨ λͺ©λ‘
GET /api/v1/predict/labels
Response 200:
```json
{
"classes": ["cat","dog","car","person"]
}
```
---
## 3. κ²μκΈ API (routers/post.py)
### [GET] κ²μκΈ λͺ©λ‘ (νμ΄μ§/νν°)
GET /api/v1/posts
Query params:
- page: int (default 1)
- size: int (default 10)
- category: string (optional)
Response 200:
```json
{
"items": [
{
"id": 1,
"title": "κ³ μμ΄ λΆλ₯ μ±κ³΅",
"prediction": "cat",
"confidence": 0.98,
"created_at": "2026-04-28T12:00:00Z"
}
],
"page": 1,
"size": 10,
"total": 34
}
```
### [GET] κ²μκΈ μμΈ
GET /api/v1/posts/{id}
Response 200:
```json
{
"id": 1,
"title": "κ³ μμ΄ λΆλ₯ μ±κ³΅",
"content": "ν
μ€νΈ κΈ",
"image_url": "/uploads/cat.jpg",
"prediction": "cat",
"confidence": 0.98,
"created_at": "2026-04-28T12:00:00Z"
}
```
404: post not found
### [POST] κ²μκΈ μμ±
POST /api/v1/posts
Headers:
- Content-Type: application/json
Request body:
```json
{
"title":"μ κ²μκΈ",
"content":"λ΄μ©",
"image_url":"/uploads/sample.jpg",
"prediction":"cat",
"confidence":0.95
}
```
Response 201:
```json
{"success": true, "id": 123}
```
Validation: title required, image_url optional, confidence 0.0-1.0
### [PUT] κ²μκΈ μμ
PUT /api/v1/posts/{id}
Request body (partial νμ©):
```json
{"title":"μμ μ λͺ©","content":"μμ λ΄μ©"}
```
Response 200: {"success": true}
### [DELETE] κ²μκΈ μμ
DELETE /api/v1/posts/{id}
Response 200:
```json
{"success": true, "message": "μμ μλ£"}
```
---
## 4. μ’μμ / μΆμ²
POST /api/v1/posts/{id}/like
Response 200:
```json
{"success": true, "likes": 12}
```
---
## 5. ν΅κ³ API (λμ보λμ©)
GET /api/v1/stats/classes
Query params (optional):
- start_date, end_date (ISO 8601)
Response 200:
```json
{"cat":34,"dog":20,"car":14}
```
---
## λ°μ΄ν°/μλ΅ μ€ν€λ§ (schemas.py)
PostCreate
- title: string (required)
- content: string (optional)
- image_url: string (optional, κ²½λ‘)
- prediction: string (optional)
- confidence: float (0.0 - 1.0, optional)
PostResponse
- id: int
- title: string
- content: string
- image_url: string
- prediction: string
- confidence: float
- created_at: datetime (ISO 8601)
PredictResponse
- success: bool
- filename: string
- predicted_class: string
- confidence: float
- top_k: [{label: string, score: float}]
- model: {name:string, version:string}
- inference_time_ms: int
ErrorResponse
- success: false
- error: {code:int, message:string, details:object|null}
---
## ꡬν/μ΄μ κΆμ₯μ¬ν
- λͺ¨λ APIλ /api/v1/ μ λμ¬λ₯Ό μ¬μ©ν΄ λ²μ κ΄λ¦¬
- μμ²/μλ΅ μμλ OpenAPI(Swagger)λ‘ μμ±ν΄ μλ λ¬Έμν κΆμ₯
- νμΌ μ
λ‘λλ μ μ₯μ μ©λ, νμ₯μ κ²μ¬, μ
μ± νμΌ κ²μ¬ ꡬν
- λ―Όκ°ν νμΌ μ
λ‘λλ μΈμ¦/ACL μ μ©
- λͺ¨λΈ λ²μ κ΄λ¦¬ λ° A/B ν
μ€νΈ λ‘κ·Έ λ¨κΈ°κΈ°
- μμΈν λ‘κΉ
(μμ² id, inference time, model version)μΌλ‘ λ¬Έμ μΆμ
--- |