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