Skip to content

Commit

Permalink
Merge pull request #19
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
ptrvsrg authored Jul 4, 2024
2 parents 90e87bf + aa8eeba commit 3b20a6c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .env.local.example
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/bot/handlers/predict_images_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions app/bot/middlewares/subscription_limit_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
3 changes: 2 additions & 1 deletion locales/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 объектов"
}

0 comments on commit 3b20a6c

Please sign in to comment.