Spaces:
Sleeping
Sleeping
Dan Mo
Refactor application structure: implement EmojiProcessor, enhance Gradio interface, and add configuration management
cf957e4
""" | |
Utility functions for the Emoji Mashup application. | |
""" | |
import logging | |
# Configure logging | |
def setup_logging(): | |
"""Configure application logging.""" | |
logging.basicConfig( | |
level=logging.INFO, | |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
) | |
return logging.getLogger(__name__) | |
# Initialize logger | |
logger = setup_logging() | |
def kitchen_txt_to_dict(filepath): | |
"""Convert emoji kitchen text file to dictionary. | |
Args: | |
filepath: Path to the emoji kitchen text file | |
Returns: | |
Dictionary mapping emojis to descriptions | |
""" | |
emoji_dict = {} | |
try: | |
with open(filepath, 'r', encoding='utf-8') as f: | |
for line in f: | |
parts = line.strip().split(' ', 1) | |
if len(parts) == 2: | |
emoji, desc = parts | |
emoji_dict[emoji] = desc | |
return emoji_dict | |
except Exception as e: | |
logger.error(f"Error loading emoji dictionary from {filepath}: {e}") | |
return {} |