test/main.py
2025-02-27 12:19:23 +03:00

36 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import logging, requests, telebot, json, os, base64, easyocr
API_TOKEN = '7543408818:AAEzpQfRy1f5HwgOi_-FVq_s-8kuxU_Oup0'
reader = easyocr.Reader(['ru', 'en'])
logger = telebot.logger
telebot.logger.setLevel(logging.INFO)
bot = telebot.TeleBot(API_TOKEN, threaded=False)
def process_event(event):
request_body_dict = json.loads(event['body'])
update = telebot.types.Update.de_json(request_body_dict)
bot.process_new_updates([update])
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message,
"Отправьте картинку с текстом. В ответ получите текст, распознанный с этой картинки")
@bot.message_handler(func=lambda message: True, content_types=['photo'])
def echo_photo(message):
file_id = message.photo[-1].file_id
file_info = bot.get_file(file_id)
downloaded_file = bot.download_file(file_info.file_path)
responce = reader.readtext(downloaded_file, detail=0, paragraph=True)
text = ''
for par in responce:
text += par + '\n'
bot.reply_to(message, text)
bot.infinity_polling()