Skip to content
.md

Build a fashion product catalogue from a Kaggle dataset

The Fashion Product Images dataset holds about 44,000 products of an online fashion shop, each with gender, category, article type, colour, season and a product image. That is the classic product catalogue: in this example you load it into a local dcupl app and query it the way a shop's filter sidebar does, with facets, combined filters and type-ahead suggestions.

Time required: 10 minutes

What you will learn: generate models from CSV files, link two files that share no key column with a loader transformer, and build facet counts and suggestions over a real catalogue.

The dataset

The data comes from Fashion Product Images on Kaggle (Aggarwal, 2019). Next to the product images, the dataset has two CSV files, and this example needs only those:

File Rows (at the time of writing) What a row is
styles.csv 44,446 A product: gender, master and sub category, article type, colour, season, year, usage, name
images.csv 44,446 An image file name (15970.jpg) and its URL

The image files themselves make the full download large. Download only the two CSV files from the dataset's file browser on Kaggle. Check the dataset's licence on its Kaggle page before you publish anything built on it.

Prerequisites

  • The dcupl CLI installed (dcupl --version to check)
  • styles.csv and images.csv from the Kaggle page

Step 1: create the workspace

terminal
dcupl init fashion-products --starter empty
cd fashion-products

Copy styles.csv and images.csv into dcupl/data/.

Step 2: generate the models

terminal
dcupl generate model --from dcupl/data/styles.csv --name Style --register
dcupl generate model --from dcupl/data/images.csv --name Image --register

Style gets id as its key, the only unique column of styles.csv. For images.csv the generator finds no key-like column and generates keys, but the file name is unique. Open dcupl/models/Image.dcupl.json and make it the key:

Image.dcupl.json: change these two fields
{
  "keyProperty": "filename",
  "autoGenerateKey": false
}

A style and its image belong together by file name: style 15970 has the image 15970.jpg. No column holds that file name on the style side, so there is nothing to reference yet. A transformer adds it: a small script the loader runs on a data file after parsing, before dcupl ingests the rows.

Create dcupl/transformers/link-images.js:

dcupl/transformers/link-images.js
return (resource, items) => items.map((item) => ({ ...item, image: `${item.id}.jpg` }));

The file is the body of a function that returns the transformer: it receives the resource and the parsed rows and returns the rows dcupl should load. Register it in dcupl/dcupl.lc.json, and tag the styles.csv resource so the transformer runs on it (and only on it):

dcupl/dcupl.lc.json (resources)
[
  { "type": "model", "url": "${baseUrl}/models/Style.dcupl.json", "tags": [] },
  { "type": "data", "model": "Style", "url": "${baseUrl}/data/styles.csv", "tags": ["styles"] },
  { "type": "model", "url": "${baseUrl}/models/Image.dcupl.json", "tags": [] },
  { "type": "data", "model": "Image", "url": "${baseUrl}/data/images.csv" },
  { "type": "transformer", "url": "${baseUrl}/transformers/link-images.js", "applyTo": ["styles"] }
]

Now image holds an image key on every style. In dcupl/models/Style.dcupl.json, set references to a reference on it, and derive the image URL into the style:

Style.dcupl.json: references
[{ "key": "image", "type": "singleValued", "model": "Image" }]
Style.dcupl.json: add to properties
{ "key": "imageUrl", "type": "string", "derive": { "localReference": "image", "remoteProperty": "link" } }

See Transformers for the transformer types and Derived properties for derive.

Step 4: load the data

terminal
dcupl app create --load --auto-serve

Check one style. The reference resolved and the image URL is on the item:

terminal
dcupl app query one --model Style --item-key 15970 --json
Output
{
  "key": "15970",
  "id": 15970,
  "gender": "Men",
  "masterCategory": "Apparel",
  "subCategory": "Topwear",
  "articleType": "Shirts",
  "baseColour": "Navy Blue",
  "season": "Fall",
  "year": 2011,
  "usage": "Casual",
  "productDisplayName": "Turtle Check Men Navy Blue Shirt",
  "image": { "key": "15970.jpg", "_dcupl_ref_": "hit" },
  "imageUrl": "http://assets.myntassets.com/v1/images/style/properties/7a5b82d1372a7a5c6de67ae7a314fd91_images.jpg"
}

Step 5: query the catalogue

The top-level navigation

The facet of masterCategory is the shop's main navigation, with a count per entry:

terminal
dcupl app fn facets --model Style --attribute masterCategory --sort size-desc --json
Output
[
  { "value": "Apparel", "count": 21400 },
  { "value": "Accessories", "count": 11289 },
  { "value": "Footwear", "count": 9222 },
  { "value": "Personal Care", "count": 2404 },
  { "value": "Free Items", "count": 105 },
  { "value": "Sporting Goods", "count": 25 },
  { "value": "Home", "count": 1 }
]

Facets that follow the filters

Once a shopper picks "Women", the article type facet counts only women's products:

terminal
dcupl app fn facets --model Style --attribute articleType --sort size-desc --limit 5 \
  --query '{"attribute":"gender","operator":"eq","value":"Women"}' --json
Output
[
  { "value": "Kurtas", "count": 1761 },
  { "value": "Handbags", "count": 1689 },
  { "value": "Tops", "count": 1532 },
  { "value": "Heels", "count": 1322 },
  { "value": "Tshirts", "count": 1116 }
]

Narrow it down to women's heels, and the colour facet shows what is left:

terminal
dcupl app fn facets --model Style --attribute baseColour --sort size-desc --limit 4 \
  --query '[{"attribute":"gender","operator":"eq","value":"Women"},{"attribute":"articleType","operator":"eq","value":"Heels"}]' --json
Output
[
  { "value": "Black", "count": 335 },
  { "value": "Brown", "count": 201 },
  { "value": "Gold", "count": 107 },
  { "value": "Blue", "count": 92 }
]

The result list

The products behind the selection, with their image URL:

terminal
dcupl app query execute --model Style \
  --query '[{"attribute":"gender","operator":"eq","value":"Women"},{"attribute":"articleType","operator":"eq","value":"Heels"},{"attribute":"baseColour","operator":"eq","value":"Black"}]' \
  --limit 2 --projection productDisplayName,season,imageUrl --json
Output
[
  {
    "key": "54118",
    "productDisplayName": "Rocia Women Black Flats",
    "season": "Winter",
    "imageUrl": "http://assets.myntassets.com/v1/images/style/properties/8d6fd53f28e010658cdf5c14c43d0cb0_images.jpg"
  },
  {
    "key": "54127",
    "productDisplayName": "Rocia Women Black Heels",
    "season": "Winter",
    "imageUrl": "http://assets.myntassets.com/v1/images/style/properties/50c7dd932d347768b05766e5dd231355_images.jpg"
  }
]

"Flats" filed as Heels is how the source data has it: dcupl returns what the data says.

Type-ahead suggestions

Suggestions for a search box, with the keys of the matching products:

terminal
dcupl app fn suggest --model Style --attribute productDisplayName --value puma --max 3 --json
Output
[
  { "value": "Puma Men Grey T-shirt", "keys": ["53759", "58726", "44875", "58732", "44830", "44897"] },
  { "value": "Puma Men Pack of 3 Socks", "keys": ["29114", "43559", "43561", "29117"] },
  { "value": "Puma Men Future Cat Remix SF Black Casual Shoes", "keys": ["9204"] }
]

When you are done, stop the app with dcupl app destroy.

A flaw in the source file

22 rows of styles.csv have a comma inside the product name without quotes, for example Boss Men Perfume, After Shave Balm and Shower Gel Set. A CSV parser reads the part after the comma as an extra column, so these products load with a shortened name (Boss Men Perfume). Fix the rows in the file, or repair them in a transformer: a rawFileTransformer receives the CSV text before parsing.

Use it in your application

The workspace is a regular dcupl project: in the browser, the loader loads the same models, data and transformer, and list.catalog.fn.facets() and suggest() drive the filter UI. The product catalog tutorial builds that UI step by step, with multi-select filters and a filter manager.