# Check if the file is an image
if file_name.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
input_path = os.path.join(root, file_name)
- output_path = os.path.join(root, file_name.replace('.', '_ocr.'))
+ output_path = f'{input_path}.ocr.json'
text = None
if os.path.exists(output_path):
text = ocr_image(ocr, input_path)
if text:
# Write the OCR result to a JSON file
- json_output_path = output_path.rsplit('.', 1)[0] + '.json'
+ json_output_path = output_path.rsplit('.', 1)[0]
with open(json_output_path, 'w') as f:
f.write(f'{{"text": "{text}"}}')