SmokeyBandit commited on
Commit
5695a1d
·
verified ·
1 Parent(s): 27718ea

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr, pytesseract, cv2, os
2
+
3
+ def process(image: str, lang: str = 'eng') -> str:
4
+ try:
5
+ img = cv2.imread(image)
6
+ gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
7
+ _,threshold_img = cv2.threshold(gray, 127, 255, cv2.THRESH_TOZERO)
8
+ result = pytesseract.image_to_string(threshold_img, lang=lang)
9
+ os.remove(image)
10
+ return result
11
+ except Exception as e:
12
+ return str(e)
13
+
14
+ langs = pytesseract.get_languages()
15
+
16
+ interface = gr.Interface(
17
+ process,
18
+ [gr.Image(type="filepath"), gr.Dropdown(label="Select Language", choices=langs, type="value")],
19
+ outputs="text",
20
+ css="footer {visibility: hidden}",
21
+ title="Optical Character Recognition | Image To Text",
22
+ 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>"""
23
+ )
24
+ interface.launch(show_api=False)