mucahitkantepe commited on
Commit
79979ec
·
1 Parent(s): 6927844

expose palette + rationale on outfit endpoint

Browse files

- ProductOut: surface scandi_score
- PaletteSwatch: outfit-merged dominant LABs (source/lab/hex/name)
- OutfitComplement: rationale, color_name, color_score, axes_added
- OutfitResponse: anchor_color_name, palette, axes_covered/contrasted, scandi_score
- DROP_FIELDS now strips internal lab_color/palette/contrast_axes blobs

.long-run/checkpoints/phase-3-step-8.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ step: 8
3
+ title: Backend schemas + outfit endpoint enrichment
4
+ status: completed
5
+ ---
6
+
7
+ # Step 8 — Backend wiring
8
+
9
+ ## What changed
10
+
11
+ - `backend/app/schemas.py`:
12
+ - `ProductOut.scandi_score` (nullable float)
13
+ - New `PaletteSwatch` (source / lab / hex / name)
14
+ - `OutfitComplement.rationale, color_name, color_score, axes_added`
15
+ - `OutfitResponse.anchor_color_name, palette, axes_covered, axes_contrasted, scandi_score`
16
+ - `backend/app/routers/products.py`:
17
+ - `_DROP_FIELDS` now drops `lab_color, palette, contrast_axes` (BLOB/JSON internal columns)
18
+ - `get_outfit` populates all new fields
19
+ - `_DROP_FIELDS` keeps `scandi_score` so it surfaces on every product
20
+ - `taste/outfits.py`: `_outfit_palette` emits `source` (was `from`) — Pydantic doesn't allow reserved names
21
+
22
+ ## Verifier
23
+
24
+ - `python3 -m py_compile` — pass
25
+ - FastAPI TestClient end-to-end smoke test: status 200, full payload shape verified
26
+
27
+ ## Live response shape
28
+
29
+ ```json
30
+ {
31
+ "anchor_color_name": "red",
32
+ "axes_covered": ["formality", "structure", "surface", "weight"],
33
+ "axes_contrasted": ["surface"],
34
+ "scandi_score": 0.664,
35
+ "palette": [
36
+ {"source": "anchor", "name": "red", "hex": "#ad0f2e"},
37
+ {"source": "shoes", "name": "black", "hex": "#272727"},
38
+ {"source": "bag", "name": "ivory", "hex": "#dad4ca"},
39
+ {"source": "outerwear", "name": "black", "hex": "#2b2525"}
40
+ ],
41
+ "complements": [
42
+ {"bucket": "shoes", "rationale": "black · complementary tones · scandi-fit"},
43
+ {"bucket": "bag", "rationale": "ivory · complementary tones · adds softness · scandi-fit"},
44
+ {"bucket": "outerwear", "rationale": "black · color-harmonious · scandi-fit"}
45
+ ]
46
+ }
47
+ ```
backend/app/routers/products.py CHANGED
@@ -5,15 +5,24 @@ import json
5
  from fastapi import APIRouter, HTTPException, Query
6
 
7
  from backend.app.deps import get_store
8
- from backend.app.schemas import OutfitComplement, OutfitResponse, ProductOut, ProductsResponse
 
 
 
 
 
 
9
  from taste.outfits import compose_outfit
10
 
11
  router = APIRouter(prefix="/api/products", tags=["products"])
12
 
13
- # Fields to drop from DB rows before passing to ProductOut
 
 
14
  _DROP_FIELDS = {
15
- "image_path", "fabric", "created_at", "first_seen_at", "last_seen_at",
16
- "updated_at", "rn", "taste_embedding",
 
17
  }
18
 
19
  # Maps UI category labels to search patterns (covers EN, NO, SV, and Zalando silhouettes)
@@ -237,7 +246,9 @@ def get_outfit(url: str = Query(..., description="Anchor product URL")):
237
 
238
  Returns the anchor + complementary pieces (shoes, bag, outerwear, etc.)
239
  drawn from the user's top-scored in-stock catalog. Pairing rules per
240
- bucket live in `taste.outfits.PAIRING_RULES`.
 
 
241
  """
242
  db = get_store()
243
  out = compose_outfit(url, db.conn)
@@ -247,9 +258,21 @@ def get_outfit(url: str = Query(..., description="Anchor product URL")):
247
  return OutfitResponse(
248
  anchor=_row_to_product(out["anchor"]),
249
  anchor_bucket=out["anchor_bucket"],
 
250
  complements=[
251
- OutfitComplement(bucket=c["bucket"], product=_row_to_product(c["product"]))
 
 
 
 
 
 
 
252
  for c in out["complements"]
253
  ],
254
  total_nok=out["total_nok"],
 
 
 
 
255
  )
 
5
  from fastapi import APIRouter, HTTPException, Query
6
 
7
  from backend.app.deps import get_store
8
+ from backend.app.schemas import (
9
+ OutfitComplement,
10
+ OutfitResponse,
11
+ PaletteSwatch,
12
+ ProductOut,
13
+ ProductsResponse,
14
+ )
15
  from taste.outfits import compose_outfit
16
 
17
  router = APIRouter(prefix="/api/products", tags=["products"])
18
 
19
+ # Fields to drop from DB rows before passing to ProductOut. The
20
+ # color/contrast/scandi backfill columns are internal — except scandi_score
21
+ # which we surface directly on ProductOut.
22
  _DROP_FIELDS = {
23
+ "image_path", "image_paths", "fabric", "created_at", "first_seen_at",
24
+ "last_seen_at", "updated_at", "rn", "taste_embedding",
25
+ "lab_color", "palette", "contrast_axes",
26
  }
27
 
28
  # Maps UI category labels to search patterns (covers EN, NO, SV, and Zalando silhouettes)
 
246
 
247
  Returns the anchor + complementary pieces (shoes, bag, outerwear, etc.)
248
  drawn from the user's top-scored in-stock catalog. Pairing rules per
249
+ bucket live in `taste.outfits.PAIRING_RULES`. Each complement carries a
250
+ short rationale (color harmony, axes added, scandi-fit) and the outfit
251
+ overall ships a merged palette + axis coverage summary.
252
  """
253
  db = get_store()
254
  out = compose_outfit(url, db.conn)
 
258
  return OutfitResponse(
259
  anchor=_row_to_product(out["anchor"]),
260
  anchor_bucket=out["anchor_bucket"],
261
+ anchor_color_name=out.get("anchor_color_name", ""),
262
  complements=[
263
+ OutfitComplement(
264
+ bucket=c["bucket"],
265
+ product=_row_to_product(c["product"]),
266
+ rationale=c.get("rationale", ""),
267
+ color_name=c.get("color_name", ""),
268
+ color_score=float(c.get("color_score") or 0.0),
269
+ axes_added=list(c.get("axes_added") or []),
270
+ )
271
  for c in out["complements"]
272
  ],
273
  total_nok=out["total_nok"],
274
+ palette=[PaletteSwatch(**p) for p in out.get("palette", [])],
275
+ axes_covered=list(out.get("axes_covered") or []),
276
+ axes_contrasted=list(out.get("axes_contrasted") or []),
277
+ scandi_score=float(out.get("scandi_score") or 0.0),
278
  )
backend/app/schemas.py CHANGED
@@ -23,18 +23,37 @@ class ProductOut(BaseModel):
23
  sizes: list[str] = []
24
  external_id: str = ""
25
  canonical_category: str = ""
 
 
 
 
 
 
 
 
 
 
26
 
27
 
28
  class OutfitComplement(BaseModel):
29
  bucket: str
30
  product: ProductOut
 
 
 
 
31
 
32
 
33
  class OutfitResponse(BaseModel):
34
  anchor: ProductOut
35
  anchor_bucket: str
 
36
  complements: list[OutfitComplement]
37
  total_nok: float
 
 
 
 
38
 
39
 
40
  class ProductsResponse(BaseModel):
 
23
  sizes: list[str] = []
24
  external_id: str = ""
25
  canonical_category: str = ""
26
+ scandi_score: float | None = None # surfaced so UI can badge "Scandi pick"
27
+
28
+
29
+ class PaletteSwatch(BaseModel):
30
+ """One color sampled from an outfit. `source` labels which slot it came from."""
31
+
32
+ source: str
33
+ lab: list[float]
34
+ hex: str
35
+ name: str
36
 
37
 
38
  class OutfitComplement(BaseModel):
39
  bucket: str
40
  product: ProductOut
41
+ rationale: str = ""
42
+ color_name: str = ""
43
+ color_score: float = 0.0
44
+ axes_added: list[str] = []
45
 
46
 
47
  class OutfitResponse(BaseModel):
48
  anchor: ProductOut
49
  anchor_bucket: str
50
+ anchor_color_name: str = ""
51
  complements: list[OutfitComplement]
52
  total_nok: float
53
+ palette: list[PaletteSwatch] = []
54
+ axes_covered: list[str] = []
55
+ axes_contrasted: list[str] = []
56
+ scandi_score: float = 0.0
57
 
58
 
59
  class ProductsResponse(BaseModel):
taste/outfits.py CHANGED
@@ -482,14 +482,19 @@ def compose_outfit(anchor_url: str, conn) -> dict | None:
482
 
483
 
484
  def _outfit_palette(anchor: dict, complements: list[dict]) -> list[dict]:
485
- """Merge dominant LABs across the outfit into a small swatch list."""
 
 
 
 
 
486
  out: list[dict] = []
487
  for label, prod in [("anchor", anchor)] + [(c["bucket"], c["product"]) for c in complements]:
488
  dom = _row_dom(prod)
489
  if dom is None:
490
  continue
491
  out.append({
492
- "from": label,
493
  "lab": [float(v) for v in dom],
494
  "hex": lab_to_hex(dom),
495
  "name": _color_name(dom),
 
482
 
483
 
484
  def _outfit_palette(anchor: dict, complements: list[dict]) -> list[dict]:
485
+ """Merge dominant LABs across the outfit into a small swatch list.
486
+
487
+ Each entry: `{source: "anchor"|<bucket>, lab: [L,a,b], hex: "#rrggbb", name: <color>}`
488
+ The `source` field labels which slot the color came from so UIs can map
489
+ swatches back to garments.
490
+ """
491
  out: list[dict] = []
492
  for label, prod in [("anchor", anchor)] + [(c["bucket"], c["product"]) for c in complements]:
493
  dom = _row_dom(prod)
494
  if dom is None:
495
  continue
496
  out.append({
497
+ "source": label,
498
  "lab": [float(v) for v in dom],
499
  "hex": lab_to_hex(dom),
500
  "name": _color_name(dom),