Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,44 @@
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
-
import
|
4 |
from PIL import Image
|
5 |
|
6 |
-
def
|
7 |
-
|
8 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
9 |
|
10 |
-
|
11 |
-
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
25 |
-
return output
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
-
|
32 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import cv2
|
3 |
+
import easyocr
|
4 |
from PIL import Image
|
5 |
|
6 |
+
def get_grayscale(image):
|
7 |
+
return cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
|
8 |
|
9 |
+
def thresholding(src):
|
10 |
+
return cv2.threshold(src,127,255, cv2.THRESH_TOZERO)[1]
|
11 |
|
12 |
+
def ocr_with_easy(img):
|
13 |
+
gray_scale_image = get_grayscale(img)
|
14 |
+
thresholding(gray_scale_image)
|
15 |
+
cv2.imwrite('image.png', gray_scale_image)
|
16 |
+
reader = easyocr.Reader(['en'])
|
17 |
+
bounds = reader.readtext('image.png', paragraph="False", detail=0)
|
18 |
+
bounds = ''.join(bounds)
|
19 |
+
return bounds
|
20 |
|
21 |
+
def generate_ocr(img):
|
22 |
+
text_output = ''
|
23 |
+
if (img).any():
|
24 |
+
if img is not None:
|
25 |
+
text_output = ocr_with_easy(img)
|
26 |
+
else:
|
27 |
+
raise gr.Error("Please upload an image!!!!")
|
28 |
+
return text_output
|
29 |
|
30 |
+
image = gr.Image()
|
31 |
+
output = gr.Textbox(label="Output")
|
|
|
32 |
|
33 |
+
demo = gr.Interface(
|
34 |
+
generate_ocr,
|
35 |
+
image,
|
36 |
+
output,
|
37 |
+
title="Optical Character Recognition",
|
38 |
+
css=".gradio-container {background-color: lightgray} #radio_div {background-color: #FFD8B4; font-size: 40px;}",
|
39 |
+
article = """<p style='text-align: center;'>Feel free to give us your thoughts on this demo and please contact us at
|
40 |
+
<a href="mailto:[email protected]" target="_blank">[email protected]</a>
|
41 |
+
<p style='text-align: center;'>Developed by: <a href="https://www.pragnakalp.com" target="_blank">Pragnakalp Techlabs</a></p>"""
|
42 |
+
)
|
43 |
|
44 |
+
demo.launch()
|
|