Spaces:
Sleeping
Sleeping
File size: 840 Bytes
8ab0729 eae6dcf 8ab0729 eae6dcf 8ab0729 eae6dcf 8ab0729 e533ffc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# ocr_utils.py
import easyocr
import numpy as np
# Initialize the EasyOCR reader for Hindi and English
reader = easyocr.Reader(['hi', 'en'])
def extract_text(image_np):
"""
Extract text from a NumPy array image using EasyOCR.
Parameters:
- image_np: NumPy array representation of the image.
Returns:
- full_text: Extracted text as a single string.
"""
extracted_text = reader.readtext(image_np, detail=0)
full_text = " ".join(extracted_text)
return full_text
def highlight_content(full_text, keyword):
if keyword:
# Highlight the keyword in the text
highlighted_text = full_text.replace(
keyword, f"<span class='highlight'>{keyword}</span>"
)
return highlighted_text
else:
return "No keyword entered for highlighting." |