From b4cb64d861e31e7159be4495c89214467c2e23bb Mon Sep 17 00:00:00 2001 From: Timothyxxx <384084775@qq.com> Date: Mon, 11 Mar 2024 00:26:59 +0800 Subject: [PATCH] Fix bugs in multiple examples --- desktop_env/evaluators/metrics/chrome.py | 16 +++------------- desktop_env/evaluators/metrics/general.py | 9 +++++++++ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/desktop_env/evaluators/metrics/chrome.py b/desktop_env/evaluators/metrics/chrome.py index 3054bee..cc12e29 100644 --- a/desktop_env/evaluators/metrics/chrome.py +++ b/desktop_env/evaluators/metrics/chrome.py @@ -178,6 +178,9 @@ import typing def compare_pdf_images(pdf1_path: str, pdf2_path: str, **kwargs) -> float: + if not pdf1_path or not pdf2_path: + return 0. + def extract_images_from_pdf(pdf_path): pdf_document = fitz.open(pdf_path) images = [] @@ -396,16 +399,3 @@ def is_added_to_steam_cart(active_tab_info, rule): return 0. return 1. - - -if __name__ == '__main__': - result = compare_archive( - r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\0e5303d4-8820-42f6-b18d-daf7e633de21\lecture_slides.zip", - r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\0e5303d4-8820-42f6-b18d-daf7e633de21\gold_lecture_slides.zip", - - **{ - "file_path": "lecture_slides", - "file_type": "pdf" - }) - - print(result) diff --git a/desktop_env/evaluators/metrics/general.py b/desktop_env/evaluators/metrics/general.py index f17bb54..bc795f7 100644 --- a/desktop_env/evaluators/metrics/general.py +++ b/desktop_env/evaluators/metrics/general.py @@ -387,6 +387,9 @@ def is_included_all_json_objects(gold_file_path, result_file_path): def is_gold_text_included_in_pdf(pdf_file_path, gold_text_path): + if not gold_text_path or not pdf_file_path: + return 0 + print("gold_text_path: ") print(gold_text_path) print("pdf_file_path: ") @@ -447,6 +450,9 @@ def check_line_number(file_path, line_number): def compare_terminal_and_txt(txt_file_path, terminal_output): + if not txt_file_path or not terminal_output: + return 0 + # read txt file content with open(txt_file_path, 'r') as f: txt_file_content = f.read() @@ -455,6 +461,9 @@ def compare_terminal_and_txt(txt_file_path, terminal_output): def compare_python_pure_text(py_file_path, gold_file_path): + if not py_file_path or not gold_file_path: + return 0 + # first, change the suffix of gold_file from .txt to .py print("py_file_path: ") print(py_file_path)