Adds initial model switching UI

This commit is contained in:
psychedelicious 2022-10-28 16:47:15 +11:00
parent d6815f61ee
commit a5915ccd2c
14 changed files with 575 additions and 1578 deletions

View File

@ -166,6 +166,15 @@ class InvokeAIWebServer:
config = self.get_system_config()
socketio.emit('systemConfig', config)
@socketio.on("setModel")
def handle_set_model(model_name: str):
print(f'>> Set model requested: {model_name}')
model = self.generate.set_model(model_name)
if model is None:
socketio.emit("modelChangeFailed", { "model_name": model_name })
else:
socketio.emit("modelChanged", { "model_name": model_name })
@socketio.on('requestLatestImages')
def handle_request_latest_images(latest_mtime):
try:
@ -482,12 +491,14 @@ class InvokeAIWebServer:
# App Functions
def get_system_config(self):
model_list = self.generate.model_cache.list_models()
return {
'model': 'stable diffusion',
'model_id': args.model,
'model_hash': self.generate.model_hash,
'app_id': APP_ID,
'app_version': APP_VERSION,
'available_models': model_list
}
def generate_images(

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

517
frontend/dist/assets/index.647e65c7.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,8 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InvokeAI - A Stable Diffusion Toolkit</title>
<link rel="shortcut icon" type="icon" href="./assets/favicon.0d253ced.ico" />
<script type="module" crossorigin src="./assets/index.46fb89d7.js"></script>
<link rel="stylesheet" href="./assets/index.fccfd8c3.css">
<script type="module" crossorigin src="./assets/index.647e65c7.js"></script>
<link rel="stylesheet" href="./assets/index.549d985b.css">
</head>
<body>

View File

@ -142,8 +142,16 @@ export declare type SystemConfig = {
model_hash: string;
app_id: string;
app_version: string;
available_models?: ModelList;
};
export declare type Model = {
status: 'active' | 'cached' | 'not loaded';
description: string;
};
export declare type ModelList = Record<string, Model>;
/**
* These types type data received from the server via socketio.
*/

View File

@ -30,3 +30,5 @@ export const uploadMaskImage = createAction<File>('socketio/uploadMaskImage');
export const requestSystemConfig = createAction<undefined>(
'socketio/requestSystemConfig'
);
export const setModel = createAction<string>('socketio/setModel');

View File

@ -177,6 +177,9 @@ const makeSocketIOEmitters = (
emitRequestSystemConfig: () => {
socketio.emit('requestSystemConfig');
},
emitSetModel: (modelName: string) => {
socketio.emit('setModel', modelName);
},
};
};

View File

@ -59,6 +59,7 @@ export const socketioMiddleware = () => {
emitUploadInitialImage,
emitUploadMaskImage,
emitRequestSystemConfig,
emitSetModel,
} = makeSocketIOEmitters(store, socketio);
/**
@ -169,6 +170,11 @@ export const socketioMiddleware = () => {
emitRequestSystemConfig();
break;
}
case 'socketio/setModel': {
emitSetModel(action.payload);
break;
}
}
next(action);

View File

@ -13,9 +13,11 @@ import {
useDisclosure,
} from '@chakra-ui/react';
import { createSelector } from '@reduxjs/toolkit';
import { isEqual } from 'lodash';
import { cloneElement, ReactElement } from 'react';
import { RootState, useAppSelector } from '../../../app/store';
import _, { isEqual } from 'lodash';
import { ChangeEvent, cloneElement, ReactElement } from 'react';
import { setModel } from '../../../app/socketio/actions';
import { RootState, useAppDispatch, useAppSelector } from '../../../app/store';
import IAISelect from '../../../common/components/IAISelect';
import { persistor } from '../../../main';
import {
setShouldConfirmOnDelete,
@ -32,11 +34,15 @@ const systemSelector = createSelector(
shouldDisplayInProgress,
shouldConfirmOnDelete,
shouldDisplayGuides,
available_models,
} = system;
return {
shouldDisplayInProgress,
shouldConfirmOnDelete,
shouldDisplayGuides,
models: available_models
? _.map(available_models, (model, key) => key)
: [],
};
},
{
@ -56,6 +62,7 @@ type SettingsModalProps = {
* Secondary post-reset modal is included here.
*/
const SettingsModal = ({ children }: SettingsModalProps) => {
const dispatch = useAppDispatch();
const {
isOpen: isSettingsModalOpen,
onOpen: onSettingsModalOpen,
@ -72,6 +79,7 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
shouldDisplayInProgress,
shouldConfirmOnDelete,
shouldDisplayGuides,
models,
} = useAppSelector(systemSelector);
/**
@ -85,6 +93,10 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
});
};
const handleChangeModel = (e: ChangeEvent<HTMLSelectElement>) => {
dispatch(setModel(e.target.value));
};
return (
<>
{cloneElement(children, {
@ -97,6 +109,11 @@ const SettingsModal = ({ children }: SettingsModalProps) => {
<ModalHeader className="settings-modal-header">Settings</ModalHeader>
<ModalCloseButton />
<ModalBody className="settings-modal-content">
<IAISelect
label="Model"
validValues={models}
onChange={handleChangeModel}
/>
<div className="settings-modal-items">
<SettingsModalItem
settingTitle="Display In-Progress Images (slower)"

View File

@ -35,6 +35,7 @@ export interface SystemState
currentStatusHasSteps: boolean;
shouldDisplayGuides: boolean;
wasErrorSeen: boolean;
available_models?: InvokeAI.ModelList;
}
const initialSystemState = {
@ -140,7 +141,10 @@ export const systemSlice = createSlice({
state.openAccordions = action.payload;
},
setSystemConfig: (state, action: PayloadAction<InvokeAI.SystemConfig>) => {
return { ...state, ...action.payload };
return {
...state,
...action.payload,
};
},
setShouldDisplayGuides: (state, action: PayloadAction<boolean>) => {
state.shouldDisplayGuides = action.payload;