Spaces:
Sleeping
Sleeping
Delete libraries
Browse files- libraries/fits/pants_lib.py +0 -63
- libraries/fits/shirts_lib.py +0 -67
- libraries/sizes/pants_lib.py +0 -119
- libraries/sizes/shirts_lib.py +0 -131
libraries/fits/pants_lib.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
from dataclasses import dataclass
|
2 |
-
|
3 |
-
@dataclass
|
4 |
-
class PantsMeasurements:
|
5 |
-
waist: float # in cm
|
6 |
-
hips: float # in cm
|
7 |
-
leg_length: float # in cm
|
8 |
-
|
9 |
-
def determine_fit(measurements: PantsMeasurements) -> str:
|
10 |
-
"""
|
11 |
-
Determine the general fit for pants based on waist, hips, and leg length measurements.
|
12 |
-
|
13 |
-
The algorithm uses two ratios:
|
14 |
-
- Waist-to-Hips Ratio: Lower ratios typically suggest a more tapered (slim) waist.
|
15 |
-
- Leg-to-Hips Ratio: Higher values indicate longer legs relative to hip size.
|
16 |
-
|
17 |
-
Assumed thresholds for demonstration purposes:
|
18 |
-
- Slim Fit: if waist/hips < 0.80 and leg_length/hips >= 1.15
|
19 |
-
- Regular Fit: if 0.80 <= waist/hips <= 0.90 and 1.05 <= leg_length/hips < 1.15
|
20 |
-
- Loose Fit: otherwise
|
21 |
-
|
22 |
-
Args:
|
23 |
-
measurements (PantsMeasurements): The measurements for waist, hips, and leg length.
|
24 |
-
|
25 |
-
Returns:
|
26 |
-
str: A recommendation of 'Slim Fit', 'Regular Fit', or 'Loose Fit'.
|
27 |
-
"""
|
28 |
-
waist_to_hip = measurements.waist / measurements.hips
|
29 |
-
leg_to_hip = measurements.leg_length / measurements.hips
|
30 |
-
|
31 |
-
if waist_to_hip < 0.80 and leg_to_hip >= 1.15:
|
32 |
-
return "Slim Fit"
|
33 |
-
elif 0.80 <= waist_to_hip <= 0.90 and 1.05 <= leg_to_hip < 1.15:
|
34 |
-
return "Regular Fit"
|
35 |
-
else:
|
36 |
-
return "Loose Fit"
|
37 |
-
|
38 |
-
def get_fit(waist: float, hips: float, leg_length: float) -> str:
|
39 |
-
"""
|
40 |
-
Get a fit recommendation for pants based on input measurements.
|
41 |
-
|
42 |
-
Args:
|
43 |
-
waist (float): Waist measurement in cm.
|
44 |
-
hips (float): Hip measurement in cm.
|
45 |
-
leg_length (float): Leg length measurement in cm.
|
46 |
-
|
47 |
-
Returns:
|
48 |
-
str: The recommended pants fit category.
|
49 |
-
"""
|
50 |
-
measurements = PantsMeasurements(waist=waist, hips=hips, leg_length=leg_length)
|
51 |
-
return determine_fit(measurements)
|
52 |
-
|
53 |
-
if __name__ == "__main__":
|
54 |
-
try:
|
55 |
-
waist_input = float(input("Enter your waist measurement (cm): "))
|
56 |
-
hips_input = float(input("Enter your hip measurement (cm): "))
|
57 |
-
leg_length_input = float(input("Enter your leg length measurement (cm): "))
|
58 |
-
except ValueError:
|
59 |
-
print("Please enter valid numeric values.")
|
60 |
-
exit(1)
|
61 |
-
|
62 |
-
recommended_fit = get_fit(waist_input, hips_input, leg_length_input)
|
63 |
-
print(f"Based on your measurements, your recommended fit for pants is: {recommended_fit}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libraries/fits/shirts_lib.py
DELETED
@@ -1,67 +0,0 @@
|
|
1 |
-
from dataclasses import dataclass
|
2 |
-
|
3 |
-
@dataclass
|
4 |
-
class BodyMeasurements:
|
5 |
-
shoulder: float # in cm
|
6 |
-
chest: float # in cm
|
7 |
-
waist: float # in cm
|
8 |
-
|
9 |
-
def determine_fit(measurements: BodyMeasurements) -> str:
|
10 |
-
"""
|
11 |
-
Determine the general fit based on shoulder, chest, and waist measurements.
|
12 |
-
|
13 |
-
The algorithm uses two simple ratios:
|
14 |
-
- waist-to-chest ratio: a lower ratio suggests a more tapered torso (slim fit).
|
15 |
-
- chest-to-shoulder ratio: a higher ratio suggests a broader chest relative to the shoulder,
|
16 |
-
which is often associated with a slimmer profile.
|
17 |
-
|
18 |
-
Thresholds (assumed for demonstration purposes):
|
19 |
-
- Slim Fit: waist/chest < 0.85 and chest/shoulder >= 1.45
|
20 |
-
- Regular Fit: waist/chest between 0.85 and 0.95 and chest/shoulder between 1.3 and 1.45
|
21 |
-
- Loose Fit: any measurements outside the above ranges
|
22 |
-
|
23 |
-
Args:
|
24 |
-
measurements (BodyMeasurements): User measurements in centimeters.
|
25 |
-
|
26 |
-
Returns:
|
27 |
-
str: A recommendation of 'Slim Fit', 'Regular Fit', or 'Loose Fit'.
|
28 |
-
"""
|
29 |
-
# Calculate ratios
|
30 |
-
waist_chest_ratio = measurements.waist / measurements.chest
|
31 |
-
chest_shoulder_ratio = measurements.chest / measurements.shoulder
|
32 |
-
|
33 |
-
# Determine fit based on ratio thresholds
|
34 |
-
if waist_chest_ratio < 0.85 and chest_shoulder_ratio >= 1.45:
|
35 |
-
return "Slim Fit"
|
36 |
-
elif 0.85 <= waist_chest_ratio <= 0.95 and 1.3 <= chest_shoulder_ratio < 1.45:
|
37 |
-
return "Regular Fit"
|
38 |
-
else:
|
39 |
-
return "Loose Fit"
|
40 |
-
|
41 |
-
def get_fit(shoulder: float, chest: float, waist: float) -> str:
|
42 |
-
"""
|
43 |
-
Get a fit recommendation based on input measurements.
|
44 |
-
|
45 |
-
Args:
|
46 |
-
shoulder (float): Shoulder measurement in cm.
|
47 |
-
chest (float): Chest measurement in cm.
|
48 |
-
waist (float): Waist measurement in cm.
|
49 |
-
|
50 |
-
Returns:
|
51 |
-
str: The recommended fit category.
|
52 |
-
"""
|
53 |
-
measurements = BodyMeasurements(shoulder=shoulder, chest=chest, waist=waist)
|
54 |
-
return determine_fit(measurements)
|
55 |
-
|
56 |
-
if __name__ == "__main__":
|
57 |
-
# Example interactive usage:
|
58 |
-
try:
|
59 |
-
shoulder_input = float(input("Enter your shoulder measurement (cm): "))
|
60 |
-
chest_input = float(input("Enter your chest measurement (cm): "))
|
61 |
-
waist_input = float(input("Enter your waist measurement (cm): "))
|
62 |
-
except ValueError:
|
63 |
-
print("Please enter valid numeric values.")
|
64 |
-
exit(1)
|
65 |
-
|
66 |
-
recommended_fit = get_fit(shoulder_input, chest_input, waist_input)
|
67 |
-
print(f"Based on your measurements, your recommended fit is: {recommended_fit}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libraries/sizes/pants_lib.py
DELETED
@@ -1,119 +0,0 @@
|
|
1 |
-
from typing import List, Dict, Tuple
|
2 |
-
from dataclasses import dataclass
|
3 |
-
import json
|
4 |
-
from enum import Enum
|
5 |
-
|
6 |
-
class SizeLabel(Enum):
|
7 |
-
XS = 1
|
8 |
-
S = 2
|
9 |
-
M = 3
|
10 |
-
L = 4
|
11 |
-
XL = 5
|
12 |
-
XXL = 6
|
13 |
-
|
14 |
-
@dataclass
|
15 |
-
class SizeRange:
|
16 |
-
label: str
|
17 |
-
waist: List[int]
|
18 |
-
hip: List[int]
|
19 |
-
length: List[int]
|
20 |
-
|
21 |
-
@dataclass
|
22 |
-
class Brand:
|
23 |
-
brand: str
|
24 |
-
sizes: List[SizeRange]
|
25 |
-
|
26 |
-
def load_size_data() -> List[Brand]:
|
27 |
-
"""Load and parse the size data from JSON."""
|
28 |
-
with open('./data/size_data_pants.json', 'r') as f:
|
29 |
-
data = json.load(f)
|
30 |
-
|
31 |
-
brands = []
|
32 |
-
for brand_data in data:
|
33 |
-
sizes = []
|
34 |
-
for size in brand_data['sizes']:
|
35 |
-
sizes.append(SizeRange(
|
36 |
-
label=size['label'],
|
37 |
-
waist=size['waist'],
|
38 |
-
hip=size['hip'],
|
39 |
-
length=size['length']
|
40 |
-
))
|
41 |
-
brands.append(Brand(brand=brand_data['brand'], sizes=sizes))
|
42 |
-
return brands
|
43 |
-
|
44 |
-
def find_size_category(measurement: int, ranges: List[List[int]]) -> List[int]:
|
45 |
-
"""Find matching size indices for a given measurement."""
|
46 |
-
return [i for i, (min_val, max_val) in enumerate(ranges) if min_val <= measurement <= max_val]
|
47 |
-
|
48 |
-
def get_best_size(brand_name: str, waist: int, hip: int, length: int) -> Tuple[str, Dict[str, str]]:
|
49 |
-
"""
|
50 |
-
Determine the best size for given measurements and brand.
|
51 |
-
|
52 |
-
Args:
|
53 |
-
brand_name (str): Name of the brand
|
54 |
-
waist (int): Waist measurement in cm
|
55 |
-
hip (int): Hip measurement in cm
|
56 |
-
length (int): Pants length in cm
|
57 |
-
|
58 |
-
Returns:
|
59 |
-
Tuple[str, Dict[str, str]]: Recommended size label and detailed fit information
|
60 |
-
"""
|
61 |
-
brands = load_size_data()
|
62 |
-
|
63 |
-
brand = next((b for b in brands if b.brand.lower() == brand_name.lower()), None)
|
64 |
-
if not brand:
|
65 |
-
raise ValueError(f"Brand '{brand_name}' not found")
|
66 |
-
|
67 |
-
waist_ranges = [size.waist for size in brand.sizes]
|
68 |
-
hip_ranges = [size.hip for size in brand.sizes]
|
69 |
-
length_ranges = [size.length for size in brand.sizes]
|
70 |
-
|
71 |
-
waist_sizes = find_size_category(waist, waist_ranges)
|
72 |
-
hip_sizes = find_size_category(hip, hip_ranges)
|
73 |
-
length_sizes = find_size_category(length, length_ranges)
|
74 |
-
|
75 |
-
if not waist_sizes or not hip_sizes or not length_sizes:
|
76 |
-
measurements_info = {
|
77 |
-
"waist": "too small" if waist < waist_ranges[0][0] else "too large" if waist > waist_ranges[-1][1] else "ok",
|
78 |
-
"hip": "too small" if hip < hip_ranges[0][0] else "too large" if hip > hip_ranges[-1][1] else "ok",
|
79 |
-
"length": "too short" if length < length_ranges[0][0] else "too long" if length > length_ranges[-1][1] else "ok"
|
80 |
-
}
|
81 |
-
return "No exact fit", measurements_info
|
82 |
-
|
83 |
-
all_indices = waist_sizes + hip_sizes + length_sizes
|
84 |
-
avg_size_index = round(sum(all_indices) / len(all_indices))
|
85 |
-
|
86 |
-
recommended_size = brand.sizes[avg_size_index].label
|
87 |
-
|
88 |
-
fit_info = {
|
89 |
-
"waist": "perfect" if avg_size_index in waist_sizes else "tight" if avg_size_index > max(waist_sizes) else "loose",
|
90 |
-
"hip": "perfect" if avg_size_index in hip_sizes else "tight" if avg_size_index > max(hip_sizes) else "loose",
|
91 |
-
"length": "perfect" if avg_size_index in length_sizes else "short" if avg_size_index > max(length_sizes) else "long"
|
92 |
-
}
|
93 |
-
|
94 |
-
return recommended_size, fit_info
|
95 |
-
|
96 |
-
def print_size_recommendation(brand: str, waist: int, hip: int, length: int) -> None:
|
97 |
-
"""
|
98 |
-
Print a formatted size recommendation.
|
99 |
-
|
100 |
-
Args:
|
101 |
-
brand (str): Brand name
|
102 |
-
waist (int): Waist measurement in cm
|
103 |
-
hip (int): Hip measurement in cm
|
104 |
-
length (int): Pants length in cm
|
105 |
-
"""
|
106 |
-
try:
|
107 |
-
size, fit_info = get_best_size(brand, waist, hip, length)
|
108 |
-
print(f"\nSize Recommendation for {brand}:")
|
109 |
-
print(f"Recommended size: {size}")
|
110 |
-
print("\nFit Details:")
|
111 |
-
print(f"Waist: {fit_info['waist']}")
|
112 |
-
print(f"Hip: {fit_info['hip']}")
|
113 |
-
print(f"Length: {fit_info['length']}")
|
114 |
-
except ValueError as e:
|
115 |
-
print(f"Error: {str(e)}")
|
116 |
-
|
117 |
-
# Example usage
|
118 |
-
if __name__ == "__main__":
|
119 |
-
print_size_recommendation("Zara", 80, 95, 105)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libraries/sizes/shirts_lib.py
DELETED
@@ -1,131 +0,0 @@
|
|
1 |
-
from typing import List, Dict, Union, Tuple
|
2 |
-
from dataclasses import dataclass
|
3 |
-
import json
|
4 |
-
from enum import Enum
|
5 |
-
|
6 |
-
class SizeLabel(Enum):
|
7 |
-
XS = 1
|
8 |
-
S = 2
|
9 |
-
M = 3
|
10 |
-
L = 4
|
11 |
-
XL = 5
|
12 |
-
XXL = 6
|
13 |
-
|
14 |
-
@dataclass
|
15 |
-
class SizeRange:
|
16 |
-
label: str
|
17 |
-
chest: List[int]
|
18 |
-
waist: List[int]
|
19 |
-
shoulder: List[int]
|
20 |
-
|
21 |
-
@dataclass
|
22 |
-
class Brand:
|
23 |
-
brand: str
|
24 |
-
sizes: List[SizeRange]
|
25 |
-
|
26 |
-
def load_size_data() -> List[Brand]:
|
27 |
-
"""Load and parse the size data from JSON."""
|
28 |
-
with open('./data/size_data_shirts.json', 'r') as f:
|
29 |
-
data = json.load(f)
|
30 |
-
|
31 |
-
brands = []
|
32 |
-
for brand_data in data:
|
33 |
-
sizes = []
|
34 |
-
for size in brand_data['sizes']:
|
35 |
-
sizes.append(SizeRange(
|
36 |
-
label=size['label'],
|
37 |
-
chest=size['chest'],
|
38 |
-
waist=size['waist'],
|
39 |
-
shoulder=size['shoulder']
|
40 |
-
))
|
41 |
-
brands.append(Brand(brand=brand_data['brand'], sizes=sizes))
|
42 |
-
return brands
|
43 |
-
|
44 |
-
def find_size_category(measurement: int, ranges: List[List[int]]) -> List[int]:
|
45 |
-
"""Find matching size indices for a given measurement."""
|
46 |
-
matching_sizes = []
|
47 |
-
for i, (min_val, max_val) in enumerate(ranges):
|
48 |
-
if min_val <= measurement <= max_val:
|
49 |
-
matching_sizes.append(i)
|
50 |
-
return matching_sizes
|
51 |
-
|
52 |
-
def get_best_size(brand_name: str, chest: int, waist: int, shoulder: int) -> Tuple[str, Dict[str, str]]:
|
53 |
-
"""
|
54 |
-
Determine the best size for given measurements and brand.
|
55 |
-
|
56 |
-
Args:
|
57 |
-
brand_name (str): Name of the brand (e.g., "Zara", "H&M", "Dior")
|
58 |
-
chest (int): Chest measurement in centimeters
|
59 |
-
waist (int): Waist measurement in centimeters
|
60 |
-
shoulder (int): Shoulder measurement in centimeters
|
61 |
-
|
62 |
-
Returns:
|
63 |
-
Tuple[str, Dict[str, str]]: Recommended size label and detailed fit information
|
64 |
-
"""
|
65 |
-
brands = load_size_data()
|
66 |
-
|
67 |
-
# Find the brand
|
68 |
-
brand = next((b for b in brands if b.brand.lower() == brand_name.lower()), None)
|
69 |
-
if not brand:
|
70 |
-
raise ValueError(f"Brand '{brand_name}' not found")
|
71 |
-
|
72 |
-
# Get all size ranges for the brand
|
73 |
-
chest_ranges = [size.chest for size in brand.sizes]
|
74 |
-
waist_ranges = [size.waist for size in brand.sizes]
|
75 |
-
shoulder_ranges = [size.shoulder for size in brand.sizes]
|
76 |
-
|
77 |
-
# Find matching sizes for each measurement
|
78 |
-
chest_sizes = find_size_category(chest, chest_ranges)
|
79 |
-
waist_sizes = find_size_category(waist, waist_ranges)
|
80 |
-
shoulder_sizes = find_size_category(shoulder, shoulder_ranges)
|
81 |
-
|
82 |
-
# If any measurement doesn't fit in any range
|
83 |
-
if not chest_sizes or not waist_sizes or not shoulder_sizes:
|
84 |
-
measurements_info = {
|
85 |
-
"chest": "too small" if chest < chest_ranges[0][0] else "too large" if chest > chest_ranges[-1][1] else "ok",
|
86 |
-
"waist": "too small" if waist < waist_ranges[0][0] else "too large" if waist > waist_ranges[-1][1] else "ok",
|
87 |
-
"shoulder": "too small" if shoulder < shoulder_ranges[0][0] else "too large" if shoulder > shoulder_ranges[-1][1] else "ok"
|
88 |
-
}
|
89 |
-
return "No exact fit", measurements_info
|
90 |
-
|
91 |
-
# Calculate the average size index
|
92 |
-
all_indices = chest_sizes + waist_sizes + shoulder_sizes
|
93 |
-
avg_size_index = round(sum(all_indices) / len(all_indices))
|
94 |
-
|
95 |
-
# Get the recommended size label
|
96 |
-
recommended_size = brand.sizes[avg_size_index].label
|
97 |
-
|
98 |
-
# Prepare detailed fit information
|
99 |
-
fit_info = {
|
100 |
-
"chest": "perfect" if avg_size_index in chest_sizes else "tight" if avg_size_index > max(chest_sizes) else "loose",
|
101 |
-
"waist": "perfect" if avg_size_index in waist_sizes else "tight" if avg_size_index > max(waist_sizes) else "loose",
|
102 |
-
"shoulder": "perfect" if avg_size_index in shoulder_sizes else "tight" if avg_size_index > max(shoulder_sizes) else "loose"
|
103 |
-
}
|
104 |
-
|
105 |
-
return recommended_size, fit_info
|
106 |
-
|
107 |
-
def print_size_recommendation(brand: str, chest: int, waist: int, shoulder: int) -> None:
|
108 |
-
"""
|
109 |
-
Print a formatted size recommendation.
|
110 |
-
|
111 |
-
Args:
|
112 |
-
brand (str): Brand name
|
113 |
-
chest (int): Chest measurement in cm
|
114 |
-
waist (int): Waist measurement in cm
|
115 |
-
shoulder (int): Shoulder measurement in cm
|
116 |
-
"""
|
117 |
-
try:
|
118 |
-
size, fit_info = get_best_size(brand, chest, waist, shoulder)
|
119 |
-
print(f"\nSize Recommendation for {brand}:")
|
120 |
-
print(f"Recommended size: {size}")
|
121 |
-
print("\nFit Details:")
|
122 |
-
print(f"Chest: {fit_info['chest']}")
|
123 |
-
print(f"Waist: {fit_info['waist']}")
|
124 |
-
print(f"Shoulder: {fit_info['shoulder']}")
|
125 |
-
except ValueError as e:
|
126 |
-
print(f"Error: {str(e)}")
|
127 |
-
|
128 |
-
# Example usage
|
129 |
-
if __name__ == "__main__":
|
130 |
-
# Example measurements
|
131 |
-
print_size_recommendation("Zara", 95, 80, 43) # Example measurements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|