-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (48 loc) · 2.21 KB
/
main.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.contrib.fsm_storage.memory import MemoryStorage
import yaml
import remove_bg
import scale
import os
remove_bg = remove_bg.remove_bg
with open('config.yaml') as f:
config = yaml.load(f, Loader=yaml.FullLoader)
bot = Bot(token=config['token'])
dp = Dispatcher(bot, storage=MemoryStorage())
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
await bot.send_message(message.chat.id, "Привет Иван! Прикрепи сюда фото".
format(message.from_user))
@dp.message_handler(content_types=['photo'])
async def text_recognition(message: types.Message):
chat_id = message.chat.id
user_id = message.from_user.id
delete_message = await bot.send_message(chat_id, 'Ща замучу...'.
format(message.from_user))
src = f'files/{message.chat.id}/'
await message.photo[-1].download(destination_file=src + 'temp.jpg')
remove_bg(src + 'temp.jpg', src + 'clrbg.jpg')
scale.scale_cv2(src + 'clrbg.jpg', src)
os.remove(src + 'clrbg.jpg')
photo = open(src + 'result.jpg', 'rb') # rb - чтение байтов, wb - запись байтов.
await bot.send_photo(chat_id, photo)
# image_text = textr.recognition(src, 'temp.jpg', language)
# db.to_mongo(user_id, image_text, 'update_temp')
# await bot.send_message(chat_id, text=image_text, reply_markup=kb.inline_text_kb)
# await bot.delete_message(chat_id, delete_message.message_id)
# remove_bg = remove_bg.remove_bg
# remove_bg('test3.jpg', 'clrbg.jpg')
# scale.scale_cv2('clrbg.jpg')
# os.remove('clrbg.jpg')
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint.
async def shutdown(dispatcher: Dispatcher):
await dispatcher.storage.close()
await dispatcher.storage.wait_closed()
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
executor.start_polling(dp, on_shutdown=shutdown)
# See PyCharm help at https://www.jetbrains.com/help/pycharm/