Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Remove usage of eval() from postprocess.py (#4571)

Mathias Panzenböck1a367664f143
diff --git a/deepdoc/vision/postprocess.py b/deepdoc/vision/postprocess.py
index 2da1477b3e..27916cf45a 100644
--- a/deepdoc/vision/postprocess.py
+++ b/deepdoc/vision/postprocess.py
@@ -23,7 +23,7 @@ import pyclipper
def build_post_process(config, global_config=None):
- support_dict = ['DBPostProcess', 'CTCLabelDecode']
+ support_dict = {'DBPostProcess': DBPostProcess, 'CTCLabelDecode': CTCLabelDecode}
config = copy.deepcopy(config)
module_name = config.pop('name')
@@ -31,10 +31,11 @@ def build_post_process(config, global_config=None):
return
if global_config is not None:
config.update(global_config)
- assert module_name in support_dict, Exception(
- 'post process only support {}'.format(support_dict))
- module_class = eval(module_name)(**config)
- return module_class
+ module_class = support_dict.get(module_name)
+ if module_class is None:
+ raise ValueError(
+ 'post process only support {}'.format(list(support_dict)))
+ return module_class(**config)
class DBPostProcess(object):