# -*- coding: utf-8 -*-
import time
import os

import ocr_client
text = '识别图片的内容，如果是发票就执行以下操作识别图中的文字信息，并以json格式返回，如果不是发票返回False'
image_dir = '/home/practice/dcu_Mineru/images'
false_count = 0
file_count = 0
true_count = 0
for root, dirs, files in os.walk(image_dir):
    for file in files:
        # 构建完整的文件路径
        file_path = os.path.join(root, file)
        # 打印文件名
        image_path = file_path
        start = time.time()
        ocr_client.compress_image(image_path)
        generated_text = ocr_client.PredictClient('http://127.0.0.1:6020').predict(image_path, text)

        if generated_text == 'False' or generated_text == 'false':
            false_count += 1
        else:
            print(f'{image_path}提取到的内容是：\n{generated_text}')
            true_count += 1
        file_count +=1

print(f'总共{file_count}个文件，其中qwen返回{false_count}个False，返回{true_count}个json')



