From 79bba6c45487783a2492d3bff964295425652b6d Mon Sep 17 00:00:00 2001 From: sudoskys Date: Sat, 9 Mar 2024 13:29:16 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20feat(playground):=20encode=20im?= =?UTF-8?q?age=20in=20base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add base64 encoding for images in img2img image generation script. --- playground/generate_image_img2img.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playground/generate_image_img2img.py b/playground/generate_image_img2img.py index 88fbf84..4942a97 100755 --- a/playground/generate_image_img2img.py +++ b/playground/generate_image_img2img.py @@ -4,6 +4,7 @@ # @File : generate_image_img2img.py # @Software: PyCharm import asyncio +import base64 import os import pathlib from dotenv import load_dotenv @@ -35,7 +36,9 @@ async def generate( if not os.path.exists(image_path): raise ValueError(f"Image not found: {image_path}") with open(image_path, "rb") as f: - image = f.read() + # Base64 encode the image + image = base64.b64encode(f.read()).decode() + # image = f.read() # Or you can use the raw bytes agent = GenerateImageInfer.build( prompt=prompt, action=Action.IMG2IMG, From 08b245f3f9947cdf691ba4e5a5e57002f2680807 Mon Sep 17 00:00:00 2001 From: sudoskys Date: Sat, 9 Mar 2024 13:44:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Update=20default=20wi?= =?UTF-8?q?dth=20and=20height=20values=20in=20add=5Fimage=5Fto=5Fblack=5Fb?= =?UTF-8?q?ackground?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Update default width and height values to 448 in add_image_to_black_background - method to ensure consistent behavior. --- src/novelai_python/sdk/ai/generate_image/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/novelai_python/sdk/ai/generate_image/__init__.py b/src/novelai_python/sdk/ai/generate_image/__init__.py index b5dfd0d..412a907 100755 --- a/src/novelai_python/sdk/ai/generate_image/__init__.py +++ b/src/novelai_python/sdk/ai/generate_image/__init__.py @@ -146,7 +146,7 @@ def resize_image(image: Union[str, bytes], width: int, height: int): return base64.b64encode(buffered.getvalue()).decode("utf-8") @staticmethod - def add_image_to_black_background(image: Union[str, bytes], width: int, height: int): + def add_image_to_black_background(image: Union[str, bytes], width: int = 448, height: int = 448): """ 将图像缩放到一个指定的黑背景上,使其最大,比例不变。 :param image: 图像 @@ -201,7 +201,7 @@ def image_validator(self): if self.image is not None: self.image = self.resize_image(self.image, self.width, self.height) if self.reference_image is not None: - self.reference_image = self.add_image_to_black_background(self.reference_image, self.width, self.height) + self.reference_image = self.add_image_to_black_background(self.reference_image, width=448, height=448) return self @field_validator('width') From 9c4b7de3330df33487086c6cb20607959a29494f Mon Sep 17 00:00:00 2001 From: sudoskys Date: Sat, 9 Mar 2024 13:44:46 +0800 Subject: [PATCH 3/3] :arrow_up: chore: update version to 0.3.7 in pyproject.toml --- pdm.lock | 8 ++++---- pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pdm.lock b/pdm.lock index f56fdb4..cec077d 100755 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev", "testing"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:05422c519ee13e8e97a1f1a5cb2e2f29bea853de5aa96f17eba4dd0a4414ecc0" +content_hash = "sha256:5fc3571d83c68c12f732e371eaa12f154c8d71625917bca1ba385ce54c9a8f3c" [[package]] name = "annotated-types" @@ -300,15 +300,15 @@ files = [ [[package]] name = "fake-useragent" -version = "1.4.0" +version = "1.5.0" summary = "Up-to-date simple useragent faker with real world database" groups = ["default"] dependencies = [ "importlib-resources>=5.0; python_version < \"3.10\"", ] files = [ - {file = "fake-useragent-1.4.0.tar.gz", hash = "sha256:5426e4015d8ccc5bb25f64d3dfcfd3915eba30ffebd31b86b60dc7a4c5d65528"}, - {file = "fake_useragent-1.4.0-py3-none-any.whl", hash = "sha256:9acce439ee2c6cf9c3772fa6c200f62dc8d56605063327a4d8c5d0e47f414b85"}, + {file = "fake-useragent-1.5.0.tar.gz", hash = "sha256:c2adf4c536f9b74053e1161374398cdd78d28762062db9b741639b2133da0016"}, + {file = "fake_useragent-1.5.0-py3-none-any.whl", hash = "sha256:1ee651ebd17fa2442abe4393f00e311769051765cd20de23cc50dc771db89540"}, ] [[package]] diff --git a/pyproject.toml b/pyproject.toml index faa893f..2564560 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "novelai-python" -version = "0.3.6" +version = "0.3.7" description = "Novelai Python Binding With Pydantic" authors = [ { name = "sudoskys", email = "coldlando@hotmail.com" },