load settings from automatic1111 png image
parent
23f0d15b92
commit
bed5a10d01
1
index.js
1
index.js
|
|
@ -91,6 +91,7 @@ const {
|
|||
selection_ts,
|
||||
stores,
|
||||
lexica,
|
||||
api_ts,
|
||||
} = require('./typescripts/dist/bundle')
|
||||
|
||||
const io = require('./utility/io')
|
||||
|
|
|
|||
|
|
@ -36,6 +36,6 @@ export * as selection_ts from './util/ts/selection'
|
|||
export * as stores from './stores'
|
||||
|
||||
export { default as lexica } from './lexical/lexical'
|
||||
|
||||
export * as api_ts from './util/ts/api'
|
||||
export { toJS } from 'mobx'
|
||||
export { default as node_fs } from 'fs'
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import ReactDOM from 'react-dom/client'
|
|||
import { observer } from 'mobx-react'
|
||||
import { AStore, toJS } from '../main/astore'
|
||||
import { Grid } from '../util/grid'
|
||||
import { io, settings_tab } from '../util/oldSystem'
|
||||
import { io, python_replacement, settings_tab } from '../util/oldSystem'
|
||||
import { MoveToCanvasSvg, PenSvg } from '../util/elements'
|
||||
import { ErrorBoundary } from '../util/errorBoundary'
|
||||
import Locale from '../locale/locale'
|
||||
|
|
@ -13,6 +13,10 @@ import { Collapsible } from '../util/collapsible'
|
|||
import { storage } from 'uxp'
|
||||
import { _arrayBufferToBase64 } from '../util/ts/io'
|
||||
import { sd_tab_store } from '../stores'
|
||||
import { postPng } from '../util/ts/api'
|
||||
import { setPrompt } from '../multiTextarea'
|
||||
import sd_tab_util from '../sd_tab/util'
|
||||
|
||||
declare let g_ui_settings_object: any
|
||||
export const store = new AStore({
|
||||
images: [] as string[], //full resloution images
|
||||
|
|
@ -180,6 +184,43 @@ function getHistoryMetadata(metadata_json: any) {
|
|||
|
||||
g_ui_settings_object.autoFillInSettings(toJS(metadata_json))
|
||||
}
|
||||
|
||||
interface Auto111Metadata {
|
||||
prompt?: string
|
||||
negative_prompt?: string
|
||||
Steps?: string
|
||||
Sampler?: string
|
||||
'CFG scale'?: string
|
||||
Seed?: string
|
||||
Size?: string
|
||||
'Model hash'?: string
|
||||
Model?: string
|
||||
'Denoising strength'?: string
|
||||
'Mask blur'?: string
|
||||
Version?: string
|
||||
}
|
||||
function ChangeSettingsFromAuto1111Metadata(metadata: Auto111Metadata) {
|
||||
if (metadata?.prompt)
|
||||
setPrompt({
|
||||
positive: metadata.prompt,
|
||||
negative: metadata?.negative_prompt,
|
||||
})
|
||||
|
||||
if (metadata?.Steps) sd_tab_util.store.data.steps = Number(metadata.Steps)
|
||||
|
||||
if (metadata?.Sampler)
|
||||
sd_tab_util.store.data.sampler_name = metadata.Sampler
|
||||
if (metadata?.['CFG scale'])
|
||||
sd_tab_util.store.data.cfg = Number(metadata['CFG scale'])
|
||||
if (metadata?.Seed) sd_tab_util.store.data.seed = metadata.Seed
|
||||
if (metadata?.Size)
|
||||
[sd_tab_util.store.data.width, sd_tab_util.store.data.height] =
|
||||
metadata.Size.split('x').map((dim) => Number(dim))
|
||||
if (metadata?.['Denoising strength'])
|
||||
sd_tab_util.store.data.denoising_strength = Number(
|
||||
metadata['Denoising strength']
|
||||
)
|
||||
}
|
||||
interface CombinedElement {
|
||||
thumbnail: string
|
||||
image: string
|
||||
|
|
@ -392,7 +433,42 @@ class History extends React.Component<{}> {
|
|||
<sp-label slot="label">Image Size:</sp-label>
|
||||
</sp-slider>
|
||||
<div>
|
||||
<button className="btnSquare" id="btnLoadHistory">
|
||||
<button
|
||||
style={{ marginBottom: '3px' }}
|
||||
className="btnSquare"
|
||||
onClick={async () => {
|
||||
try {
|
||||
const response_json = await postPng()
|
||||
if (
|
||||
response_json?.metadata?.parameters
|
||||
) {
|
||||
const auto_metadata =
|
||||
python_replacement.convertMetadataToJson(
|
||||
response_json.metadata
|
||||
.parameters
|
||||
)
|
||||
console.log(
|
||||
'auto_metadata: ',
|
||||
auto_metadata
|
||||
)
|
||||
ChangeSettingsFromAuto1111Metadata(
|
||||
auto_metadata
|
||||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
}
|
||||
}}
|
||||
>
|
||||
Load Metadata from Image
|
||||
</button>
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
className="btnSquare"
|
||||
id="btnLoadHistory"
|
||||
style={{ marginRight: '3px' }}
|
||||
>
|
||||
Load Previous Generations
|
||||
</button>
|
||||
<button
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@ function convertMetadataToJson(metadata_str) {
|
|||
// console.log('sub_settings: ', sub_settings)
|
||||
|
||||
const settings_json = {}
|
||||
settings_json['prompt'] = prompt
|
||||
;[settings_json['prompt'], settings_json['negative_prompt']] =
|
||||
prompt.split('Negative prompt: ')
|
||||
|
||||
for (const setting of sub_settings) {
|
||||
let [key, value] = setting.split(':').map((s) => s.trimLeft())
|
||||
|
|
|
|||
Loading…
Reference in New Issue