@@ -477,6 +477,7 @@ if (SENTRY_URL := env.str('SENTRY_URL', '')) and RELEASE and ENVIRONMENT: 'RequestBlocked', 'PredictionInterruptedError', 'ImageContentNotFound', + 'InvalidParameterError' ], ) @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-12-25 15:54+0300\n" +"POT-Creation-Date: 2025-12-26 12:38+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -958,6 +958,10 @@ msgstr "Не найдено моделей по этому ID" msgid "No matching version found" msgstr "Соответствующая версия не найдена" +#: ml_model/services/minimaxmusic.py:57 +msgid "Lyrics is too long" +msgstr "Текст песни слишком длинный" + #: ml_model/services/minio_service.py:36 ml_model/services/minio_service.py:54 #: ml_model/services/minio_service.py:62 ml_model/services/minio_service.py:71 msgid "Unknown bucket destination" @@ -5,8 +5,11 @@ from io import BytesIO import requests from django.core.files import File +from django.utils.translation import gettext as _ +from replicate.exceptions import ModelError from messages.models import Message +from ml_model.exceptions import RequestBlocked, InvalidParameterError, GenerationException from ml_model.services.base import SimpleService from ml_model.tasks import replicate_run @@ -47,8 +50,15 @@ class Minimaxmusic(SimpleService): file_url = Preset.objects.get(slug=instrumental).file.url callback_data.update({'instrumental_file': file_url}) start_time = time.time() - video = replicate_run(f'minimax/music-01', callback_data) + try: + audio = replicate_run(f'minimax/music-01', callback_data) + except ModelError as exc: + if 'lyrics is too long' in str(exc): + raise InvalidParameterError(_('Lyrics is too long')) + if any(error in str(exc) for error in ('E005', 'E006', 'sexual')): + raise RequestBlocked + raise GenerationException from exc process_time = timedelta(seconds=(time.time() - start_time)) self.handle_invoice(input_message.content_object.model) - msgs = self.save_results(input_message.content, process_time, video, save) + msgs = self.save_results(input_message.content, process_time, audio, save) return msgs @@ -94,3 +94,11 @@ class InvalidStyleCombinationError(Exception): class PredictionInterruptedError(Exception): def __str__(self): return _('Prediction interrupted. Please retry again') + + +class InvalidParameterError(Exception): + def __init__(self, error_text: str): + self.error_text = error_text + + def __str__(self): + return self.error_text \ No newline at end of file @@ -15,7 +15,8 @@ from ml_model.exceptions import ( UnsupportedSize, FileNotProvided, ImageContentNotFound, - InvalidStyleCombinationError + InvalidStyleCombinationError, + InvalidParameterError, ) from ml_model.models import NeuronModel from ml_model.services.base import SimpleService @@ -158,9 +159,17 @@ 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, InvalidStyleCombinationError - )): + if isinstance( + exc, + ( + UnsupportedSize, + RequestBlocked, + FileNotProvided, + ImageContentNotFound, + InvalidStyleCombinationError, + InvalidParameterError, + ), + ): return Response({'detail': f'{exc}'}, status=HTTP_400_BAD_REQUEST) return Response( {