@@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-12-04 13:22+0300\n" +"POT-Creation-Date: 2025-12-05 17:44+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -563,7 +563,7 @@ msgstr "" msgid "Token is invalid" msgstr "" -#: messages/serializers.py:50 +#: messages/serializers.py:44 #, python-format msgid "The file size cannot exceed %(max_mb_size)d MB" msgstr "Файл не может быть размером больше %(max_mb_size)d мегабайт" @@ -640,6 +640,10 @@ msgstr "Файл (%(file_type)s) не прикреплен" msgid "No image content found in response. Try a different request" msgstr "В промпте отсутствует описание изображения. Попробуйте другой запрос" +#: ml_model/exceptions.py:90 +msgid "Use style type AUTO or GENERAL when a style preset is selected" +msgstr "При выбранном стиле используйте тип стиля AUTO или GENERAL" + #: ml_model/models.py:18 ml_model/models.py:38 ml_model/models.py:70 #: ml_model/models.py:182 msgid "Slug" @@ -923,12 +927,7 @@ msgstr "Инструкции Моделей" msgid "no model by this id" msgstr "Не найдено моделей по этому ID" -#: ml_model/services/chatgpt.py:187 -msgid "Unable to recognize the image. (Supported formats are PNG, JPG, JPEG)" -msgstr "" -"Невозможно распознать изображение. (Поддерживаемые форматы: PNG, JPG, JPEG)" - -#: ml_model/services/chatgpt.py:212 +#: ml_model/services/chatgpt.py:225 msgid "No matching version found" msgstr "Соответствующая версия не найдена" @@ -1240,6 +1239,12 @@ msgstr "Отсутствует обязательный параметр: 'messa msgid "Model not found" msgstr "Модель не найдена" +#~ msgid "" +#~ "Unable to recognize the image. (Supported formats are PNG, JPG, JPEG)" +#~ msgstr "" +#~ "Невозможно распознать изображение. (Поддерживаемые форматы: PNG, JPG, " +#~ "JPEG)" + #~ msgid "Wrong username" #~ msgstr "Неверное имя пользователя" @@ -1,14 +1,13 @@ -import base64 import time from datetime import timedelta from decimal import Decimal from io import BytesIO -import filetype import requests from django.core.files import File from messages.models import Message +from ml_model.exceptions import InvalidStyleCombinationError from ml_model.models import ( NeuronModel, ) @@ -63,6 +62,11 @@ class Ideogram(SimpleService): def make(self, input_message: Message, save: bool = True) -> list[Message]: start_time = time.time() version = input_message.info.get('version') + if ( + input_message.info.get('style_preset', 'None') != 'None' + and input_message.info.get('style_type', 'None') not in ('None', 'Auto', 'General') + ): + raise InvalidStyleCombinationError callback_data = dict( { 'prompt': self.translate_prompt(input_message.content), @@ -8,8 +8,10 @@ from typing import Optional import filetype import requests from django.core.files import File +from replicate.exceptions import ModelError from messages.models import Message +from ml_model.exceptions import ImageContentNotFound from ml_model.services.base import SimpleService from ml_model.tasks import replicate_run @@ -63,7 +65,11 @@ class Nanobanana(SimpleService): image = f'data:{mime};base64,{base64.b64encode(input_message.file.read()).decode("utf-8")}' input_message.file.close() callback_data.update({'image_input': [image]}) - image = replicate_run(f'google/{version}', callback_data) + try: + image = replicate_run(f'google/{version}', callback_data) + except ModelError as exc: + if exc.prediction.error == 'No image content found in response': + raise ImageContentNotFound process_time = timedelta(seconds=(time.time() - start_time)) self.handle_invoice(input_message.content_object.model, version=version, resolution=resolution) msgs = self.save_results(input_message.content, image, process_time, save) @@ -83,3 +83,8 @@ class FileNotProvided(Exception): class ImageContentNotFound(Exception): def __str__(self): return _('No image content found in response. Try a different request') + + +class InvalidStyleCombinationError(Exception): + def __str__(self) -> str: + return _('Use style type AUTO or GENERAL when a style preset is selected') @@ -10,7 +10,13 @@ from rest_framework.views import APIView from messages.models import Message from messages.serializers import MessageSerializer -from ml_model.exceptions import RequestBlocked, UnsupportedSize, FileNotProvided, ImageContentNotFound +from ml_model.exceptions import ( + RequestBlocked, + UnsupportedSize, + FileNotProvided, + ImageContentNotFound, + InvalidStyleCombinationError +) from ml_model.models import NeuronModel from ml_model.services.base import SimpleService from payments.exceptions.insufficient_balance import InsufficientBalance @@ -152,7 +158,9 @@ class MediaAPIView(APIView): input_message.save() if isinstance(exc, InsufficientBalance): return Response({'detail': f'{exc}'}, status=HTTP_402_PAYMENT_REQUIRED) - if isinstance(exc, (UnsupportedSize, RequestBlocked, FileNotProvided, ImageContentNotFound)): + if isinstance(exc, ( + UnsupportedSize, RequestBlocked, FileNotProvided, ImageContentNotFound, InvalidStyleCombinationError + )): return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) return Response( {