NexaClothes / generate_sample_clothes.py
NexaCoders's picture
Create generate_sample_clothes.py
075d78c verified
Raw History Blame Contribute Delete
1.59 kB
import requests
from PIL import Image
import io
import json
import os
import uuid
SAMPLE_CLOTHES_URLS = {
"shirt": [
"https://images.unsplash.com/photo-1521572163474-6864f9cf17ab?w=300&h=400&fit=crop",
"https://images.unsplash.com/photo-1581655353564-df123a1eb820?w=300&h=400&fit=crop",
# Add 48 more...
],
"pants": [
"https://images.unsplash.com/photo-1542272604-787c3835535d?w=300&h=400&fit=crop",
# Add 24 more...
],
"dress": [
"https://images.unsplash.com/photo-1572635196237-14b3f281503f?w=300&h=400&fit=crop",
# Add 24 more...
]
}
def generate_sample_catalog():
os.makedirs("static/sample_clothes", exist_ok=True)
catalog = []
for cloth_type, urls in SAMPLE_CLOTHES_URLS.items():
for i, url in enumerate(urls):
try:
resp = requests.get(url)
img = Image.open(io.BytesIO(resp.content))
img = img.resize((256, 384))
img.save(f"static/sample_clothes/{cloth_type}_{i}.png")
catalog.append({
"image_path": f"static/sample_clothes/{cloth_type}_{i}.png",
"clothing_type": cloth_type,
"name": f"{cloth_type.title()} {i+1}"
})
except:
continue
with open("static/sample_clothes_catalog.json", "w") as f:
json.dump(catalog, f)
print(f"✅ Generated {len(catalog)} sample clothes for HF!")
if __name__ == "__main__":
generate_sample_catalog()