1
1
from telegram import Update
2
- from telegram .ext import Updater , CommandHandler , MessageHandler , Filters , CallbackContext
2
+ from telegram .ext import (
3
+ Updater ,
4
+ CommandHandler ,
5
+ MessageHandler ,
6
+ Filters ,
7
+ CallbackContext ,
8
+ )
3
9
import pytesseract
4
10
import os
5
11
from PIL import Image
6
12
import logging
7
13
import traceback
8
14
9
- pytesseract .pytesseract .tesseract_cmd = ' /usr/bin/tesseract' # ваш путь до tesseract
15
+ pytesseract .pytesseract .tesseract_cmd = " /usr/bin/tesseract" # ваш путь до tesseract
10
16
11
17
12
18
def get_text_from_image (path ):
13
19
logging .info ("getting image" )
14
20
img = Image .open (path )
15
21
logging .info ("image opened" )
16
- return pytesseract .image_to_string (img , lang = "rus+eng" ,timeout = 30 )
22
+ return pytesseract .image_to_string (img , lang = "rus+eng" , timeout = 30 )
23
+
17
24
18
25
def echo_photo (update : Update , context : CallbackContext ) -> None :
19
26
print (update .message .photo )
@@ -22,7 +29,7 @@ def echo_photo(update: Update, context: CallbackContext) -> None:
22
29
result = "Что-то пошло не так, попробуйте позже"
23
30
try :
24
31
path = "images/photo.jpg"
25
- lst [- 1 ].get_file ().download (path , timeout = 5 );
32
+ lst [- 1 ].get_file ().download (path , timeout = 5 )
26
33
logging .info ("download ok" )
27
34
result = get_text_from_image (path )
28
35
logging .info ("getting text ok" )
@@ -32,11 +39,12 @@ def echo_photo(update: Update, context: CallbackContext) -> None:
32
39
update .message .reply_text (result )
33
40
except Exception as e :
34
41
update .message .reply_text ("Текст не определен" )
35
-
42
+
36
43
37
44
def echo_no_photo (update : Update , context : CallbackContext ) -> None :
38
45
update .message .reply_text ("Это не фото" )
39
46
47
+
40
48
def help (update : Update , context : CallbackContext ) -> None :
41
49
update .message .reply_text ("Пришлите фотографию, текст с которой вам нужен" )
42
50
@@ -54,6 +62,3 @@ def main():
54
62
55
63
if __name__ == "__main__" :
56
64
main ()
57
-
58
-
59
- #/usr/src/app
0 commit comments