Skip to content

Commit

Permalink
add textural inversion menu
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahAlfaraj committed Sep 13, 2023
1 parent df868dd commit 662d2f1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
12 changes: 12 additions & 0 deletions typescripts/sd_tab/sd_tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,18 @@ class SDTab extends React.Component<{}> {
})
}}
></SpMenu>
<SpMenu
title="use textual inversion in your prompt"
style={{ ...styles.spMenu }}
items={helper_store.data.embeddings}
label_item="Select Textual Inversion"
onChange={(id: any, value: any) => {
const prompt = multiPrompts.getPrompt().positive
multiPrompts.setPrompt({
positive: `${prompt} ${value.item}`,
})
}}
></SpMenu>

<sp-checkbox
title="use {keyword} form the prompts library"
Expand Down
14 changes: 14 additions & 0 deletions typescripts/sd_tab/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const helper_store = new AStore({
b_show_sampler: false, //false when off, true when on,
models: [] as any[],
loras: [] as any[],
embeddings: [] as any[],
sampler_list: [] as any[],
hr_upscaler_list: [] as string[],
previous_width: 512,
Expand Down Expand Up @@ -366,6 +367,7 @@ export async function refreshUI() {

await refreshModels()
helper_store.data.loras = await requestLoraModels()
helper_store.data.embeddings = await requestEmbeddings()
await refreshExtraUpscalers()

await setInpaintMaskWeight(1.0) //set the inpaint conditional mask to 1 when the on plugin start
Expand Down Expand Up @@ -433,6 +435,18 @@ export async function requestLoraModels() {
return lora_models
}

export async function requestEmbeddings() {
try {
const full_url = `${g_sd_url}/sdapi/v1/embeddings`
let results = (await requestGet(full_url)) || {}
let embeddings = Object.keys(results?.loaded || {})
return embeddings
} catch (e) {
console.error(e)
return []
}
}

export function getLoraModelPrompt(lora_model_name: string) {
return `<lora:${lora_model_name}:1>`
}
Expand Down
2 changes: 1 addition & 1 deletion typescripts/viewer/viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ const Viewer = observer(() => {
title="expand the Photoshop masking by x pixels"
>
<sp-label slot="label">
{Locale('Expand by')}
{Locale('Expand by')}{' '}
</sp-label>
<sp-label slot="label">
{mask_store.data.expand_by}
Expand Down

0 comments on commit 662d2f1

Please sign in to comment.