Spaces:
Sleeping
Sleeping
pragnakalp
commited on
Commit
•
6d9f1bd
1
Parent(s):
a6fc706
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,8 @@ from PIL import Image
|
|
18 |
from paddleocr import PaddleOCR
|
19 |
from save_data import flag
|
20 |
import spaces
|
|
|
|
|
21 |
|
22 |
gpus = tf.config.experimental.list_physical_devices('GPU')
|
23 |
if gpus:
|
@@ -48,13 +50,27 @@ Keras OCR
|
|
48 |
"""
|
49 |
@spaces.GPU
|
50 |
def ocr_with_keras(img):
|
51 |
-
output_text = ''
|
52 |
-
pipeline=keras_ocr.pipeline.Pipeline()
|
53 |
-
images=[keras_ocr.tools.read(img)]
|
54 |
-
predictions=pipeline.recognize(images)
|
55 |
-
first=predictions[0]
|
56 |
-
for text,box in first:
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
return output_text
|
59 |
|
60 |
"""
|
|
|
18 |
from paddleocr import PaddleOCR
|
19 |
from save_data import flag
|
20 |
import spaces
|
21 |
+
import pytesseract
|
22 |
+
from PIL import Image
|
23 |
|
24 |
gpus = tf.config.experimental.list_physical_devices('GPU')
|
25 |
if gpus:
|
|
|
50 |
"""
|
51 |
@spaces.GPU
|
52 |
def ocr_with_keras(img):
|
53 |
+
# output_text = ''
|
54 |
+
# pipeline=keras_ocr.pipeline.Pipeline()
|
55 |
+
# images=[keras_ocr.tools.read(img)]
|
56 |
+
# predictions=pipeline.recognize(images)
|
57 |
+
# first=predictions[0]
|
58 |
+
# for text,box in first:
|
59 |
+
# output_text += ' '+ text
|
60 |
+
# return output_text
|
61 |
+
|
62 |
+
|
63 |
+
# Path to Tesseract executable (you may need to change this)
|
64 |
+
pytesseract.pytesseract.tesseract_cmd = r'<path_to_tesseract_executable>'
|
65 |
+
|
66 |
+
# Load the image
|
67 |
+
image = Image.open(img)
|
68 |
+
|
69 |
+
# Perform OCR on the image
|
70 |
+
output_text = pytesseract.image_to_string(image)
|
71 |
+
|
72 |
+
# Print the extracted text
|
73 |
+
print(output_text)
|
74 |
return output_text
|
75 |
|
76 |
"""
|