It's version 0.6.2 I clear code

This commit is contained in:
Niken
2025-11-23 23:17:00 +03:00
parent b6c1c60609
commit 7495062a8a
15 changed files with 183 additions and 97 deletions
+15 -10
View File
@@ -3,7 +3,7 @@ import base64
from io import BytesIO
import asyncio
import aiohttp
from PIL import Image
from aiogram import Dispatcher, Bot
from aiogram.types import Message, BufferedInputFile
from aiogram.filters import Command
@@ -43,6 +43,11 @@ async def generate_img2img(prompt: str, init_image: BytesIO) -> BytesIO | None:
:return: BytesIO с результатом или None при ошибке
"""
try:
# Определяем размеры оригинала
init_image.seek(0)
with Image.open(init_image) as img:
width, height = img.size
# кодируем входное изображение в base64
init_image_base64 = base64.b64encode(init_image.getvalue()).decode("utf-8")
@@ -50,15 +55,15 @@ async def generate_img2img(prompt: str, init_image: BytesIO) -> BytesIO | None:
"init_images": [init_image_base64],
"prompt": prompt,
"negative_prompt": "blurry, low quality, bad anatomy, watermark, text, cropped",
"steps": 20, # можно 1520
"width": 1024, # лучше подставлять размеры исходного фото
"height": 1024,
"sampler_name": "Euler a", # мягкий и стабильный для img2img
"Schedule_type": "Karras",
"cfg_scale": 6, # чуть ниже, чем для txt2img
"steps": 25,
"width": width, # берём ширину оригинала
"height": height, # берём высоту оригинала
"sampler_name": "Euler a",
"scheduler": "Karras", # исправлен ключ
"cfg_scale": 10,
"seed": -1,
"denoising_strength": 0.8, # 0.3–0.5 для «сохранить стиль», 0.6–0.8 для «перерисовать»
"restore_faces": True, # если работаешь с людьми
"denoising_strength": 0.45,
"restore_faces": True,
"override_settings": {
"sd_model_checkpoint": "waiNSFWIllustrious_v150.safetensors"
},
@@ -101,7 +106,7 @@ async def generate_image(prompt: str) -> BytesIO | None:
"hr_scale": 2, # во сколько раз увеличить при highres fix
"hr_upscaler": "Latent", # апскейлер для highres fix
"override_settings": {
"sd_model_checkpoint": "waiNSFWIllustrious_v150.safetensors" # выбор модели
"sd_model_checkpoint": "sd_xl_base_1.safetensors" # выбор модели
},
}