sussahoo commited on
Commit
a55334d
·
1 Parent(s): d0a63d5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ import cv2
4
+ import pytesseract
5
+ import numpy as np
6
+ from PIL import Image
7
+ import urllib
8
+
9
+ def process_image(image):
10
+ image = np.array(image)
11
+ gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
12
+ gray, img_bin = cv2.threshold(gray,128,255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)
13
+ gray = cv2.bitwise_not(img_bin)
14
+
15
+ kernel = np.ones((2, 1), np.uint8)
16
+ img = cv2.erode(gray, kernel, iterations=1)
17
+ img = cv2.dilate(img, kernel, iterations=1)
18
+ generated_text = pytesseract.image_to_string(img)
19
+
20
+ return generated_text
21
+
22
+ title = "Interactive demo: TrOCR"
23
+ description = "Demo for tesseract ocr"
24
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/2109.10282'>TrOCR: Transformer-based Optical Character Recognition with Pre-trained Models</a> | <a href='https://github.com/microsoft/unilm/tree/master/trocr'>Github Repo</a></p>"
25
+ examples =[["image_0.png"]]
26
+
27
+ iface = gr.Interface(fn=process_image,
28
+ inputs=gr.inputs.Image(type="pil"),
29
+ outputs=gr.outputs.Textbox(),
30
+ title=title,
31
+ description=description,
32
+ article=article)
33
+ iface.launch(debug=True)