From a30fe62bc3e59414b163a452df7a132676f2200b Mon Sep 17 00:00:00 2001 From: arkohut <39525455+arkohut@users.noreply.github.com> Date: Mon, 9 Sep 2024 23:39:04 +0800 Subject: [PATCH] fix: yaml parse related --- memos/config.py | 4 +--- memos/plugins/ocr/main.py | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/memos/config.py b/memos/config.py index ec9170b..b840254 100644 --- a/memos/config.py +++ b/memos/config.py @@ -102,15 +102,13 @@ yaml.add_representer(OrderedDict, dict_representer) def secret_str_representer(dumper, data): return dumper.represent_scalar("tag:yaml.org,2002:str", data.get_secret_value()) - # Custom constructor for SecretStr def secret_str_constructor(loader, node): value = loader.construct_scalar(node) return SecretStr(value) - +# Register the representer and constructor only for specific fields yaml.add_representer(SecretStr, secret_str_representer) -yaml.add_constructor("tag:yaml.org,2002:str", secret_str_constructor) def create_default_config(): diff --git a/memos/plugins/ocr/main.py b/memos/plugins/ocr/main.py index a0b207d..b40be50 100644 --- a/memos/plugins/ocr/main.py +++ b/memos/plugins/ocr/main.py @@ -183,10 +183,10 @@ def init_plugin(config): ocr_config['Cls']['model_path'] = os.path.join(model_dir, os.path.basename(ocr_config['Cls']['model_path'])) ocr_config['Rec']['model_path'] = os.path.join(model_dir, os.path.basename(ocr_config['Rec']['model_path'])) - # Save the updated config to a temporary file + # Save the updated config to a temporary file with strings wrapped in double quotes temp_config_path = os.path.join(os.path.dirname(__file__), "temp_ppocr.yaml") with open(temp_config_path, 'w') as f: - yaml.safe_dump(ocr_config, f) + yaml.safe_dump(ocr_config, f, default_style='"') ocr = RapidOCR(config_path=temp_config_path) thread_pool = ThreadPoolExecutor(max_workers=concurrency)