Creates an AigcModel instance from a JSON configuration file. Args: json_path (str): The path to the JSON configuration file. Returns: AigcModel: An instance of the AigcModel.
(cls, json_path: str)
| 399 | |
| 400 | @classmethod |
| 401 | def from_json_file(cls, json_path: str): |
| 402 | """ |
| 403 | Creates an AigcModel instance from a JSON configuration file. |
| 404 | |
| 405 | Args: |
| 406 | json_path (str): The path to the JSON configuration file. |
| 407 | |
| 408 | Returns: |
| 409 | AigcModel: An instance of the AigcModel. |
| 410 | """ |
| 411 | import json |
| 412 | json_path = os.path.expanduser(json_path) |
| 413 | if not os.path.exists(json_path): |
| 414 | raise FileNotFoundError( |
| 415 | f'JSON config file not found at: {json_path}') |
| 416 | |
| 417 | with open(json_path, 'r', encoding='utf-8') as f: |
| 418 | config = json.load(f) |
| 419 | |
| 420 | # Ensure required fields are present |
| 421 | required_fields = [ |
| 422 | 'model_path', 'aigc_type', 'base_model_type', 'base_model_id' |
| 423 | ] |
| 424 | for field in required_fields: |
| 425 | if field not in config: |
| 426 | raise ValueError( |
| 427 | f"Missing required field in JSON config: '{field}'") |
| 428 | |
| 429 | return cls(**config) |