<jupyter_start><jupyter_text>MVP Cognitive Search Application using OCR approach<jupyter_code>from pdf2image import convert_from_path
import easyocr
import numpy as np 
import PIL
from PIL import ImageDraw
import spacy 
reader = easyocr.Reader(['en'])
images = convert_from_path('./PDF_docs/09_080661e_Golpanol_ALS.pdf')
from IPython.display import display, Image
display(images[1])
bounds = reader.readtext(np.array(images[1]), min_size=0, slope_ths=0.2, ycenter_ths=0.7, height_ths=0.6, width_ths=0.8, decoder='beamsearch', beamWidth=10)

bounds
def draw_boxes(image, bounds, color='yellow', width=2):
    draw = ImageDraw.Draw(image)
    for bound in bounds:
        p0, p1, p2, p3 = bound[0]
        draw.line([*p0, *p1, *p2, *p3, *p0], fill = color, width = width)
    return image

draw_boxes(images[1], bounds)
text = ''
for i in range(len(bounds)):
    text = text + bounds[i][1] + '\n'

print (text)
nlp = spacy.load('en_core_web_sm')
doc = nlp(text)
from spacy import displacy
displacy.render(nlp(doc.text), style='ent', jupyter=True)
f = open('txt.txt', 'w')
f.write(text)
f.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14425645592163847, 'fraction_numerical': 0.031166518254674976, 'mean_word_length': 5.497109826589595, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '486483', 'license': 'MIT', 'n_tokens_mistral': 442, 'n_tokens_neox': 425, 'n_words': 100, 'path': 'MVP_cognitive_search_OCR.ipynb', 'repo_name': 'ajaykrsna/mvp-cognitive-search-nlp', 'size': '1123'}