This commit is contained in:
Misha4ca228 2025-04-30 21:41:23 +03:00
parent 504abc5ad8
commit 89cea797b8
6 changed files with 35 additions and 10 deletions

View File

@ -490,11 +490,16 @@ class Api:
return models.TextToImageResponse(images=b64images, parameters=vars(txt2imgreq), info=processed.js())
def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
from modules.env_to_yaml import get_env_var
from modules.s3 import s3_client
from modules.download_from_s3 import get_photo_base64
task_id = img2imgreq.force_task_id or create_task_id("img2img")
init_images = img2imgreq.init_images
if init_images is None:
if img2imgreq.init_images is None:
raise HTTPException(status_code=404, detail="Init image not found")
init_images = [get_photo_base64(s3_url=img2imgreq.init_images)]
mask = img2imgreq.mask
if mask:
@ -562,8 +567,6 @@ class Api:
img2imgreq.init_images = None
img2imgreq.mask = None
from modules.s3 import s3_client
from modules.env_to_yaml import get_env_var
import uuid
b64_string = b64images[0].decode("utf-8")

View File

@ -117,7 +117,7 @@ StableDiffusionImg2ImgProcessingAPI = PydanticModelGenerator(
StableDiffusionProcessingImg2Img,
[
{"key": "sampler_index", "type": str, "default": "Euler"},
{"key": "init_images", "type": list, "default": None},
{"key": "init_images", "type": str, "default": None},
{"key": "denoising_strength", "type": float, "default": 0.75},
{"key": "mask", "type": str, "default": None},
{"key": "include_init_images", "type": bool, "default": False, "exclude" : True},

View File

@ -0,0 +1,22 @@
import base64
from modules.s3 import s3_client
from urllib.parse import urlparse
def get_photo_base64(s3_url) -> str:
try:
s3_url = s3_url
parsed = urlparse(s3_url)
path_parts = parsed.path.lstrip('/').split('/', 1)
if len(path_parts) != 2:
raise ValueError("Не удалось извлечь bucket и key из URL.")
bucket_name, s3_key = path_parts
response = s3_client.get_object(Bucket=bucket_name, Key=s3_key)
image_data = response['Body'].read()
return base64.b64encode(image_data).decode('utf-8')
except Exception as e:
print(f"Ошибка при получении файла: {e}")
return ""

View File

@ -5,4 +5,4 @@ load_dotenv()
def get_env_var(key: str) -> str:
value = os.getenv(key)
return value
return value

View File

@ -1,3 +1,4 @@
import boto3
from botocore.client import Config
@ -11,5 +12,3 @@ s3_client = boto3.client(
region_name='ru-1',
config=Config(s3={'addressing_style': 'path'})
)

View File

@ -13,18 +13,19 @@ gradio==3.41.2
inflection
jsonmerge
kornia
urllib
lark
numpy
omegaconf
open-clip-torch
dotenv
piexif
protobuf==3.20.0
psutil
pytorch_lightning
requests
resize-right
botocore
safetensors
scikit-image>=0.19
tomesd