From 25992ef772e5dcbca62f5e284a74f2bf55dc1098 Mon Sep 17 00:00:00 2001 From: Kirill Kirilenko Date: Sat, 7 Mar 2026 04:32:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20=D0=B3?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BC=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ai_agent.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ai_agent.py b/ai_agent.py index 756765e..b514caa 100644 --- a/ai_agent.py +++ b/ai_agent.py @@ -29,7 +29,7 @@ PRIVATE_CHAT_MAX_MESSAGES = 40 MAX_OUTPUT_TOKENS = 500 FAL_MODEL = "fal-ai/bytedance/seedream/v4.5/text-to-image" -REPLICATE_MODEL = "ultracoderru/nova-anime-xl-il-140:83a9531bdd7eab282e68d16a80d7b25502df827e43d286360299fe6321d81d06" +REPLICATE_MODEL = "ultracoderru/nova-anime-xl-14:1a8ded85309ffeb41780db667102ea935e4140b1a15f4a0f669a60a104b722db" @dataclass() @@ -286,12 +286,13 @@ class AiAgent: "height": height, "guidance_scale": 4.5, "num_inference_steps": 20, + "hires_enable": True, "disable_safety_checker": True } try: outputs = await self.replicate_client.async_run(REPLICATE_MODEL, input=arguments) - image = _convert_image_to_jpeg(await outputs[0].aread()) + image = _convert_image_to_jpeg(await outputs[0].aread(), (width, height)) return Ok(image) except Exception as e: print(f"Ошибка генерации изображения: {e}") @@ -407,8 +408,10 @@ def _get_resolution_for_aspect_ratio(aspect_ratio: str) -> Tuple[int, int]: return aspect_ratio_resolution_map.get(aspect_ratio, (1280, 1024)) -def _convert_image_to_jpeg(image: bytes) -> bytes: +def _convert_image_to_jpeg(image: bytes, size: Optional[tuple[int, int]] = None) -> bytes: img = Image.open(BytesIO(image)).convert("RGB") + if size is not None: + img = img.resize(size=size, resample=Image.Resampling.BILINEAR) output = BytesIO() img.save(output, format='JPEG', quality=87, optimize=True) return output.getvalue()