File size: 733 Bytes
d053f30
 
 
 
 
4a1f0e8
 
d053f30
4a1f0e8
 
d053f30
 
4a1f0e8
d053f30
 
 
 
4a1f0e8
d053f30
4a1f0e8
d053f30
 
4a1f0e8
d053f30
 
 
 
 
4a1f0e8
d053f30
 
 
4a1f0e8
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
import cv2
import easyocr
import gradio as gr
import base64

# Instance text detector
reader = easyocr.Reader(['en'], gpu=False)

def text_extraction(image):
    text_ = reader.readtext(image)

    threshold = 0.25
    # draw bbox and text
    for t_, t in enumerate(text_):
        bbox, text, score = t

        if score > threshold:
            cv2.rectangle(image, tuple(map(int, bbox[0])), tuple(map(int, bbox[2])), (255, 0, 0), 2)

    retval, buffer = cv2.imencode('.jpg', image)
    img_base64 = base64.b64encode(buffer).decode('utf-8')

    return img_base64

# Define Gradio interface
iface = gr.Interface(
    fn=text_extraction,
    inputs=gr.Image(),
    outputs=["image"]
)

# Launch the Gradio interface
iface.launch()