|
|
|
|
|
from typing import Dict, List |
|
|
|
|
|
class UniversalObjectPrompts: |
|
|
""" |
|
|
通用物品描述 Prompt 庫 |
|
|
涵蓋日常物品、動物、交通工具、電子產品等 |
|
|
確保系統能夠描述各種類型的圖片 |
|
|
""" |
|
|
|
|
|
def __init__(self): |
|
|
"""初始化通用物品詞彙庫""" |
|
|
|
|
|
self.object_vocabularies = { |
|
|
|
|
|
'animals': { |
|
|
'dogs': [ |
|
|
'friendly dog with expressive eyes and playful demeanor', |
|
|
'canine companion with soft fur and loyal presence', |
|
|
'domestic dog breed with distinct markings and alert posture', |
|
|
'pet dog in outdoor setting with natural behavior', |
|
|
'puppy with cute features and energetic personality', |
|
|
'large breed dog with muscular build and protective stance', |
|
|
'small lap dog with fluffy coat and adorable expression', |
|
|
'working dog demonstrating intelligence and trained skills', |
|
|
'mixed breed dog with unique features and charming character', |
|
|
'dog portrait with focused gaze and photogenic qualities' |
|
|
], |
|
|
'cats': [ |
|
|
'elegant cat with graceful posture and alert expression', |
|
|
'feline companion with soft fur and independent character', |
|
|
'domestic cat with distinctive markings and curious nature', |
|
|
'cat resting in comfortable position with relaxed demeanor', |
|
|
'kitten with playful energy and adorable tiny features', |
|
|
'long-haired cat with fluffy coat and majestic appearance', |
|
|
'short-haired cat with sleek coat and athletic build', |
|
|
'cat portrait with piercing eyes and photogenic pose', |
|
|
'tabby cat with striped pattern and charming personality', |
|
|
'cat in natural sunlight with warm ambient lighting' |
|
|
], |
|
|
'birds': [ |
|
|
'colorful bird with vibrant plumage and natural beauty', |
|
|
'bird in flight with spread wings and dynamic motion', |
|
|
'perched bird with detailed feather texture and alert posture', |
|
|
'exotic bird species with distinctive beak and eye markings', |
|
|
'songbird with delicate features and graceful appearance', |
|
|
'bird of prey with powerful build and intense gaze', |
|
|
'waterfowl with sleek feathers and aquatic adaptation', |
|
|
'tropical bird with brilliant colors and exotic appeal', |
|
|
'bird feeding or foraging showing natural behavior', |
|
|
'bird silhouette against sky with artistic composition' |
|
|
], |
|
|
'wildlife': [ |
|
|
'wildlife creature in natural habitat showing authentic behavior', |
|
|
'wild animal with powerful build and majestic presence', |
|
|
'forest wildlife with camouflage coloring and alert senses', |
|
|
'marine wildlife with aquatic adaptation and fluid movement', |
|
|
'safari animal with distinctive features and exotic appeal', |
|
|
'small mammal with cute features and curious expression', |
|
|
'endangered species with conservation importance and beauty', |
|
|
'nocturnal animal with adapted eyes and nighttime behavior', |
|
|
'wildlife portrait with environmental context and natural light', |
|
|
'animal in motion demonstrating speed agility or power' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'vehicles': { |
|
|
'cars': [ |
|
|
'modern automobile with sleek design and aerodynamic lines', |
|
|
'luxury car with premium finish and sophisticated styling', |
|
|
'sports car with aggressive stance and performance aesthetics', |
|
|
'classic car with vintage charm and timeless design', |
|
|
'electric vehicle with futuristic design and eco-friendly appeal', |
|
|
'SUV with robust build and commanding presence', |
|
|
'sedan with elegant profile and comfortable proportions', |
|
|
'convertible with open top and free-spirited character', |
|
|
'vintage automobile with chrome details and nostalgic beauty', |
|
|
'race car with aerodynamic body and competition livery' |
|
|
], |
|
|
'motorcycles': [ |
|
|
'motorcycle with powerful engine and dynamic design', |
|
|
'cruiser bike with low profile and relaxed riding position', |
|
|
'sport bike with aggressive fairings and racing aesthetics', |
|
|
'vintage motorcycle with classic styling and heritage appeal', |
|
|
'custom bike with unique modifications and personal touches', |
|
|
'touring motorcycle with comfort features and long-distance capability', |
|
|
'dirt bike with off-road tires and rugged construction', |
|
|
'scooter with practical design and urban mobility', |
|
|
'cafe racer with minimalist design and retro styling', |
|
|
'adventure motorcycle with all-terrain capability and robust build' |
|
|
], |
|
|
'bicycles': [ |
|
|
'road bike with lightweight frame and racing geometry', |
|
|
'mountain bike with suspension and off-road tires', |
|
|
'vintage bicycle with classic design and nostalgic charm', |
|
|
'urban commuter bike with practical features and city-ready design', |
|
|
'electric bicycle with motor assist and modern technology', |
|
|
'BMX bike with compact frame and trick-ready build', |
|
|
'touring bicycle with panniers and long-distance setup', |
|
|
'folding bike with space-saving design and portability', |
|
|
'fixed gear bike with minimalist aesthetic and urban style', |
|
|
'cruiser bicycle with comfortable seat and relaxed riding position' |
|
|
], |
|
|
'public_transport': [ |
|
|
'city bus with public transit livery and urban setting', |
|
|
'train at station with platform and passenger environment', |
|
|
'subway car with interior lighting and metro system', |
|
|
'tram on city streets with overhead wires and urban backdrop', |
|
|
'ferry boat with water transportation and maritime setting', |
|
|
'taxi cab with distinctive markings and urban context', |
|
|
'double-decker bus with iconic design and city character', |
|
|
'monorail with elevated track and futuristic appearance', |
|
|
'light rail vehicle with modern design and efficient transit', |
|
|
'cable car with hillside location and scenic views' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'electronics': { |
|
|
'smartphones': [ |
|
|
'modern smartphone with edge-to-edge display and sleek design', |
|
|
'mobile phone with premium materials and minimalist aesthetic', |
|
|
'smartphone showing screen interface with app icons and features', |
|
|
'phone with camera system and advanced photography capabilities', |
|
|
'mobile device with protective case and personal accessories', |
|
|
'smartphone in hand demonstrating use and scale', |
|
|
'phone with wireless charging and modern conveniences', |
|
|
'mobile phone with notification screen and communication features', |
|
|
'smartphone capturing photo showing photography in action', |
|
|
'device with headphones and mobile entertainment setup' |
|
|
], |
|
|
'laptops': [ |
|
|
'laptop computer with open screen and modern workspace', |
|
|
'portable computer with sleek design and professional appearance', |
|
|
'laptop showing desktop interface and productivity software', |
|
|
'computer with external peripherals and complete workstation', |
|
|
'thin and light laptop with premium build and portability', |
|
|
'gaming laptop with powerful specs and aggressive styling', |
|
|
'laptop in cafe setting with remote work environment', |
|
|
'computer with split screen showing multitasking capability', |
|
|
'laptop with coding environment and developer workflow', |
|
|
'portable computer with creative software and design work' |
|
|
], |
|
|
'cameras': [ |
|
|
'professional camera with interchangeable lens and manual controls', |
|
|
'DSLR camera with telephoto lens and photography equipment', |
|
|
'mirrorless camera with compact design and modern features', |
|
|
'vintage film camera with classic design and analog charm', |
|
|
'action camera with rugged housing and adventure ready build', |
|
|
'instant camera with retro aesthetic and print functionality', |
|
|
'camera on tripod with stable shooting setup', |
|
|
'photography gear with lenses filters and accessories', |
|
|
"camera with viewfinder showing photographer's perspective", |
|
|
'compact camera with point-and-shoot simplicity' |
|
|
], |
|
|
'wearables': [ |
|
|
'smartwatch with digital display and fitness tracking features', |
|
|
'fitness tracker with health monitoring and activity data', |
|
|
'wireless earbuds with charging case and modern design', |
|
|
'smart glasses with augmented reality and tech integration', |
|
|
'VR headset with immersive technology and gaming capability', |
|
|
'smart ring with minimalist design and health sensors', |
|
|
'activity band with water resistance and sport features', |
|
|
'wireless headphones with noise cancellation and premium audio', |
|
|
'smart jewelry with notification features and elegant styling', |
|
|
'wearable device with heart rate monitor and workout tracking' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'home_items': { |
|
|
'furniture': [ |
|
|
'modern sofa with clean lines and comfortable upholstery', |
|
|
'wooden dining table with natural grain and family seating', |
|
|
'contemporary chair with ergonomic design and stylish form', |
|
|
'bookshelf with organized volumes and decorative objects', |
|
|
'bed with plush bedding and inviting sleep environment', |
|
|
'desk with workspace organization and productive setup', |
|
|
'coffee table with minimalist design and functional surface', |
|
|
'cabinet with storage solutions and practical organization', |
|
|
'armchair with cozy cushioning and reading nook appeal', |
|
|
'sideboard with display area and dining room elegance' |
|
|
], |
|
|
'decor': [ |
|
|
'wall art with framed artwork and gallery wall aesthetic', |
|
|
'decorative plant with lush foliage and natural greenery', |
|
|
'vase with fresh flowers and elegant arrangement', |
|
|
'candles with ambient lighting and cozy atmosphere', |
|
|
'throw pillows with colorful patterns and comfort layers', |
|
|
'mirror with decorative frame and space-enhancing reflection', |
|
|
'rug with textile pattern and floor covering warmth', |
|
|
'sculpture with artistic form and decorative presence', |
|
|
'decorative bowls with artisan craft and functional beauty', |
|
|
'wall clock with timepiece function and design statement' |
|
|
], |
|
|
'kitchenware': [ |
|
|
'ceramic plates with elegant design and table setting ready', |
|
|
'glassware with crystal clarity and beverage service', |
|
|
'cookware with non-stick surface and culinary preparation', |
|
|
'cutting board with natural wood and food prep surface', |
|
|
'kitchen utensils with stainless steel and cooking tools', |
|
|
'coffee maker with brewing capability and morning ritual', |
|
|
'mixing bowls with nesting design and baking essentials', |
|
|
'serving platters with presentation surface and entertaining ready', |
|
|
'storage containers with organization and food preservation', |
|
|
'tea kettle with stovetop heating and beverage preparation' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'fashion_accessories': { |
|
|
'shoes': [ |
|
|
'leather shoes with polished finish and formal elegance', |
|
|
'sneakers with athletic design and casual comfort', |
|
|
'high heels with sophisticated style and fashion statement', |
|
|
'boots with rugged construction and seasonal appropriateness', |
|
|
'sandals with open design and warm weather comfort', |
|
|
'loafers with slip-on convenience and smart casual style', |
|
|
'running shoes with performance features and sport technology', |
|
|
'dress shoes with refined appearance and occasion ready', |
|
|
'canvas shoes with casual aesthetic and everyday wearability', |
|
|
'designer footwear with luxury branding and premium materials' |
|
|
], |
|
|
'bags': [ |
|
|
'leather handbag with structured form and quality craftsmanship', |
|
|
'backpack with practical compartments and daily carry capability', |
|
|
'tote bag with spacious interior and versatile use', |
|
|
'clutch with compact elegance and evening sophistication', |
|
|
'messenger bag with crossbody strap and urban function', |
|
|
'duffel bag with travel capacity and gym ready design', |
|
|
'satchel with classic styling and professional appearance', |
|
|
'wallet with organized card slots and essential storage', |
|
|
'shoulder bag with adjustable strap and comfortable carry', |
|
|
'luxury bag with designer branding and premium construction' |
|
|
], |
|
|
'jewelry': [ |
|
|
'necklace with pendant design and elegant neckline accent', |
|
|
'earrings with gemstone sparkle and facial framing beauty', |
|
|
'ring with precious metal and symbolic significance', |
|
|
'bracelet with linked design and wrist adornment', |
|
|
'watch with timepiece function and wrist jewelry appeal', |
|
|
'brooch with decorative pin and vintage charm', |
|
|
'anklet with delicate chain and summer accessory style', |
|
|
'cufflinks with formal accent and menswear detail', |
|
|
'charm bracelet with personal tokens and memory collection', |
|
|
'statement jewelry with bold design and fashion impact' |
|
|
], |
|
|
'eyewear': [ |
|
|
'sunglasses with UV protection and stylish frames', |
|
|
'eyeglasses with prescription lenses and daily wear design', |
|
|
'aviator sunglasses with classic pilot styling and metal frame', |
|
|
'cat-eye glasses with vintage inspired shape and feminine flair', |
|
|
'sport sunglasses with wraparound design and performance features', |
|
|
'reading glasses with magnification and close-work utility', |
|
|
'designer eyewear with luxury branding and premium materials', |
|
|
'mirrored sunglasses with reflective lenses and modern edge', |
|
|
'oversized sunglasses with dramatic proportions and fashion statement', |
|
|
'safety glasses with protective function and durable construction' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'sports_equipment': { |
|
|
'fitness': [ |
|
|
'dumbbells with weight plates and strength training equipment', |
|
|
'yoga mat with non-slip surface and exercise foundation', |
|
|
'resistance bands with elastic tension and portable workout', |
|
|
'kettlebell with cast iron construction and functional training', |
|
|
'foam roller with massage texture and recovery tool', |
|
|
'exercise ball with inflatable design and core workout', |
|
|
'jump rope with cardio training and coordination exercise', |
|
|
'weight bench with adjustable positions and lifting support', |
|
|
'pull-up bar with doorframe mounting and bodyweight exercise', |
|
|
'treadmill with running surface and cardio machine' |
|
|
], |
|
|
'outdoor_sports': [ |
|
|
'tennis racket with string tension and court sport equipment', |
|
|
'basketball with leather or composite cover and game ready', |
|
|
'soccer ball with classic panel design and field sport', |
|
|
'golf clubs with metal woods and iron set', |
|
|
'baseball glove with leather construction and catching mitt', |
|
|
'skateboard with deck grip tape and wheel assembly', |
|
|
'surfboard with wax coating and wave riding design', |
|
|
'snowboard with bindings and mountain sport equipment', |
|
|
'hiking boots with ankle support and trail ready tread', |
|
|
'camping tent with weatherproof fabric and outdoor shelter' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'musical_instruments': { |
|
|
'string': [ |
|
|
'acoustic guitar with wooden body and string instrument charm', |
|
|
'electric guitar with solid body and amplified rock sound', |
|
|
'violin with curved body and classical string beauty', |
|
|
'cello with rich tone and orchestral presence', |
|
|
'bass guitar with deep sound and rhythm section foundation', |
|
|
'ukulele with small size and tropical string instrument', |
|
|
'harp with multiple strings and angelic sound quality', |
|
|
'banjo with circular body and folk music character', |
|
|
'mandolin with paired strings and bright tone', |
|
|
'sitar with resonating strings and world music heritage' |
|
|
], |
|
|
'keyboard': [ |
|
|
'piano with ivory keys and classical instrument elegance', |
|
|
'keyboard synthesizer with electronic sound and modern music', |
|
|
'organ with multiple manuals and church music tradition', |
|
|
'electric piano with vintage tone and stage performance', |
|
|
'digital piano with weighted keys and home practice', |
|
|
'accordion with bellows and folk dance music', |
|
|
'MIDI controller with production capability and studio tool', |
|
|
'harpsichord with baroque styling and historical instrument', |
|
|
'melodica with breath control and portable keyboard', |
|
|
'keytar with shoulder strap and performance showmanship' |
|
|
], |
|
|
'percussion': [ |
|
|
'drum kit with multiple pieces and rhythmic foundation', |
|
|
'djembe with hand drumming and African rhythm', |
|
|
'conga drums with Latin percussion and tropical beat', |
|
|
'tambourine with jingles and shaker instrument', |
|
|
'bongos with paired drums and Latin music style', |
|
|
'xylophone with mallet playing and melodic percussion', |
|
|
'cymbals with crash sound and orchestral accent', |
|
|
'maracas with rattle sound and Latin rhythm shaker', |
|
|
'cajón with box drum and flamenco percussion', |
|
|
'timpani with kettle drum and orchestral thunder' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'office_supplies': { |
|
|
'stationery': [ |
|
|
'pen with smooth writing and everyday writing tool', |
|
|
'notebook with lined pages and note-taking essential', |
|
|
'pencil with graphite lead and sketching tool', |
|
|
'markers with vibrant colors and highlighting capability', |
|
|
'sticky notes with adhesive backing and reminder function', |
|
|
'paper clips with metal construction and document organization', |
|
|
'stapler with binding function and paper fastening', |
|
|
'tape dispenser with adhesive roll and office essential', |
|
|
'ruler with measurement markings and straight edge', |
|
|
'scissors with sharp blades and cutting tool' |
|
|
], |
|
|
'desk_items': [ |
|
|
'desk lamp with adjustable arm and task lighting', |
|
|
'organizer with compartments and clutter management', |
|
|
'mouse pad with smooth surface and wrist support', |
|
|
'desk calendar with date tracking and planning tool', |
|
|
'pen holder with upright storage and writing implement organization', |
|
|
'file folders with document sorting and category organization', |
|
|
'desk mat with large surface and workspace protection', |
|
|
'paper tray with stacking design and document storage', |
|
|
'business card holder with professional presentation', |
|
|
'cable organizer with cord management and tidy workspace' |
|
|
] |
|
|
}, |
|
|
|
|
|
|
|
|
'toys_games': { |
|
|
'toys': [ |
|
|
'stuffed animal with soft plush and cuddly companion', |
|
|
'action figure with articulated joints and character play', |
|
|
'doll with detailed features and imaginative play', |
|
|
'building blocks with interlocking pieces and creative construction', |
|
|
'toy car with rolling wheels and miniature vehicle play', |
|
|
'puzzle with interlocking pieces and problem-solving challenge', |
|
|
'board game with playing pieces and family entertainment', |
|
|
'card game with illustrated cards and strategy play', |
|
|
'remote control toy with wireless operation and interactive play', |
|
|
'educational toy with learning elements and developmental benefits' |
|
|
], |
|
|
'collectibles': [ |
|
|
'figurine with detailed sculpting and display collectible', |
|
|
'vinyl toy with designer art and limited edition appeal', |
|
|
'model kit with assembly parts and hobbyist construction', |
|
|
'trading cards with collectible series and rarity value', |
|
|
'die-cast model with metal construction and scale replica', |
|
|
'statue with artistic detail and collector showcase', |
|
|
'pop culture figure with character likeness and fandom appeal', |
|
|
'vintage toy with nostalgic value and retro charm', |
|
|
'limited edition collectible with numbered series and exclusivity', |
|
|
'display case with protective housing and collection showcase' |
|
|
] |
|
|
} |
|
|
} |
|
|
|
|
|
print(f"✓ Universal Object Prompts initialized with {len(self.object_vocabularies)} major categories") |
|
|
|
|
|
def get_prompts(self, category: str, subcategory: str = None) -> List[str]: |
|
|
""" |
|
|
取得物品 prompts |
|
|
|
|
|
Args: |
|
|
category: 物品類別 (如 'animals', 'vehicles') |
|
|
subcategory: 子類別 (如 'dogs', 'cats') |
|
|
|
|
|
Returns: |
|
|
Prompt 列表 |
|
|
""" |
|
|
category_prompts = self.object_vocabularies.get(category, {}) |
|
|
|
|
|
if subcategory: |
|
|
return category_prompts.get(subcategory, []) |
|
|
else: |
|
|
|
|
|
all_prompts = [] |
|
|
for prompts in category_prompts.values(): |
|
|
if isinstance(prompts, list): |
|
|
all_prompts.extend(prompts) |
|
|
return all_prompts |
|
|
|
|
|
def get_all_categories(self) -> List[str]: |
|
|
"""取得所有物品類別""" |
|
|
return list(self.object_vocabularies.keys()) |
|
|
|
|
|
def get_subcategories(self, category: str) -> List[str]: |
|
|
"""取得特定類別的所有子類別""" |
|
|
category_data = self.object_vocabularies.get(category, {}) |
|
|
return list(category_data.keys()) if isinstance(category_data, dict) else [] |
|
|
|
|
|
def detect_object_category(self, detected_objects: List[str]) -> str: |
|
|
""" |
|
|
根據檢測到的物體推測主要類別 |
|
|
|
|
|
Args: |
|
|
detected_objects: YOLO 檢測到的物體列表 |
|
|
|
|
|
Returns: |
|
|
推測的類別名稱 |
|
|
""" |
|
|
object_str = ' '.join(detected_objects).lower() |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['dog', 'cat', 'bird', 'animal', 'pet']): |
|
|
return 'animals' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['car', 'bike', 'motorcycle', 'bus', 'train', 'vehicle']): |
|
|
return 'vehicles' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['phone', 'laptop', 'camera', 'computer', 'tablet']): |
|
|
return 'electronics' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['chair', 'table', 'bed', 'couch', 'furniture']): |
|
|
return 'home_items' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['shoe', 'bag', 'handbag', 'backpack', 'watch']): |
|
|
return 'fashion_accessories' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['ball', 'racket', 'equipment', 'fitness']): |
|
|
return 'sports_equipment' |
|
|
|
|
|
|
|
|
if any(kw in object_str for kw in ['guitar', 'piano', 'drum', 'instrument']): |
|
|
return 'musical_instruments' |
|
|
|
|
|
return None |
|
|
|
|
|
print("✓ UniversalObjectPrompts defined") |
|
|
|