@@ -8,7 +8,7 @@
|
||||
import TextInput from "src/lib/UI/GUI/TextInput.svelte";
|
||||
import SelectInput from "src/lib/UI/GUI/SelectInput.svelte";
|
||||
import OptionInput from "src/lib/UI/GUI/OptionInput.svelte";
|
||||
import CheckInput from "src/lib/UI/GUI/CheckInput.svelte";
|
||||
import SliderInput from "src/lib/UI/GUI/SliderInput.svelte";
|
||||
|
||||
</script>
|
||||
<h2 class="mb-2 text-2xl font-bold mt-2">{language.otherBots}</h2>
|
||||
@@ -67,6 +67,21 @@
|
||||
<span class="text-textcolor">Model</span>
|
||||
<TextInput size="sm" marginBottom placeholder="nai-diffusion-3" bind:value={$DataBase.NAIImgModel}/>
|
||||
|
||||
<span class="text-textcolor">Enable I2I</span>
|
||||
<Check bind:check={$DataBase.NAII2I}/>
|
||||
|
||||
|
||||
{#if $DataBase.NAII2I}
|
||||
|
||||
<span class="text-textcolor">strength</span>
|
||||
<SliderInput min={0} max={0.99} step={0.01} bind:value={$DataBase.NAIImgConfig.strength}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.strength}</span>
|
||||
<span class="text-textcolor">noise</span>
|
||||
<SliderInput min={0} max={0.99} step={0.01} bind:value={$DataBase.NAIImgConfig.noise}/>
|
||||
<span class="text-textcolor2 mb-6 text-sm">{$DataBase.NAIImgConfig.noise}</span>
|
||||
|
||||
{/if}
|
||||
|
||||
<span class="text-textcolor">Width</span>
|
||||
<NumberInput size="sm" marginBottom min={0} max={2048} bind:value={$DataBase.NAIImgConfig.width}/>
|
||||
<span class="text-textcolor">Height</span>
|
||||
|
||||
9
src/ts/process/generateSeed.ts
Normal file
9
src/ts/process/generateSeed.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function generateRandomSeed(length) {
|
||||
let result = '';
|
||||
const characters = '0123456789';
|
||||
const charactersLength = characters.length;
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
15
src/ts/process/processzip.ts
Normal file
15
src/ts/process/processzip.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import JSZip from "jszip";
|
||||
|
||||
export async function processZip(dataArray: Uint8Array): Promise<string> {
|
||||
const blob = new Blob([dataArray], { type: "application/zip" });
|
||||
const zip = new JSZip();
|
||||
const zipData = await zip.loadAsync(blob);
|
||||
|
||||
const imageFile = Object.keys(zipData.files).find(fileName => /\.(jpg|jpeg|png)$/.test(fileName));
|
||||
if (imageFile) {
|
||||
const imageData = await zipData.files[imageFile].async("base64");
|
||||
return `data:image/png;base64,${imageData}`;
|
||||
} else {
|
||||
throw new Error("No image found in ZIP file");
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,13 @@ import { get } from "svelte/store"
|
||||
import { DataBase, type character } from "../storage/database"
|
||||
import { requestChatData } from "./request"
|
||||
import { alertError } from "../alert"
|
||||
import { globalFetch } from "../storage/globalApi"
|
||||
import { globalFetch, readImage } from "../storage/globalApi"
|
||||
import { CharEmotion } from "../stores"
|
||||
import type { OpenAIChat } from "."
|
||||
|
||||
|
||||
import { processZip } from "./processzip"
|
||||
import { convertToBase64 } from "./uinttobase64"
|
||||
import type { List } from "lodash"
|
||||
import { generateRandomSeed } from "./generateSeed"
|
||||
export async function stableDiff(currentChar:character,prompt:string){
|
||||
const mainPrompt = "assistant is a chat analyzer.\nuser will input a data of situation with key and values before chat, and a chat of a user and character.\nView the status of the chat and change the data.\nif data's key starts with $, it must change it every time.\nif data value is none, it must change it."
|
||||
let db = get(DataBase)
|
||||
@@ -175,39 +177,80 @@ export async function stableDiff(currentChar:character,prompt:string){
|
||||
}
|
||||
|
||||
|
||||
const uri = new URL(db.NAIImgUrl)
|
||||
uri.pathname = '/ai/generate-image'
|
||||
const reqlist = {
|
||||
body: {
|
||||
"input": prompts.join(','),
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"width": db.NAIImgConfig.width,
|
||||
"height": db.NAIImgConfig.height,
|
||||
"sampler": db.NAIImgConfig.sampler,
|
||||
"steps": db.NAIImgConfig.steps,
|
||||
"scale": db.NAIImgConfig.scale,
|
||||
"negative_prompt": neg,
|
||||
"sm": db.NAIImgConfig.sm,
|
||||
"sm_dyn": db.NAIImgConfig.sm_dyn
|
||||
const charimg = currentChar.image; // Uint8Array 형태의 이미지 데이터
|
||||
console.log("charimg:" + charimg);
|
||||
|
||||
const img = await readImage(charimg)
|
||||
console.log("img:" + img);
|
||||
const base64 = await convertToBase64(img);
|
||||
const base64img = base64.split('base64,')[1];
|
||||
|
||||
console.log("base64img:" + base64img);
|
||||
let reqlist= {}
|
||||
|
||||
if(db.NAII2I){
|
||||
let randomseed = generateRandomSeed(10);
|
||||
let seed = parseInt(randomseed, 10);
|
||||
reqlist = {
|
||||
body: {
|
||||
"action": "img2img",
|
||||
"input": prompts.join(','),
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"seed": seed,
|
||||
"extra_noise_seed": seed,
|
||||
"add_original_image": false,
|
||||
"cfg_rescale": 0,
|
||||
"controlnet_strength": 1,
|
||||
"dynamic_threshold": false,
|
||||
"n_samples": 1,
|
||||
"width": db.NAIImgConfig.width,
|
||||
"height": db.NAIImgConfig.height,
|
||||
"sampler": db.NAIImgConfig.sampler,
|
||||
"steps": db.NAIImgConfig.steps,
|
||||
"scale": db.NAIImgConfig.scale,
|
||||
"negative_prompt": neg,
|
||||
"sm": false,
|
||||
"sm_dyn": false,
|
||||
"noise": db.NAIImgConfig.noise,
|
||||
"noise_schedule": "native",
|
||||
"strength": db.NAIImgConfig.strength,
|
||||
"image": base64img,
|
||||
"ucPreset": 2,
|
||||
"uncond_scale": 1
|
||||
}
|
||||
},
|
||||
headers:{
|
||||
"Authorization": "Bearer " + db.NAIApiKey
|
||||
}
|
||||
}
|
||||
}else{
|
||||
reqlist = {
|
||||
body: {
|
||||
"input": prompts.join(','),
|
||||
"model": db.NAIImgModel,
|
||||
"parameters": {
|
||||
"width": db.NAIImgConfig.width,
|
||||
"height": db.NAIImgConfig.height,
|
||||
"sampler": db.NAIImgConfig.sampler,
|
||||
"steps": db.NAIImgConfig.steps,
|
||||
"scale": db.NAIImgConfig.scale,
|
||||
"negative_prompt": neg,
|
||||
"sm": db.NAIImgConfig.sm,
|
||||
"sm_dyn": db.NAIImgConfig.sm_dyn
|
||||
}
|
||||
},
|
||||
headers:{
|
||||
"Authorization": "Bearer " + db.NAIApiKey
|
||||
}
|
||||
},
|
||||
headers:{
|
||||
'Authorization:': 'Bearer ' + db.NAIApiKey,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
|
||||
console.log(uri)
|
||||
console.log(reqlist)
|
||||
try {
|
||||
const da = await globalFetch(uri.toString(), reqlist)
|
||||
const da = await globalFetch(db.NAIImgUrl, reqlist)
|
||||
|
||||
console.log(da)
|
||||
if(da.ok){
|
||||
if(da){
|
||||
let charemotions = get(CharEmotion)
|
||||
const img = `data:image/png;base64,${da.data.images[0]}`
|
||||
console.log(img)
|
||||
const img = await processZip(da.data);
|
||||
const emos:[string, string,number][] = [[img, img, Date.now()]]
|
||||
charemotions[currentChar.chaId] = emos
|
||||
CharEmotion.set(charemotions)
|
||||
|
||||
17
src/ts/process/uinttobase64.ts
Normal file
17
src/ts/process/uinttobase64.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export async function convertToBase64(data: Uint8Array): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const blob = new Blob([data]);
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onloadend = function() {
|
||||
const base64String = reader.result as string;
|
||||
resolve(base64String);
|
||||
};
|
||||
|
||||
reader.onerror = function(error) {
|
||||
reject(error);
|
||||
};
|
||||
|
||||
reader.readAsDataURL(blob);
|
||||
});
|
||||
}
|
||||
@@ -175,7 +175,7 @@ export function setDatabase(data:Database){
|
||||
data.sdCFG = 7
|
||||
}
|
||||
if(checkNullish(data.NAIImgUrl)){
|
||||
data.NAIImgUrl = 'https://api.novelai.net'
|
||||
data.NAIImgUrl = 'https://api.novelai.net/ai/generate-image'
|
||||
}
|
||||
if(checkNullish(data.NAIApiKey)){
|
||||
data.NAIApiKey = ''
|
||||
@@ -183,6 +183,9 @@ export function setDatabase(data:Database){
|
||||
if(checkNullish(data.NAIImgModel)){
|
||||
data.NAIImgModel = 'nai-diffusion-3'
|
||||
}
|
||||
if(checkNullish(data.NAII2I)){
|
||||
data.NAII2I = true
|
||||
}
|
||||
if(checkNullish(data.textTheme)){
|
||||
data.textTheme = "standard"
|
||||
}
|
||||
@@ -248,7 +251,9 @@ export function setDatabase(data:Database){
|
||||
steps:28,
|
||||
scale:5,
|
||||
sm:true,
|
||||
sm_dyn:true
|
||||
sm_dyn:true,
|
||||
noise:0.0,
|
||||
strength:0.3
|
||||
}
|
||||
}
|
||||
if(checkNullish(data.customTextTheme)){
|
||||
@@ -417,6 +422,7 @@ export interface Database{
|
||||
NAIImgUrl:string
|
||||
NAIApiKey:string
|
||||
NAIImgModel:string
|
||||
NAII2I:boolean
|
||||
NAIImgConfig:NAIImgConfig
|
||||
runpodKey:string
|
||||
promptPreprocess:boolean
|
||||
@@ -748,7 +754,9 @@ interface NAIImgConfig{
|
||||
steps:number,
|
||||
scale:number,
|
||||
sm:boolean,
|
||||
sm_dyn:boolean
|
||||
sm_dyn:boolean,
|
||||
noise:number,
|
||||
strength:number
|
||||
}
|
||||
export type FormatingOrderItem = 'main'|'jailbreak'|'chats'|'lorebook'|'globalNote'|'authorNote'|'lastChat'|'description'|'postEverything'|'personaPrompt'
|
||||
|
||||
|
||||
@@ -661,7 +661,7 @@ export async function globalFetch(url:string, arg:{
|
||||
method: method,
|
||||
signal: arg.abortSignal
|
||||
})
|
||||
|
||||
|
||||
addFetchLog("Uint8Array Response", da.ok && da.status >= 200 && da.status < 300)
|
||||
return {
|
||||
ok: da.ok && da.status >= 200 && da.status < 300,
|
||||
@@ -685,6 +685,16 @@ export async function globalFetch(url:string, arg:{
|
||||
headers: headers,
|
||||
method: method
|
||||
})
|
||||
if(da.headers.get('content-type')?.includes('application/x-zip-compressed')){
|
||||
const daText = await da.blob()
|
||||
|
||||
addFetchLog(daText, da.ok && da.status >= 200 && da.status < 300)
|
||||
return {
|
||||
ok: da.ok && da.status >= 200 && da.status < 300,
|
||||
data: daText,
|
||||
headers: Object.fromEntries(da.headers)
|
||||
}
|
||||
}
|
||||
const daText = await da.text()
|
||||
try {
|
||||
const dat = JSON.parse(daText)
|
||||
|
||||
Reference in New Issue
Block a user