diff --git a/chyoso_toolkit_ui.py b/chyoso_toolkit_ui.py index 30c9141..76e40c1 100644 --- a/chyoso_toolkit_ui.py +++ b/chyoso_toolkit_ui.py @@ -177,15 +177,17 @@ def run_ocr(image): "sudo", "-u", "tmfc", "/home/tmfc/miniconda3/envs/got/bin/python3", "/home/tmfc/apps/got-ocr/GOT/demo/run_ocr_2.0_crop.py", "--model-name", "/home/tmfc/apps/got-ocr/models/", - "--image-file", image_path, - "> /home/tmfc/apps/got-ocr/img.txt" + "--image-file", image_path ] + out_file = "/home/tmfc/apps/got-ocr/img.txt" try: - subprocess.run(command, check=True) + with open(out_file, 'w') as f: + result = subprocess.run(command, stdout=f, stderr=subprocess.PIPE, text=True) + except subprocess.CalledProcessError as e: return f"识别失败: {e}" - with open("/home/tmfc/apps/got-ocr/img.txt", 'r', encoding='utf-8') as f: + with open(out_file, 'r', encoding='utf-8') as f: content = f.read() return content