Spaces:
Sleeping
Sleeping
| import yaml | |
| import json | |
| import os | |
| from box import Box | |
| import re | |
| MAX_INPUT_TOKEN_NUM = 128000 | |
| def load_config(config_path): | |
| config = Box.from_yaml( | |
| filename=config_path, Loader=yaml.FullLoader) | |
| return config | |
| def save_as_json(path, data): | |
| ''' | |
| outout a json file with indent equals to 2 | |
| ''' | |
| json_data = json.dumps(data, indent=2) | |
| # Save JSON to a file | |
| try: | |
| # Create the directory structure if it doesn't exist | |
| os.makedirs(os.path.dirname(path), exist_ok=True) | |
| # Write data to the JSON file | |
| with open(path, 'w') as json_file: | |
| json_file.write(json_data) | |
| print(f"Experiment results written to '{path}' successfully.") | |
| class ContextAttributeError(BaseException): | |
| def __init__(self, message): | |
| self.message = message | |
| super().__init__(self.message) | |
| return True | |
| except Exception as e: | |
| print(f"Failed to write experiment results to '{path}': {e}") | |
| return False | |
| pass | |