Spaces:
Build error
Build error
| class CharacterTracker: | |
| def __init__(self): | |
| self.characters = {} | |
| def add_character(self, name, attributes): | |
| """ | |
| Add a character with their attributes to track consistency. | |
| Args: | |
| name (str): Character name | |
| attributes (dict): Character attributes including physical appearance, | |
| personality traits, and other distinguishing features | |
| """ | |
| self.characters[name] = attributes | |
| def get_character_prompt(self, name): | |
| """ | |
| Generate a consistent character description for image generation. | |
| Args: | |
| name (str): Character name | |
| Returns: | |
| str: Detailed character description for consistent image generation | |
| """ | |
| if name not in self.characters: | |
| return "" | |
| attrs = self.characters[name] | |
| prompt_parts = [] | |
| # Add physical appearance details | |
| if 'appearance' in attrs: | |
| prompt_parts.append(f"Physical appearance: {attrs['appearance']}") | |
| # Add personality traits that might affect expression | |
| if 'personality' in attrs: | |
| prompt_parts.append(f"Personality (affecting expression): {attrs['personality']}") | |
| # Add distinguishing features | |
| if 'distinguishing_features' in attrs: | |
| prompt_parts.append(f"Distinguishing features: {attrs['distinguishing_features']}") | |
| return ", ".join(prompt_parts) | |
| def validate_consistency(self, story_text): | |
| """ | |
| Validate character consistency in story text. | |
| Args: | |
| story_text (str): The story text to validate | |
| Returns: | |
| bool: True if consistent, False otherwise | |
| str: Inconsistency message if any | |
| """ | |
| # Basic consistency checks | |
| for name, attrs in self.characters.items(): | |
| if name in story_text: | |
| # Check for basic attribute consistency | |
| for key, value in attrs.items(): | |
| if isinstance(value, str) and value in story_text: | |
| continue | |
| elif isinstance(value, list): | |
| if not any(v in story_text for v in value): | |
| return False, f"Inconsistency found for {name}'s {key}" | |
| return True, "Character consistency maintained" |