import json from typing import Optional, Dict, Any, List, Tuple def create_instruction_description(instruction: Dict[str, Any]) -> str: movement = instruction.get('cameraMovement', 'N/A') shot_type = instruction.get('initialShotType', 'N/A') frames = instruction.get('frameCount', 'N/A') subject_idx = instruction.get('subjectIndex', 'N/A') return f"{movement} {shot_type} of subject {subject_idx} ({frames} frames)" def load_simulation_data(file) -> Tuple[Optional[List[Dict[str, Any]]], Optional[List[str]]]: if file is None: return None, None try: json_data = json.load(open(file.name)) simulations = json_data['simulations'] descriptions = [] for i, sim in enumerate(simulations): header = f"Simulation {i + 1}" instruction_texts = [] for j, instruction in enumerate(sim['instructions']): inst_desc = create_instruction_description(instruction) instruction_texts.append(f" {j + 1}. {inst_desc}") full_description = f"{header}\n" + "\n".join(instruction_texts) subject_count = len(sim['subjects']) full_description = f"{full_description}\n ({subject_count} subjects)" descriptions.append(full_description) return simulations, descriptions except Exception as e: print(f"Error loading simulation data: {str(e)}") return None, None