@@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-05-06 17:58+0300\n" +"POT-Creation-Date: 2026-05-14 22:35+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -624,7 +624,7 @@ msgstr "" msgid "A %(model)s with fields %(fields)s already exists" msgstr "Уже существует %(model)s с полями %(fields)s" -#: messages/serializers.py:44 ml_model/exceptions.py:78 +#: messages/serializers.py:44 ml_model/exceptions.py:86 #, python-format msgid "The file size cannot exceed %(max_mb_size)d MB" msgstr "Файл не может быть размером больше %(max_mb_size)d мегабайт" @@ -663,11 +663,16 @@ msgstr "" "Размер изображения %(cw)sx%(ch)s не поддерживается. Требуемый размер: " "%(rw)sx%(rh)s" -#: ml_model/exceptions.py:45 +#: ml_model/exceptions.py:47 +#, python-format +msgid "Image exceeds the maximum allowed pixel count (%(max_pixels)d)." +msgstr "Размер изображения превышает максимально допустимое количество пикселей (%(max_pixels)d)." + +#: ml_model/exceptions.py:53 msgid "The model is not responding" msgstr "Модель не отвечает" -#: ml_model/exceptions.py:54 +#: ml_model/exceptions.py:62 #, python-format msgid "" "The attached file format is not supported. Available formats: " @@ -676,79 +681,79 @@ msgstr "" "Формат вложенного файла не поддерживается. Доступные форматы: " "%(available_extensions)s." -#: ml_model/exceptions.py:60 +#: ml_model/exceptions.py:68 msgid "The file may be corrupted. Please try another one." msgstr "Возможно, файл повреждён. Попробуйте загрузить другой файл." -#: ml_model/exceptions.py:65 +#: ml_model/exceptions.py:73 msgid "File Uploading Not supported" msgstr "Загрузка файлов не поддерживается" -#: ml_model/exceptions.py:70 +#: ml_model/exceptions.py:78 msgid "Unable to recognize the file" msgstr "Не удаётся распознать файл" -#: ml_model/exceptions.py:83 +#: ml_model/exceptions.py:91 msgid "The length of the context has been exceeded." msgstr "Длина контекста превышена." -#: ml_model/exceptions.py:88 +#: ml_model/exceptions.py:96 msgid "Jinja template not found" msgstr "Jinja-шаблон не найден" -#: ml_model/exceptions.py:93 +#: ml_model/exceptions.py:101 msgid "There was an unknown error while rendering a template" msgstr "При рендеринге шаблона произошла неизвестная ошибка" -#: ml_model/exceptions.py:98 +#: ml_model/exceptions.py:106 msgid "The neuron model does not exist" msgstr "Нейронная модель не существует" -#: ml_model/exceptions.py:106 +#: ml_model/exceptions.py:114 #, python-format msgid "The %(file_type)s is not attached" msgstr "Файл (%(file_type)s) не прикреплен" -#: ml_model/exceptions.py:111 +#: ml_model/exceptions.py:119 msgid "No image content found in response. Try a different request" msgstr "В промпте отсутствует описание изображения. Попробуйте другой запрос" -#: ml_model/exceptions.py:116 +#: ml_model/exceptions.py:124 msgid "" "The model could not analyze your request. Please rephrase it and try again" msgstr "" "Модель не смогла проанализировать ваш запрос. Перефразируйте его и " "попробуйте снова" -#: ml_model/exceptions.py:121 +#: ml_model/exceptions.py:129 msgid "Image analysis error. Please try another image." msgstr "Ошибка анализа изображения. Попробуйте другую картинку." -#: ml_model/exceptions.py:126 +#: ml_model/exceptions.py:134 msgid "Use style type AUTO or GENERAL when a style preset is selected" msgstr "При выбранном стиле используйте тип стиля AUTO или GENERAL" -#: ml_model/exceptions.py:131 +#: ml_model/exceptions.py:139 msgid "Prediction interrupted. Please retry again" msgstr "Генерация прервана. Пожалуйста, повторите попытку еще раз" -#: ml_model/exceptions.py:146 +#: ml_model/exceptions.py:154 #, python-format msgid "Prompt is too long. Maximum length is %(max_length)s characters." msgstr "Промпт слишком длинный. Максимальная длина — %(max_length)s символов." -#: ml_model/exceptions.py:153 +#: ml_model/exceptions.py:161 msgid "" "Service is currently unavailable due to high demand. Please try again later" msgstr "" "Сервис временно недоступен из-за высокой нагрузки. Пожалуйста, попробуйте " "позже" -#: ml_model/exceptions.py:158 +#: ml_model/exceptions.py:166 msgid "Available only in paid plan" msgstr "Доступно только в платном тарифе" -#: ml_model/exceptions.py:163 +#: ml_model/exceptions.py:171 msgid "Face not found in the image. Please try another image with a face." msgstr "Не найдено лицо на картинке. Попробуйте другую картинку с лицом." @@ -1043,11 +1048,11 @@ msgstr "Не найдено моделей по этому ID" msgid "No matching version found" msgstr "Соответствующая версия не найдена" -#: ml_model/services/chatgpt_5_4.py:269 +#: ml_model/services/chatgpt_5_4.py:270 msgid "Image is ready" msgstr "Изображение готово" -#: ml_model/services/elevenlabs_music.py:46 +#: ml_model/services/elevenlabs_music.py:45 msgid "Duration cannot be less than 5 seconds" msgstr "Длительность не может быть меньше 5 секунд" @@ -1065,20 +1070,23 @@ msgstr "" "Режим «Плавное движение» доступен только для 5-секундных видео в качестве " "540p и 720p" -#: ml_model/services/minimaxmusic.py:58 -#: ml_model/services/minimaxmusic_lite.py:62 -msgid "Lyrics is too long" -msgstr "Текст песни слишком длинный" - #: ml_model/services/minio_service.py:37 ml_model/services/minio_service.py:55 #: ml_model/services/minio_service.py:63 ml_model/services/minio_service.py:72 msgid "Unknown bucket destination" msgstr "Неизвестный бакет для загрузки" +#: ml_model/services/seedance_2_dreamina.py:108 +msgid "1080p output is not supported for Seedance Dreamina 2.0 Fast." +msgstr "" + #: ml_model/services/upscaleai.py:124 msgid "No image given for improving" msgstr "Нет изображения для улучшения" +#: ml_model/tasks.py:188 +msgid "Lyrics is too long" +msgstr "Текст песни слишком длинный" + #: ml_model/views.py:65 msgid "Model data cannot be retrieved" msgstr "Невозможно получить данные модели" @@ -1093,7 +1101,7 @@ msgstr "" msgid "Missing" msgstr "Отсутствующий" -#: payments/apps.py:11 payments/models/payment.py:60 +#: payments/apps.py:12 payments/models/payment.py:60 msgid "Payments" msgstr "Платежи" @@ -7,9 +7,10 @@ from io import BytesIO import filetype from PIL import Image +from PIL.Image import DecompressionBombError from messages.models import Message -from ml_model.exceptions import FileExtensionNotSupported, CorruptedFileError +from ml_model.exceptions import FileExtensionNotSupported, CorruptedFileError, ImageTooLargeError from ml_model.services.EmbeddingService import EmbeddingService from ml_model.services.FileService import FileProcessingService from ml_model.services.base import SimpleService @@ -27,6 +28,9 @@ class Grok_4_1_Fast(SimpleService): TOOLS_TOKEN_COSTS = {'text-embedding-3-small': {'output': Decimal('0.00001')}} + MAX_PIXELS = 178956970 + + def calculate_price(self, input_tokens: int, output_tokens: int, embedding_tokens: int) -> Decimal: price = ( input_tokens * self.TOKENS_COST['input'] / 1_000_000 @@ -57,6 +61,7 @@ class Grok_4_1_Fast(SimpleService): if input_message.file: file_service = FileProcessingService file_bytes = input_message.file.read() + input_message.file.close() kind = filetype.guess(file_bytes[:550]) if not kind: raise CorruptedFileError @@ -100,14 +105,20 @@ class Grok_4_1_Fast(SimpleService): f'{chunks}. Вопрос: {input_message.content}' ) elif file_extension in ('jpg', 'jpeg', 'png', 'webp'): - kind = filetype.guess(file_bytes[:20]) + try: + with Image.open(BytesIO(file_bytes)) as normalized_image: + current_pixels = normalized_image.width * normalized_image.height + if current_pixels > self.MAX_PIXELS: + raise ImageTooLargeError(self.MAX_PIXELS) + except DecompressionBombError: + raise ImageTooLargeError(self.MAX_PIXELS) + mime = kind.mime if kind else 'application/octet-stream' - normalized_image = Image.open(input_message.file) - format = 'jpeg' if kind.extension == 'jpg' else kind.extension - buf = BytesIO() - normalized_image.save(buf, format=format) - image_url = f'data:{mime};base64,{base64.b64encode(buf.getvalue()).decode("utf-8")}' - buf.close() + image_url = ( + f'data:{mime};base64,' + f'{base64.b64encode(file_bytes).decode("utf-8")}' + ) + messages[-1]['content'] = [ {'type': 'text', 'text': input_message.content}, {'type': 'image_url', 'image_url': {'url': image_url}}, @@ -39,6 +39,14 @@ class UnsupportedSize(Exception): self.current_size | self.required_size ) +class ImageTooLargeError(Exception): + def __init__(self, max_pixels: int) -> None: + self.max_pixels = max_pixels + + def __str__(self) -> str: + return _('Image exceeds the maximum allowed pixel count (%(max_pixels)d).') % { + 'max_pixels': self.max_pixels + } class ModelTimeoutError(Exception): def __str__(self): @@ -160,4 +168,4 @@ class PaidPlanRequiredError(Exception): class FaceNotFoundError(Exception): def __str__(self) -> str: - return _('Face not found in the image. Please try another image with a face.') + return _('Face not found in the image. Please try another image with a face.') \ No newline at end of file