| """ | |
| UI State management for DocAI Space | |
| Per-session state via factory function + shared caches | |
| """ | |
| import hashlib | |
| from typing import Dict, List, Any | |
| def create_initial_state() -> dict: | |
| """Factory returning a fresh per-session state dict.""" | |
| return { | |
| "uploaded_file_hash": None, | |
| "uploaded_file_bytes": None, | |
| "parsed_result": {}, | |
| "page_images": [], | |
| "figures_info": [], | |
| "selected_figure": None, | |
| "last_csv": None, | |
| "current_figure_index": 0, | |
| "conversation_history": [], | |
| "current_image_path": None, | |
| } | |
| # Module-level shared caches (keyed by content hash, safe to share across sessions) | |
| parse_cache: Dict[str, Dict] = {} | |
| page_cache: Dict[str, List] = {} | |
| def hash_bytes(data: bytes) -> str: | |
| """Generate SHA256 hash of bytes.""" | |
| return hashlib.sha256(data).hexdigest() | |