File size: 1,073 Bytes
d867b14
 
 
 
 
 
 
 
 
 
582935f
d867b14
 
 
 
 
 
 
 
 
fb13c00
 
 
d867b14
 
 
 
 
 
 
d69917c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from paddleocr import PaddleOCR
import translate_speak
import datetime

def ocr_with_paddle(img):
    """
    Paddle OCR
    """
    try:
        finaltext = ''
        ocr = PaddleOCR(lang='en', use_angle_cls=True, show_log=False)
        result = ocr.ocr(img)

        if result[0] == None:
            finaltext = "Text not found in the given Image. Try with another Image"
        else:
            for i in range(len(result[0])):
                text = result[0][i][1][0]
                finaltext += ' ' + text

        # with open("Request.txt", 'a', encoding="utf-8") as f:
        #     f.write(f"{datetime.datetime.now()}: {finaltext}\n")
        print(f"\n{datetime.datetime.now()}: {finaltext}\n")
        audio_path = translate_speak.audio_streaming(txt=finaltext, to=1)

        return finaltext, audio_path
    except Exception as e:
        return f"An error occurred. Please upload image {e}", translate_speak.audio_streaming(txt="An error occurred. Please upload image", to=1)

if __name__ == "__main__":
    print(ocr_with_paddle('Images/download.jpeg'))