Sarath0x8f commited on
Commit
d867b14
·
verified ·
1 Parent(s): fc1a867

Update ObjCharRec.py

Browse files
Files changed (1) hide show
  1. ObjCharRec.py +30 -29
ObjCharRec.py CHANGED
@@ -1,30 +1,31 @@
1
- import os
2
-
3
- from paddleocr import PaddleOCR
4
- import translate_speak
5
-
6
-
7
- def ocr_with_paddle(img):
8
- """
9
- Paddle OCR
10
- """
11
- try:
12
- finaltext = ''
13
- ocr = PaddleOCR(lang='en', use_angle_cls=True)
14
- result = ocr.ocr(img)
15
-
16
- if result[0] == None:
17
- finaltext = "Text not found in the given Image. Try with another Image"
18
- else:
19
- for i in range(len(result[0])):
20
- text = result[0][i][1][0]
21
- finaltext += ' ' + text
22
-
23
- audio_path = translate_speak.audio_streaming(txt=finaltext, to=1)
24
-
25
- return finaltext, audio_path
26
- except Exception as e:
27
- return f"An error occurred. Please upload image {e}", translate_speak.audio_streaming(txt="An error occurred. Please upload image", to=1)
28
-
29
- if __name__ == "__main__":
 
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'))