Skip to content

Commit

Permalink
Updated database and wrote a few scripts to test/demo it 🗃️
Browse files Browse the repository at this point in the history
  • Loading branch information
soon-dubu committed Dec 7, 2024
1 parent c28a662 commit b7ea27c
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 97 deletions.
11 changes: 11 additions & 0 deletions color_analysis/download_dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import os
import pandas as pd

# df = pd.read_csv(f'grailed-dataset/styles_grailed.csv')
# print(df.head())
# print(len(df.loc[df["Department"]=="womenswear"]))
num_hits = 40
page_range = 500
for department in ["menswear", "womenswear"]:
for page_num in range(page_range):
os.system(f"python3 get_grailed_items.py -g {department} -n {num_hits} -p {page_num}")
54 changes: 34 additions & 20 deletions color_analysis/get_grailed_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,23 @@ def download_image(save_path, image_url):
handle.write(block)

def get_products(client, product_specifications):

department = product_specifications["department"]
product_specifications.pop("department")
if department=="menswear":
department = Departments.MENSWEAR
else:
department = Departments.WOMENSWEAR
products = client.find_products(
sold=True,
on_sale=True,
conditions=[Conditions.IS_GENTLY_USED, Conditions.IS_NEW],
markets=[Markets.BASIC, Markets.GRAILED],
locations=[Locations.US, Locations.ASIA, Locations.EUROPE],
# department=Departments.MENSWEAR,
department=Departments.WOMENSWEAR,
department=department,
**product_specifications
)

print(f"Fetched {len(products)} products...")
# print(f"Fetched {len(products)} products...")

return products

Expand All @@ -49,22 +55,23 @@ def download_and_save_products(products):
image_url = product["cover_photo"]["image_url"]
save_path = f"{data_path}/images/{product_id}.jpg"
# print(product["category"].split('.'))
data.append(
{
"Id": product_id,
"Department": product["department"],
"MasterCategory": product["category_path_size"].split('.')[0],
"SubCategory": product["category_path_size"].split('.')[1],
"Size": product["category_path_size"].split('.')[2],
"Color": product["color"],
"Designers": product["designers"],
"Hashtags": product["hashtags"],
"ProductDisplayName": product["description"],
"ItemUrl": product["cover_photo"]["url"]
}
)
# check if photo already downloaded
if not os.path.exists(save_path):

data.append(
{
"Id": product_id,
"Department": product["department"],
"MasterCategory": product["category_path_size"].split('.')[0],
"SubCategory": product["category_path_size"].split('.')[1],
"Size": product["category_path_size"].split('.')[2],
"Color": product["color"],
"Designers": product["designers"],
"Hashtags": product["hashtags"],
"ProductDisplayName": product["description"],
"ItemUrl": product["cover_photo"]["url"]
}
)
download_image(save_path, image_url)
num_downloaded+=1
else:
Expand All @@ -73,15 +80,22 @@ def download_and_save_products(products):
print(f"Downloaded {num_downloaded} images; already downloaded {already_downloaded} images in results")
# create empty dataframe
df = pd.DataFrame(data=data, columns=["Id", "Department", "MasterCategory", "SubCategory", "Size", "Color", "Designers", "Hashtags", "ProductDisplayName", "ItemUrl"])
print(df.head())
# print(df.head())
# print(len(df))

if os.path.exists(f'{data_path}/styles_grailed.csv'):
df_old = pd.read_csv(f'{data_path}/styles_grailed.csv')
df = pd.concat([df_old, df])

# print(len(df))
df.to_csv(f'{data_path}/styles_grailed.csv', index=False)

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Fetching and downloading items from Grailed")
# parser.add_argument("--gender", "-g", help="Gender, mens or womens", dest="department")
parser.add_argument("--gender", "-g", help="Gender, mens or womens", dest="department")
parser.add_argument("--query_search", "-q", help="Query to look up", dest="query_search")
parser.add_argument("--num_hits", "-n", help="Number of hits to pull up", dest="hits_per_page", default=1)
parser.add_argument("--page", "-p", help="Page number", dest="page", default=1)
# parser.add_argument("--categories", "-c", helper="Iterable of categories to include")
parser.add_argument("--price_from", "-l", help="Min price", dest="price_from", default=0)
parser.add_argument("--price_to", "-m", help="Max price", dest="price_to", default=100)
Expand Down
Binary file modified color_analysis/grailed.db
Binary file not shown.
32 changes: 0 additions & 32 deletions color_analysis/sample-fashion-dataset.bash

This file was deleted.

Binary file removed color_analysis/small-fashion-dataset.db
Binary file not shown.
12 changes: 6 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuraRequest(BaseModel):
Department: Literal['menswear', 'womenswear']
ColorSeason: Literal['autumn', 'winter', 'spring', 'summer']
# MasterCategory: Literal['Tops', 'Bottoms', 'Outerwear', 'Footwear', 'Tailoring', 'Accessories']
num_outfits: int = 1
n: int = 1


class Items(SQLModel, table=True):
Expand Down Expand Up @@ -132,28 +132,28 @@ async def generate_outfit(
aura_request: AuraRequest
):
# Get tops
tops = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "tops", Items.MasterCategory == "womens_tops")).order_by(func.random()).limit(aura_request.num_outfits)).all()
tops = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "tops", Items.MasterCategory == "womens_tops")).order_by(func.random()).limit(aura_request.n)).all()
if not tops:
raise HTTPException(status_code=404, detail="No matching tops found")

# Get bottoms
bottoms = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "bottoms", Items.MasterCategory == "womens_bottoms")).order_by(func.random()).limit(aura_request.num_outfits)).all()
bottoms = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "bottoms", Items.MasterCategory == "womens_bottoms")).order_by(func.random()).limit(aura_request.n)).all()
if not bottoms:
raise HTTPException(status_code=404, detail="No matching bottoms found")

# Get shoes
shoes = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "footwear", Items.MasterCategory == "womens_footwear")).order_by(func.random()).limit(aura_request.num_outfits)).all()
shoes = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "footwear", Items.MasterCategory == "womens_footwear")).order_by(func.random()).limit(aura_request.n)).all()
if not bottoms:
raise HTTPException(status_code=404, detail="No matching shoes found")

# Get outerwear
outerwear = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "outerwear", Items.MasterCategory == "outerwear")).order_by(func.random()).limit(aura_request.num_outfits)).all()
outerwear = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "outerwear", Items.MasterCategory == "womens_outerwear")).order_by(func.random()).limit(aura_request.n)).all()
if not outerwear:
print("No matching outerwear found")
# raise HTTPException(status_code=404, detail="No matching outerwear found")

# Get accessories
accessories = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "accessories", Items.MasterCategory == "womens_accessories")).order_by(func.random()).limit(aura_request.num_outfits)).all()
accessories = session.exec(select(Items).where(Items.ColorSeason == aura_request.ColorSeason).where(Items.Department == aura_request.Department).where(or_(Items.MasterCategory == "accessories", Items.MasterCategory == "womens_accessories")).order_by(func.random()).limit(aura_request.n)).all()
if not bottoms:
print("No matching accessories found")
# raise HTTPException(status_code=404, detail="No matching outerwear found")
Expand Down
49 changes: 49 additions & 0 deletions tests/database_contents.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="tops"; --217
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="tops"; --132
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="tops"; --220
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="tops"; --160

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="bottoms"; --84
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="bottoms"; --54
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="bottoms"; --72
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="bottoms"; --54

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="footwear"; --13
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="footwear"; --7
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="footwear"; --22
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="footwear"; --11

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="outerwear"; --37
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="outerwear"; --30
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="outerwear"; --51
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="outerwear"; --35

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="accessories"; --160
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="accessories"; --87
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="accessories"; --137
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="accessories"; --99

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="womens_tops"; --231
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="womens_tops"; --125
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="womens_tops"; --163
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="womens_tops"; --133

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="womens_bottoms"; --116
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="womens_bottoms"; --69
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="womens_bottoms"; --85
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="womens_bottoms"; --57

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="womens_footwear"; --56
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="womens_footwear"; --66
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="womens_footwear"; --43
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="womens_footwear"; --39

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="womens_outerwear"; --81
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="womens_outerwear"; --63
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="womens_outerwear"; --56
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="womens_outerwear"; --41

SELECT COUNT(*) FROM items WHERE ColorSeason="spring" AND MasterCategory="womens_accessories"; --81
SELECT COUNT(*) FROM items WHERE ColorSeason="summer" AND MasterCategory="womens_accessories"; --66
SELECT COUNT(*) FROM items WHERE ColorSeason="autumn" AND MasterCategory="womens_accessories"; --67
SELECT COUNT(*) FROM items WHERE ColorSeason="winter" AND MasterCategory="womens_accessories"; --38
117 changes: 78 additions & 39 deletions tests/test_outfit_generation.ipynb

Large diffs are not rendered by default.

0 comments on commit b7ea27c

Please sign in to comment.