Skip to content

Commit

Permalink
Merge pull request #78 from LlmKira/dev
Browse files Browse the repository at this point in the history
(refactor): Add ImageVerifier for tool.image_metadata / add bch_utils
  • Loading branch information
sudoskys authored Sep 27, 2024
2 parents acdcacb + 0d93790 commit feeb058
Show file tree
Hide file tree
Showing 8 changed files with 448 additions and 153 deletions.
54 changes: 53 additions & 1 deletion pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion playground/image_metadata/read_lsb.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
from pathlib import Path

from novelai_python.tool.image_metadata.lsb_extractor import ImageLsbDataExtractor
Expand Down
33 changes: 10 additions & 23 deletions playground/image_metadata/read_nai_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# @Time : 2024/2/8 下午4:57
# @Author : sudoskys
# @File : read_nai_tag.py
from io import BytesIO
from pathlib import Path

from novelai_python.tool.image_metadata import ImageMetadata
from novelai_python.tool.image_metadata import ImageMetadata, ImageVerifier

image = Path(__file__).parent.joinpath("sample-0316.png")
image_clear = ImageMetadata.reset_alpha(
input_img=BytesIO(image.read_bytes())
image=image
)

try:
Expand All @@ -18,23 +17,11 @@
raise LookupError("Cant find a MetaData")

print(meta.Title)
print(meta.Description)
print(meta.Comment)

try:
meta = ImageMetadata.load_image(image_clear)
print(meta.Title)
print(meta.Description)
print(meta.Comment)
except ValueError:
print("Cant find a MetaData")

image = Path(__file__).parent.joinpath("sample-0317.png")
try:
meta = ImageMetadata.load_image(image)
except ValueError:
raise LookupError("Cant find a MetaData")

print(meta.Title)
print(meta.Description)
print(meta.Comment)
print(f"Description: {meta.Description}")
print(f"Comment: {meta.Comment}")
print(f"Request Method: {meta.Comment.request_type}")
print(f"Used image model: {meta.used_model}")
# Verify if the image is from NovelAI
is_novelai, have_latent = ImageVerifier().verify(image=image)
print(f"Is NovelAI: {is_novelai}")
print(f"Have Latent: {have_latent}")
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "novelai-python"
version = "0.5.1"
version = "0.5.2"
description = "NovelAI Python Binding With Pydantic"
authors = [
{ name = "sudoskys", email = "[email protected]" },
Expand Down Expand Up @@ -28,6 +28,7 @@ dependencies = [
"tokenizers>=0.15.2",
"json-repair>=0.29.4",
"robust-downloader>=0.0.2",
"bchlib>=2.1.3",
]
requires-python = ">=3.9"
readme = "README.md"
Expand Down
Loading

0 comments on commit feeb058

Please sign in to comment.