Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
jadewang26 committed Dec 7, 2024
2 parents 4dd32c7 + e901f0e commit bf4a9b1
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 97 deletions.
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 @@ -15,7 +15,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 @@ -143,28 +143,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
117 changes: 78 additions & 39 deletions tests/test_outfit_generation.ipynb

Large diffs are not rendered by default.

0 comments on commit bf4a9b1

Please sign in to comment.