diff --git a/.env.local.example b/.env.local.example index d07cb76..439cbfe 100644 --- a/.env.local.example +++ b/.env.local.example @@ -1,6 +1,6 @@ MAJOR_VERSION=1 -MINOR_VERSION=0 -PATCH_VERSION=1 +MINOR_VERSION=1 +PATCH_VERSION=0 LOCALE_DIR=locales DETECT_MODEL_PATH=models/yolov8n.pt diff --git a/app/bot/handlers/predict_images_handler.py b/app/bot/handlers/predict_images_handler.py index e153794..17aa9ea 100644 --- a/app/bot/handlers/predict_images_handler.py +++ b/app/bot/handlers/predict_images_handler.py @@ -59,6 +59,12 @@ async def predict_images(message: Message, bot: Bot, state: FSMContext): if len(cropped_images) == 0: cropped_images = [file_bytes] + # Too many objects in the photo + if len(cropped_images) > 10: + await answer.delete() + await message.answer(t("error.too_many_objects_in_photo")) + return + # User must select one image if more than one is detected if len(cropped_images) > 1: # Send message with cropped images diff --git a/app/bot/middlewares/subscription_limit_filter.py b/app/bot/middlewares/subscription_limit_filter.py index 0e27654..4975591 100644 --- a/app/bot/middlewares/subscription_limit_filter.py +++ b/app/bot/middlewares/subscription_limit_filter.py @@ -5,7 +5,7 @@ from app.bot.utils.message_utils import ( get_username_from_message, ) -from app.service import user_service +from app.service import statistics_service from app.config import config @@ -16,9 +16,9 @@ def __init__(self): async def __call__(self, message: Message) -> bool: username = get_username_from_message(message) - user = user_service.get_user_by_username(username) + statistics = statistics_service.get_statistics(username) - limit_reached = user.daily_predictions >= config.bot.daily_limit + limit_reached = statistics.daily_predictions >= config.bot.daily_limit if limit_reached: await message.answer(t("error.subscription_limit")) diff --git a/docker/Dockerfile b/docker/Dockerfile index 24e3b85..e67b21c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -16,8 +16,8 @@ RUN pip3 install -r app/requirements.txt ENV PYTHONPATH=. ENV MAJOR_VERSION=1 -ENV MINOR_VERSION=0 -ENV PATCH_VERSION=1 +ENV MINOR_VERSION=1 +ENV PATCH_VERSION=0 ENV LOCALE_DIR=locales ENV DETECT_MODEL_PATH=models/yolov8n.pt ENV PREDICT_MODEL_PATH=models/yolov8n-hotdog-cls.pt diff --git a/locales/en.json b/locales/en.json index 99e0be4..52a2358 100644 --- a/locales/en.json +++ b/locales/en.json @@ -47,5 +47,6 @@ "error.only_one_image" : "Only one image can be uploaded", "error.image_too_big" : "Image too large", "error.subscription_limit" : "Daily prediction limit reached", - "error.file_not_found" : "File lifetime expired" + "error.file_not_found" : "File lifetime expired", + "error.too_many_objects_in_photo": "Too many objects in the photo. Try cropping the photo to no more than 10 objects" } \ No newline at end of file diff --git a/locales/ru.json b/locales/ru.json index 5412a7b..c668ff2 100644 --- a/locales/ru.json +++ b/locales/ru.json @@ -47,5 +47,6 @@ "error.only_one_image" : "Можно загрузить только одно изображение", "error.image_too_big" : "Изображение слишком большое", "error.subscription_limit" : "Достигнут лимит на количество предсказаний за день", - "error.file_not_found" : "Истекло время жизни файла" + "error.file_not_found" : "Истекло время жизни файла", + "error.too_many_objects_in_photo": "Слишком много объектов на фотографии. Попробуйте обрезать фото, чтобы было не более 10 объектов" }