Skip to content

Commit

Permalink
Merge pull request #49 from LlmKira/dev
Browse files Browse the repository at this point in the history
Multiple Vibe Transfer
  • Loading branch information
sudoskys authored Apr 6, 2024
2 parents a378ffc + 0453df3 commit 037790a
Show file tree
Hide file tree
Showing 10 changed files with 376 additions and 247 deletions.
4 changes: 3 additions & 1 deletion playground/vibe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import asyncio
import os
import pathlib

from dotenv import load_dotenv
from pydantic import SecretStr

Expand Down Expand Up @@ -50,7 +51,8 @@ async def generate(
print(f"Error: {e.message}")
return None
else:
print(f"Meta: {result.meta}")
pass
# print(f"Meta: {result.meta}")
_res: ImageGenerateResp
file = result.files[0]
with open(f"{pathlib.Path(__file__).stem}.png", "wb") as f:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "novelai-python"
version = "0.4.5"
version = "0.4.6"
description = "NovelAI Python Binding With Pydantic"
authors = [
{ name = "sudoskys", email = "[email protected]" },
Expand Down
3 changes: 2 additions & 1 deletion record/ai/generate_image/enhance.json

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions record/ai/generate_image/export.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import base64
import json
import pathlib
import base64
from PIL import Image
from io import BytesIO

from PIL import Image
from loguru import logger


Expand All @@ -16,6 +16,23 @@ def decode_base64_in_dict(data, current_path):
for k, v in data.items():
if isinstance(v, dict) or isinstance(v, list):
decode_base64_in_dict(v, current_path)
if isinstance(v, list):
_new_list = []
for index, item in enumerate(v):
if isinstance(item, str) and len(item) > 100:
try:
# Base64解码
image_bytes = base64.b64decode(item)
image = Image.open(BytesIO(image_bytes))
except Exception as e:
ignore(e)
else:
logger.info(f"Decoding Base64 data in {k}")
img_name = f"{current_path}/{index}-{k}.png"
image.save(img_name)
_new_list.append('Base64 Data')
if _new_list:
data[k] = _new_list
if isinstance(v, str) and len(v) > 100:
try:
# Base64解码
Expand Down Expand Up @@ -47,6 +64,11 @@ def handle_file(filename):
# 写回原文件
with open(filename, 'w') as file:
json.dump(json_data, file, indent=2)
if 'authorization' in json_data['headers']:
json_data['headers']['authorization'] = 'Secret'
# 写回原文件
with open(filename, 'w') as file:
json.dump(json_data, file, indent=2)
request_data = json.loads(json_data.get("body", ""))
request_data = decode_base64_in_dict(request_data, filename_wo_ext)
# 写出包含替换字段的 JSON 文件回同名的文件夹
Expand Down
30 changes: 17 additions & 13 deletions record/ai/generate_image/vibe_image.json

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
27 changes: 18 additions & 9 deletions record/ai/generate_image/vibe_image/schema.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"input": "1boy, leaf background, from behind, cowboy shot, purple eyes, big hair, blonde hair, long bangs, tiara, striped shirt, shorts, impossible clothes, prosthetic leg, back focus, best quality, amazing quality, very aesthetic, absurdres",
"input": "no humans, scenery, bamboo forest, alley, train interior, night, road sign, bed sheet, tulip, best quality, amazing quality, very aesthetic, absurdres",
"model": "nai-diffusion-3",
"action": "generate",
"parameters": {
"params_version": 1,
"width": 128,
"height": 128,
"width": 832,
"height": 1216,
"scale": 5,
"sampler": "k_euler",
"steps": 28,
"seed": 248658061,
"n_samples": 1,
"ucPreset": 0,
"qualityToggle": true,
Expand All @@ -17,15 +18,23 @@
"dynamic_thresholding": false,
"controlnet_strength": 1,
"legacy": false,
"add_original_image": false,
"add_original_image": true,
"uncond_scale": 1,
"cfg_rescale": 0,
"noise_schedule": "native",
"legacy_v3_extend": false,
"reference_information_extracted": 0.53,
"reference_strength": 0.53,
"seed": 1160599050,
"reference_image": "Base64 Data",
"negative_prompt": "nsfw, lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]"
"negative_prompt": "nsfw, lowres, {bad}, error, fewer, extra, missing, worst quality, jpeg artifacts, bad quality, watermark, unfinished, displeasing, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]",
"reference_image_multiple": [
"Base64 Data",
"Base64 Data"
],
"reference_information_extracted_multiple": [
0.89,
0.9
],
"reference_strength_multiple": [
0.6,
0.6
]
}
}
Loading

0 comments on commit 037790a

Please sign in to comment.