Datasets:
Tasks:
Text Classification
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
1K - 10K
Tags:
art
License:
| import json | |
| import os | |
| def load_metadata(): | |
| """Load metadata from metadata.jsonl""" | |
| metadata_path = "metadata.jsonl" | |
| metadata = {} | |
| # Parse JSONL file and map descriptions by sprite ID | |
| with open(metadata_path, 'r') as f: | |
| for line in f: | |
| if line.strip(): | |
| entry = json.loads(line) | |
| # Extract sprite ID from file_name (e.g., "23.png" -> "23") | |
| sprite_id = entry["file_name"].split(".")[0] | |
| metadata[sprite_id] = entry["text"] | |
| return metadata | |
| def extract_info_safely(description): | |
| """Extract information from description with error handling""" | |
| info = { | |
| "frames": "unknown", | |
| "action": "unknown", | |
| "direction": "unknown", | |
| "character": "unknown" | |
| } | |
| try: | |
| # Extract frame count | |
| if "-frame" in description: | |
| info["frames"] = description.split("-frame")[0] | |
| # Extract action | |
| if "that: " in description and "," in description: | |
| info["action"] = description.split("that: ")[1].split(",")[0] | |
| # Extract direction | |
| if "facing: " in description: | |
| info["direction"] = description.split("facing: ")[1] | |
| # Extract character | |
| if "of: " in description and ", that:" in description: | |
| info["character"] = description.split("of: ")[1].split(", that:")[0] | |
| except Exception as e: | |
| print(f"Warning: Error parsing description: {description}") | |
| print(f"Error details: {str(e)}") | |
| return info | |
| def create_sprite_dataset(): | |
| """Create sprite dataset with metadata""" | |
| # Load metadata | |
| metadata = load_metadata() | |
| # Create output directory structure | |
| base_dir = "sprite_dataset" | |
| if not os.path.exists(base_dir): | |
| os.makedirs(base_dir) | |
| # Create metadata mapping | |
| sprite_info = {} | |
| # Process each folder in the train directory | |
| train_dir = "train" | |
| for folder_name in os.listdir(train_dir): | |
| if folder_name.endswith("_frames"): | |
| # Extract sprite ID from folder name (e.g., "23_frames" -> "23") | |
| sprite_id = folder_name.split("_")[0] | |
| # Get description from metadata | |
| description = metadata.get(sprite_id, "No description available") | |
| # Extract information safely | |
| info = extract_info_safely(description) | |
| # Create organized structure with folder name | |
| sprite_info[sprite_id] = { | |
| "frames": info["frames"], | |
| "action": info["action"], | |
| "direction": info["direction"], | |
| "character": info["character"], | |
| "folder_name": folder_name, | |
| "full_description": description | |
| } | |
| # Save metadata to JSON file | |
| metadata_path = os.path.join(base_dir, "sprite_metadata.json") | |
| with open(metadata_path, "w") as f: | |
| json.dump(sprite_info, f, indent=4) | |
| print(f"Created sprite dataset with metadata for {len(sprite_info)} sprites") | |
| return sprite_info | |
| if __name__ == "__main__": | |
| sprite_info = create_sprite_dataset() |