From ab9cfb6248f38d1dad19d0a2d83b917f2f4ae925 Mon Sep 17 00:00:00 2001 From: D3h Date: Thu, 27 Feb 2025 12:19:23 +0300 Subject: [PATCH] initial commit --- Dockerfile | 9 +++++++++ main.py | 36 ++++++++++++++++++++++++++++++++++++ ocr-bot.tar.gz | Bin 0 -> 45 bytes requirements.txt | 2 ++ 4 files changed, 47 insertions(+) create mode 100644 Dockerfile create mode 100644 main.py create mode 100644 ocr-bot.tar.gz create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..802e41f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.11 + +WORKDIR /app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY . . + +CMD ["python", "main.py"] diff --git a/main.py b/main.py new file mode 100644 index 0000000..5226d1e --- /dev/null +++ b/main.py @@ -0,0 +1,36 @@ +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() \ No newline at end of file diff --git a/ocr-bot.tar.gz b/ocr-bot.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..872c01559ea7ac2302b7d73ae653f7ad29f8981d GIT binary patch literal 45 qcmb2|=3oE==C=nKd4a4$3%>j3@|iDyhyuw5bLLt1WYrlo7#IN4*9i&$ literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..188c075 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +telebot +easyocr \ No newline at end of file