| import os | |
| import random | |
| import json | |
| from typing import Dict, Any, Optional | |
| class SimpleJSONCache: | |
| def __init__(self, filepath: str): | |
| self.filepath = filepath | |
| self._cache = self._load() | |
| def _load(self): | |
| if os.path.exists(self.filepath): | |
| try: | |
| with open(self.filepath, 'r', encoding='utf-8') as f: | |
| return json.load(f) | |
| except Exception: | |
| return {} | |
| else: | |
| return {} | |
| def get(self, key, default=None): | |
| return self._cache.get(key, default) | |
| def set(self, key, value): | |
| self._cache[key] = value | |
| try: | |
| with open(self.filepath, 'w', encoding='utf-8') as f: | |
| json.dump(self._cache, f, indent=2) | |
| except Exception as e: | |
| print(f"Error saving cache: {e}") | |
| class PromptGenerator: | |
| CACHE_KEY = "generated_prompts" | |
| def __init__(self, cache_path: str = "prompt_cache.json") -> None: | |
| self.cache = SimpleJSONCache(cache_path) | |
| self._load_defaults() | |
| def _load_defaults(self) -> None: | |
| self.ROLES = [ | |
| "nurse", "nun", "doctor", "secretary", "teacher", "schoolgirl", "lawyer", | |
| "yoga instructor", "policewoman", "female military officer in gala uniform", | |
| "WWII-era secretary", "1960s flight attendant", "boudoir model", | |
| "elegant judge", "seductive librarian", "sensual model", "alluring secretary", | |
| "elegant flight attendant", "seductive maid", "mysterious nurse", | |
| "captivating schoolgirl", "business executive", "fitness model" | |
| ] | |
| self.HAIR_COLORS = [ | |
| "deep sapphire blue", "silver platinum", "vibrant ruby red", "glossy jet black", | |
| "luxurious chestnut brown", "emerald green", "vivid amethyst purple", | |
| "chocolate brown", "honey blonde", "burgundy red" | |
| ] | |
| self.EYE_COLORS = [ | |
| "intense brown", "bright sapphire blue", "emerald green", "golden amber", | |
| "fascinating hazel", "deep violet", "piercing emerald", "deep sapphire", | |
| "intense amber", "hypnotic hazel", "vibrant violet", "mysterious gray" | |
| ] | |
| self.HAIR_STYLES = [ | |
| "long flowing chestnut hair styled in soft waves", "sleek straight long black hair", | |
| "luxurious long blonde curls", "elegant updo with loose cascading strands", | |
| "glossy long brunette hair parted in the middle", "long flowing waves", | |
| "luxurious straight hair", "voluminous curls", "elegant updo with cascading strands", | |
| "thick braid over the shoulder", "loose and silky layers", "messy chic bun" | |
| ] | |
| self.OUTFIT_TEMPLATES = { | |
| "nurse": "a classic short nurse dress, thigh-high stockings, semi-transparent lace panties subtly slipping down as if accidentally revealed beneath a skirt, no bra, elegant high heels", | |
| "nun": "a sensual interpretation of a nun's habit with a revealing long robe and thigh-high stockings, semi-transparent lace panties suggesting a playful accidental reveal, no bra, black stiletto heels", | |
| "doctor": "a daring white lab coat minidress left slightly open, thigh-high stockings, semi-transparent lace panties exposed subtly as if by chance, no bra, high heels", | |
| "secretary": "a provocative office pencil skirt and sheer blouse, thigh-high stockings, semi-transparent lace panties hinted at from a natural skirt shift, no bra, red high heels", | |
| "teacher": "a fitted blazer over a silk blouse and short skirt, thigh-high stockings, delicate lace panties subtly visible during natural movement, no bra, classic pumps", | |
| "schoolgirl": "a short pleated skirt and white blouse, thigh-high stockings, classic black lace panties slipping into view during casual poses, no bra, black loafers", | |
| "lawyer": "a tailored suit with skirt cut above knees, silk blouse unbuttoned slightly, thigh-high stockings, lace panties revealed subtly when seated, no bra, leather pumps", | |
| "yoga instructor": "form-fitting athletic wear that hugs curves, moisture-wicking fabric, lace panty lines subtly visible through tight clothing, sports bra barely containing", | |
| "policewoman": "a fitted police uniform with short skirt, thigh-high stockings, lace panties subtly showing during action poses, no bra, polished combat boots", | |
| "female military officer in gala uniform": "a ceremonial uniform with decorative elements, thigh-high stockings, lace panties hinted beneath tailored skirt, no bra, dress shoes", | |
| "WWII-era secretary": "vintage styled dress with seamed stockings, lace panties from era subtly revealed when bending, no bra, period-appropriate heels", | |
| "1960s flight attendant": "retro uniform with pillbox hat, thigh-high stockings, vintage lace panties subtly visible during graceful movements, no bra, classic heels", | |
| "boudoir model": "silk robe falling open, thigh-high stockings, intricate lace panties prominently displayed, no bra, feathered mules", | |
| "elegant judge": "judicial robes over a sophisticated dress, thigh-high stockings, luxury lace panties subtly revealed when robes part, no bra, court heels", | |
| "seductive librarian": "tight sweater and pencil skirt, thigh-high stockings, lace panties subtly visible when reaching for books, no bra, reading glasses", | |
| "sensual model": "designer evening gown with thigh slit, thigh-high stockings, luxury lace panties showcased during photo shoot poses, no bra, runway heels", | |
| "alluring secretary": "bodycon dress and blazer, thigh-high stockings, lace panties clearly outlined beneath fabric, no bra, stiletto pumps", | |
| "elegant flight attendant": "modern uniform with scarf, thigh-high stockings, lace panties subtly visible during boarding gestures, no bra, airline heels", | |
| "seductive maid": "traditional french maid costume shortened, thigh-high stockings, lace panties prominently displayed during cleaning poses, no bra,mary janes", | |
| "mysterious nurse": "night shift uniform with cape, thigh-high stockings, lace panties revealed during urgent movements, no bra, silent shoes", | |
| "captivating schoolgirl": "a short skirt and blouse with thigh-high stockings, classic black lace panties slipping into view, no bra, black patent heels", | |
| "business executive": "power suit with mini skirt, thigh-high stockings, luxury lace panties visible during confident walking, no bra, executive heels", | |
| "fitness model": "performance activewear, thigh-high athletic socks, sporty lace panties outlined during exercise poses, no bra, training shoes" | |
| } | |
| self.POSES = [ | |
| "standing gracefully with one leg slightly forward, skirt adjusting as if caught in motion revealing lace panties", | |
| "seated on the edge, legs crossed, skirt shifting and lace panties subtly visible", | |
| "bending forward slightly as if picking something up, skirt rising to show lace panties", | |
| "leaning against a wall, one hip cocked, skirt riding up to reveal lace panties", | |
| "walking with a natural sway, skirt moving with motion to show glimpses of lace panties", | |
| "reaching upwards for an object, skirt lifting to display lace panties", | |
| "sitting on stairs, legs slightly apart, skirt providing a view of lace panties", | |
| "lying on a sofa, dress falling open to reveal lace panties naturally", | |
| "dancing gently, skirt flowing to show lace panties during spins", | |
| "adjusting stockings, skirt lifted to expose lace panties momentarily" | |
| ] | |
| self.SETTINGS = [ | |
| "a modern professional office with golden sunset light and sophisticated decor", | |
| "a stylish hospital room with clean bright tones and realistic medical equipment", | |
| "a luxurious bedroom with silk sheets and soft lighting", | |
| "an elegant living room with vintage furniture and warm ambiance", | |
| "a photography studio with professional lighting and minimalist backdrop", | |
| "a high-end hotel suite with city views and contemporary design", | |
| "a classic library with wooden shelves and warm reading lights", | |
| "a rooftop terrace with urban landscape and twilight sky", | |
| "a dressing room with large mirrors and velvet furnishings", | |
| "a boutique hotel lobby with art deco elements and soft lighting" | |
| ] | |
| self.ATMOSPHERES = [ | |
| "soft professional lighting with perfect color, crisp highlights and smooth skin shadows", | |
| "warm ambient sunlight, rich gold reflections and depth", | |
| "moody cinematic lighting with dramatic shadows and highlights", | |
| "romantic candlelight with soft glows and intimate shadows", | |
| "studio flash lighting with clean, sharp details and minimal shadows", | |
| "golden hour natural light with warm, flattering tones", | |
| "moonlit ambiance with cool tones and mysterious atmosphere", | |
| "neon accent lighting with vibrant colors and urban vibe" | |
| ] | |
| self.TECHNICAL_DETAILS = ( | |
| "shot in full vertical 9:16 aspect ratio capturing the entire figure with natural human proportions and anatomical precision, " | |
| "featuring hyperrealistic skin texture with subtle imperfections, perfect makeup, and real fabric and hair strand details. " | |
| "Captured with professional camera gear (Canon R5, 85mm lens, f/1.2) emphasizing soft, natural lighting and highlights for humanized photorealism. " | |
| "Exclude any cartoon, 2D, painting, stylized, CGI, illustration, low resolution, or watermark artifacts." | |
| ) | |
| def _random_choice(self, collection: list) -> str: | |
| return random.choice(collection) | |
| def generate_prompt( | |
| self, | |
| seed_config: Optional[Dict[str, Any]] = None, | |
| context: Optional[Dict[str, Any]] = None | |
| ) -> str: | |
| seed = seed_config or {} | |
| role = seed.get("role", self._random_choice(self.ROLES)) | |
| hair_color = seed.get("hair_color", self._random_choice(self.HAIR_COLORS)) | |
| eye_color = seed.get("eye_color", self._random_choice(self.EYE_COLORS)) | |
| hair_style = seed.get("hair_style", self._random_choice(self.HAIR_STYLES)) | |
| outfit = self.OUTFIT_TEMPLATES.get(role, self.OUTFIT_TEMPLATES["secretary"]) | |
| pose = seed.get("pose", self._random_choice(self.POSES)) | |
| setting = seed.get("setting", self._random_choice(self.SETTINGS)) | |
| atmosphere = seed.get("atmosphere", self._random_choice(self.ATMOSPHERES)) | |
| context_note = f" Context: {context['summary']}." if context and "summary" in context else "" | |
| prompt = ( | |
| f"A hyperrealistic full-body portrait of a sensual {role} with {hair_style} in {hair_color}, {eye_color} eyes, " | |
| f"perfect makeup and flawless skin with subtle natural imperfections. Wearing {outfit}. " | |
| f"Pose: {pose}. Scene: {setting} with {atmosphere}.{context_note} " | |
| f"{self.TECHNICAL_DETAILS}" | |
| ) | |
| cache_list = self.cache.get(self.CACHE_KEY, []) | |
| if prompt in cache_list: | |
| prompt = prompt + f" [uid:{random.randint(1000,9999)}]" | |
| cache_list.append(prompt) | |
| self.cache.set(self.CACHE_KEY, cache_list) | |
| return f"``````" | |
| def generate_five_prompts( | |
| self, | |
| seed_config: Optional[Dict[str, Any]] = None, | |
| context: Optional[Dict[str, Any]] = None | |
| ) -> list[str]: | |
| prompts = [] | |
| for _ in range(5): | |
| prompt = self.generate_prompt(seed_config=seed_config, context=context) | |
| prompts.append(prompt) | |
| return prompts | |
| def update_configuration(self, new_config: Dict[str, Any]) -> None: | |
| for key, value in new_config.items(): | |
| if hasattr(self, key): | |
| existing = getattr(self, key) | |
| if isinstance(existing, list) and isinstance(value, list): | |
| existing.extend(x for x in value if x not in existing) | |
| elif isinstance(existing, dict) and isinstance(value, dict): | |
| existing.update(value) | |
| if __name__ == "__main__": | |
| generator = PromptGenerator() | |
| print("Generating 5 hyperrealistic humanized full-body prompts for individual characters:\n") | |
| prompts = generator.generate_five_prompts() | |
| for prompt in prompts: | |
| print(prompt + "\n") | |