import json import os from typing import List, Optional, Dict from .merge import run_multimodal_analysis from .img.resources import resources print("⏳ Loading Models...") try: resources.load_all() print("✅ Models Ready.") except Exception as e: print(f"⚠️ Warning loading models: {e}") async def run_multimodal_to_json( image_paths: Optional[List[str]] = None, text: Optional[str] = None, output_json_path: Optional[str] = "result.json" ) -> List[Dict]: """ Process image + text and write the results to a JSON file. Args: image_paths: List of image paths. text: Input text. output_json_path: Path to save the JSON file. Returns: Path of the JSON file. """ safe_text = text or "" image_paths = image_paths or [] # Run analysis result_dict = await run_multimodal_analysis( image_paths, safe_text ) # Write JSON or return dict if output_json_path: with open(output_json_path, "w", encoding="utf-8") as f: json.dump(result_dict, f, ensure_ascii=False, indent=2) return output_json_path else: return result_dict