attribution / schema_free.py
thanhnt-cf's picture
update to support user schema
28f26e5
from enum import Enum
from typing import Union
from pydantic import BaseModel, Field
#####
# avoid using the 'import' string, including words like 'important', etc.
class UpperGarmentProperties(BaseModel):
upper_category: str
neck: str
sleeve: str
shoulder: str
waist: str
length: str
class LowerGarmentProperties(BaseModel):
lower_category: str
waist: str
hip: str
rise: str
leg: str
class HatProperties(BaseModel):
style: str
brim: str
class TargetAudience(BaseModel):
age_range: str
style_preference: str
lifestyle: str
class Closure(BaseModel):
color: str
type: str
location: str
class Pattern(BaseModel):
type: str
color: list[str]
class LuggageProperties(BaseModel):
luggage_type: str = Field(..., description="Type of luggage, e.g., suitcase, duffel, backpack, etc.")
size: str = Field(..., description="Size of the luggage, e.g., carry-on, large, extra-large")
material: str = Field(..., description="Material used, e.g., leather, polyester, polycarbonate")
color: list[str] = Field(..., description="Color of the luggage")
weight: str = Field(..., description="Weight of the luggage in kg or lbs")
compartments: int = Field(..., description="Number of compartments")
wheels: str = Field(..., description="Wheel type, e.g., 2-wheel, 4-wheel, or spinner")
handle_type: str = Field(..., description="Type of handle, e.g., retractable, fixed, or no handle")
closure: Closure = Field(..., description="Closure details like type, color, and location")
lock_type: str = Field(..., description="Lock type, e.g., TSA, combination, or none")
expandable: bool = Field(..., description="Whether the luggage is expandable")
waterproof: bool = Field(..., description="Whether the luggage is waterproof or water-resistant")
class HandbagProperties(BaseModel):
handbag_type: str = Field(..., description="Type of handbag, e.g., tote, crossbody, clutch, etc.")
size: str = Field(..., description="Size of the handbag, e.g., small, medium, large")
material: str = Field(..., description="Material used, e.g., leather, canvas, suede")
color: list[str] = Field(..., description="Color of the handbag")
weight: str = Field(..., description="Weight of the handbag in kg or lbs")
compartments: int = Field(..., description="Number of compartments in the handbag")
strap_type: str = Field(..., description="Type of strap, e.g., adjustable, removable, fixed")
handle_type: str = Field(..., description="Type of handle, e.g., top handle, shoulder strap, none")
closure: Closure = Field(..., description="Closure details like type, color, and location")
lock_type: str = Field(..., description="Lock type, e.g., magnetic, zipper, clasp, or none")
pattern: Pattern = Field(..., description="Pattern details")
occasion: list[str] = Field(..., description="Occasions suitable for the handbag, e.g., formal, casual, evening")
waterproof: bool = Field(..., description="Whether the handbag is waterproof or water-resistant")
class MakeupProperties(BaseModel):
makeup_type: str = Field(..., description="Type of makeup, e.g., foundation, lipstick, eyeshadow, mascara, etc.")
shade: str = Field(..., description="Shade of the makeup product")
finish: str = Field(..., description="Finish of the product, e.g., matte, dewy, satin, glossy, etc.")
texture: str = Field(..., description="Texture of the product, e.g., creamy, powder, liquid")
skin_type_compatibility: list[str] = Field(..., description="Skin types compatible with the product, e.g., dry, oily, combination")
waterproof: bool = Field(..., description="Whether the product is waterproof or not")
long_wear: bool = Field(..., description="Whether the product is long-wearing")
cruelty_free: bool = Field(..., description="Whether the product is cruelty-free")
vegan: bool = Field(..., description="Whether the product is vegan")
ingredients: list[str] = Field(..., description="Key ingredients in the product")
packaging_type: str = Field(..., description="Type of packaging, e.g., compact, tube, pump bottle")
application_method: str = Field(..., description="How the product is applied, e.g., brush, sponge, fingers, applicator")
ingredients: list[str] = Field(..., description="If visible in images, what ingredients are in the product")
class ChairProperties(BaseModel):
chair_type: str = Field(..., description="Type of chair, e.g., office chair, dining chair, lounge chair")
material: str = Field(..., description="Material used, e.g., wood, metal, fabric")
upholstery_material: str = Field(..., description="Upholstery material, e.g., leather, fabric, mesh, none")
color: list[str] = Field(..., description="Color of the chair")
weight_capacity: str = Field(..., description="Maximum weight capacity of the chair in kg or lbs")
dimensions: str = Field(..., description="Dimensions of the chair, e.g., height, width, depth")
adjustable: bool = Field(..., description="Whether the chair is adjustable")
swivel: bool = Field(..., description="Whether the chair can swivel")
wheels: bool = Field(..., description="Whether the chair has wheels")
ergonomic: bool = Field(..., description="Whether the chair is ergonomically designed")
class CarpetProperties(BaseModel):
carpet_type: str = Field(..., description="Type of carpet, e.g., area rug, runner, mat")
material: str = Field(..., description="Material used, e.g., wool, synthetic, cotton")
color: list[str] = Field(..., description="Color of the carpet")
dimensions: str = Field(..., description="Dimensions of the carpet, e.g., length and width")
pile_height: str = Field(..., description="Pile height of the carpet in mm or inches")
pattern: Pattern = Field(..., description="Pattern details of the carpet")
anti_slip: bool = Field(..., description="Whether the carpet has anti-slip backing")
washable: bool = Field(..., description="Whether the carpet is washable")
indoor_outdoor: str = Field(..., description="Whether the carpet is meant for indoor or outdoor use")
class WatchProperties(BaseModel):
watch_type: str = Field(..., description="Type of watch, e.g., analog, digital, smart watch, hybrid")
movement_type: str = Field(..., description="Type of movement, e.g., quartz, mechanical, automatic, digital")
material: str = Field(..., description="Material of the watch case, e.g., stainless steel, titanium, plastic")
strap_material: str = Field(..., description="Material of the strap, e.g., leather, rubber, metal, nylon")
strap_color: list[str] = Field(..., description="Color of the watch strap")
dial_color: str = Field(..., description="Color of the watch dial")
water_resistant: bool = Field(..., description="Whether the watch is water-resistant")
water_resistance_depth: str = Field(..., description="Depth rating for water resistance in meters or feet")
features: list[str] = Field(..., description="Special features like GPS, heart rate monitor, chronograph, etc.")
case_diameter: str = Field(..., description="Diameter of the watch case in mm or inches")
case_thickness: str = Field(..., description="Thickness of the watch case in mm or inches")
weight: str = Field(..., description="Weight of the watch")
display_type: str = Field(..., description="Display type for smart/digital watches, e.g., LED, AMOLED, LCD")
battery_life: str = Field(..., description="Battery life for digital or smart watches")
clasp_type: str = Field(..., description="Type of clasp or buckle, e.g., deployant, tang buckle, folding clasp")
class SleepwareProperties(BaseModel):
sleepware_type: str = Field(..., description="Type of sleepware, e.g., pillow, duvet, mattress, mattress topper, blanket")
material: str = Field(..., description="Material used, e.g., cotton, down, memory foam, microfiber")
filling_material: str = Field(..., description="Filling material for pillows or duvets, e.g., down, feather, polyester")
firmness: str = Field(..., description="Firmness level for pillows or mattresses, e.g., soft, medium, firm")
size: str = Field(..., description="Size of the sleepware, e.g., queen, king, standard")
weight: str = Field(..., description="Weight of the sleepware (mainly for duvets and blankets)")
temperature_regulation: bool = Field(..., description="Whether the item has temperature regulation properties")
hypoallergenic: bool = Field(..., description="Whether the item is hypoallergenic")
machine_washable: bool = Field(..., description="Whether the item is machine washable")
thread_count: str = Field(..., description="Thread count for items like sheets or pillowcases")
moisture_wicking: bool = Field(..., description="Whether the material wicks away moisture")
class TablewareProperties(BaseModel):
tableware_type: str = Field(..., description="Type of tableware, e.g., dinner plate, salad bowl, mug, cup, saucer")
material: str = Field(..., description="Material of the tableware, e.g., porcelain, ceramic, glass, stoneware")
color: list[str] = Field(..., description="Color of the tableware")
pattern: Pattern = Field(..., description="Pattern details if applicable")
diameter: str = Field(..., description="Diameter of the tableware (for plates or bowls)")
volume: str = Field(..., description="Volume capacity for bowls, cups, mugs in ml or oz")
dishwasher_safe: bool = Field(..., description="Whether the tableware is dishwasher safe")
microwave_safe: bool = Field(..., description="Whether the tableware is microwave safe")
oven_safe: bool = Field(..., description="Whether the tableware is oven safe")
stackable: bool = Field(..., description="Whether the tableware is stackable")
chip_resistant: bool = Field(..., description="Whether the tableware is chip-resistant")
class CookwareProperties(BaseModel):
cookware_type: str = Field(..., description="Type of cookware, e.g., skillet, saucepan, stockpot, frying pan")
material: str = Field(..., description="Material of the cookware, e.g., stainless steel, cast iron, non-stick, aluminum")
diameter: str = Field(..., description="Diameter of the cookware in cm or inches")
depth: str = Field(..., description="Depth of the cookware in cm or inches")
weight: str = Field(..., description="Weight of the cookware in kg or lbs")
non_stick: bool = Field(..., description="Whether the cookware is non-stick")
induction_safe: bool = Field(..., description="Whether the cookware is safe for induction stoves")
oven_safe: bool = Field(..., description="Whether the cookware is oven safe")
max_oven_temperature: str = Field(..., description="Maximum temperature in Celsius or Fahrenheit for oven use")
dishwasher_safe: bool = Field(..., description="Whether the cookware is dishwasher safe")
handle_material: str = Field(..., description="Material of the handle, e.g., stainless steel, silicone, wood")
lid_included: bool = Field(..., description="Whether the cookware comes with a lid")
heat_distribution: str = Field(..., description="Heat distribution technology, e.g., tri-ply, aluminum core")
class BathroomItemProperties(BaseModel):
item_type: str = Field(..., description="Type of bathroom item, e.g., towel, bath mat, shower curtain")
material: str = Field(..., description="Material of the item, e.g., cotton, microfiber, bamboo")
size: str = Field(..., description="Size of the item, e.g., bath towel, hand towel, washcloth")
gsm: str = Field(..., description="Grams per square meter (GSM) which indicates the density of the towel fabric")
color: list[str] = Field(..., description="Color of the bathroom item")
absorbency: str = Field(..., description="Absorbency level, e.g., high, medium, low")
quick_dry: bool = Field(..., description="Whether the towel has quick-dry properties")
softness: str = Field(..., description="Softness rating, e.g., ultra-soft, soft, firm")
machine_washable: bool = Field(..., description="Whether the item is machine washable")
pattern: Pattern = Field(..., description="Pattern details if applicable")
anti_bacterial: bool = Field(..., description="Whether the towel has anti-bacterial properties")
hypoallergenic: bool = Field(..., description="Whether the towel is hypoallergenic")
class Garment(BaseModel): # don't rename this class
category: str = Field(..., description='Category of the garment')
gender: str
material: str
color: list[str] = Field(..., description='Color of the garment')
pattern: Pattern
style: str
closure: Closure
fit: str = Field(..., description='Should be one of slim fit, regular fit, loose fit')
season: list[str]
occasion: list[str]
special_occasion: list[str] = Field(..., description='List up to three special occasions, such as weddings, halloween or graduation')
usage: list[str]
pairing: list[str]
microtrends: list[str]
silhouette: list[str]
aesthetic: list[str]
dressing_style: list[str]
target_audience: list[TargetAudience]
properties: Union[UpperGarmentProperties, LowerGarmentProperties, HatProperties, LuggageProperties, HandbagProperties, MakeupProperties, ChairProperties, CarpetProperties, WatchProperties, CookwareProperties, TablewareProperties, SleepwareProperties, BathroomItemProperties ] = Field(..., description="Specific properties for different product categories")