File size: 1,010 Bytes
3a764de
2fe4a06
98e083b
2fe4a06
f9d9d3e
 
886766a
f9d9d3e
edf2be5
 
2fe4a06
 
 
c10c0c5
2fe4a06
 
 
c10c0c5
2fe4a06
0599af6
2fe4a06
f750f0e
2fe4a06
7204266
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr, pytesseract, cv2, os

def process(image: str, lang: str = 'eng') -> str:
    try:
        img = cv2.imread(image) 
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
        threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)[1]
        result = pytesseract.image_to_string(threshold_img, lang=lang)
        os.remove(image)
        return result
    except Exception as e:
        return str(e)

langs = pytesseract.get_languages()

interface = gr.Interface(
    process,
    [gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=langs, type="value")],
    outputs="text",
    css="footer {visibility: hidden}",
    title="Optical Character Recognition | Image To Text",
    article = """<p style='text-align: center;'>Hello, thanks for coming, visit AI tools: <a href="https://www.genelify.com" target="_blank">Genelify</a>, visit Social Media tools: <a href="https://www.tubtic.com" target="_blank">Tubtic</a></p>"""
)
interface.launch(show_api=False)