<commit_before>import os

import cv
import cv2
import tesseract
from twisted.python import log

from pllm import config, util
from pllm.vision import algo
from pllm.vision.util import draw_segments


def ocr(fpath, block=True):
    """
    Recognize text in image specified by `fpath`.
    Should contain single block of text (pre-segmented)
    """

    api = tesseract.TessBaseAPI()
    api.Init(".", "eng", tesseract.OEM_DEFAULT)
    if block:
        api.SetPageSegMode(tesseract.PSM_SINGLE_BLOCK)
    else:
        api.SetPageSegMode(tesseract.PSM_AUTO)

    img = cv.LoadImage(fpath, iscolor=False)
    tesseract.SetCvImage(img, api)
    text = api.GetUTF8Text()
    return text


def ocr_optimize(fpath, upscale=5, threshold=160):
    """
    Optimize `fpath` image for ocr
    """
<commit_msg>delete unused log<commit_after>import os

import cv
import cv2
import tesseract

from pllm import config, util
from pllm.vision import algo
from pllm.vision.util import draw_segments


def ocr(fpath, block=True):
    """
    Recognize text in image specified by `fpath`.
    Should contain single block of text (pre-segmented)
    """

    api = tesseract.TessBaseAPI()
    api.Init(".", "eng", tesseract.OEM_DEFAULT)
    if block:
        api.SetPageSegMode(tesseract.PSM_SINGLE_BLOCK)
    else:
        api.SetPageSegMode(tesseract.PSM_AUTO)

    img = cv.LoadImage(fpath, iscolor=False)
    tesseract.SetCvImage(img, api)
    text = api.GetUTF8Text()
    return text


def ocr_optimize(fpath, upscale=5, threshold=160):
    """
    Optimize `fpath` image for ocr
    """

{'fraction_non_alphanumeric': 0.09968253968253968, 'fraction_numerical': 0.007619047619047619, 'mean_word_length': 3.4519774011299433, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4974146', 'n_tokens_mistral': 554, 'n_tokens_neox': 555, 'n_words': 138}