import gradio as gr import cv2 import easyocr from PIL import Image def get_grayscale(image): return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) def thresholding(src): return cv2.threshold(src,127,255, cv2.THRESH_TOZERO)[1] def ocr_with_easy(img): gray_scale_image = get_grayscale(img) thresholding(gray_scale_image) cv2.imwrite('image.png', gray_scale_image) reader = easyocr.Reader(['en']) bounds = reader.readtext('image.png', paragraph="False", detail=0) bounds = ''.join(bounds) return bounds def generate_ocr(img): text_output = '' if (img).any(): if img is not None: text_output = ocr_with_easy(img) else: raise gr.Error("Please upload an image!!!!") return text_output image = gr.Image() output = gr.Textbox(label="Output") demo = gr.Interface( generate_ocr, image, output, title="Optical Character Recognition", css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}", article = """

Feel free to give us your thoughts on this demo and please contact us at letstalk@pragnakalp.com

Developed by: Pragnakalp Techlabs

""" ) demo.launch()