File size: 1,435 Bytes
c50bb95
 
f5a94e3
c50bb95
 
f5a94e3
 
c50bb95
f5a94e3
 
c50bb95
f5a94e3
 
 
 
 
 
 
 
c50bb95
f5a94e3
 
 
 
 
 
 
 
c50bb95
f5a94e3
 
001f24f
f5a94e3
 
 
 
 
 
 
 
 
 
c50bb95
f5a94e3
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
36
37
38
39
40
41
42
43
44
45
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 = """<p style='text-align: center;'>Feel free to give us your thoughts on this demo and please contact us at
                    <a href="mailto:[email protected]" target="_blank">[email protected]</a>
                    <p style='text-align: center;'>Developed by: <a href="https://www.pragnakalp.com" target="_blank">Pragnakalp Techlabs</a></p>"""
)

demo.launch()