Spaces:
Running
Running
Sarath0x8f
commited on
Update ObjCharRec.py
Browse files- ObjCharRec.py +30 -29
ObjCharRec.py
CHANGED
@@ -1,30 +1,31 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
"""
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
result
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
30 |
print(ocr_with_paddle('Images/download.jpeg'))
|
|
|
1 |
+
from paddleocr import PaddleOCR
|
2 |
+
import translate_speak
|
3 |
+
import datetime
|
4 |
+
|
5 |
+
def ocr_with_paddle(img):
|
6 |
+
"""
|
7 |
+
Paddle OCR
|
8 |
+
"""
|
9 |
+
try:
|
10 |
+
finaltext = ''
|
11 |
+
ocr = PaddleOCR(lang='en', use_angle_cls=True)
|
12 |
+
result = ocr.ocr(img)
|
13 |
+
|
14 |
+
if result[0] == None:
|
15 |
+
finaltext = "Text not found in the given Image. Try with another Image"
|
16 |
+
else:
|
17 |
+
for i in range(len(result[0])):
|
18 |
+
text = result[0][i][1][0]
|
19 |
+
finaltext += ' ' + text
|
20 |
+
|
21 |
+
with open("Request.txt", 'a', encoding="utf-8") as f:
|
22 |
+
f.write(f"{datetime.datetime.now()}: {finaltext}\n")
|
23 |
+
|
24 |
+
audio_path = translate_speak.audio_streaming(txt=finaltext, to=1)
|
25 |
+
|
26 |
+
return finaltext, audio_path
|
27 |
+
except Exception as e:
|
28 |
+
return f"An error occurred. Please upload image {e}", translate_speak.audio_streaming(txt="An error occurred. Please upload image", to=1)
|
29 |
+
|
30 |
+
if __name__ == "__main__":
|
31 |
print(ocr_with_paddle('Images/download.jpeg'))
|