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() config = self.get_system_config()
socketio.emit('systemConfig', 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') @socketio.on('requestLatestImages')
def handle_request_latest_images(latest_mtime): def handle_request_latest_images(latest_mtime):
try: try:
@ -482,12 +491,14 @@ class InvokeAIWebServer:
# App Functions # App Functions
def get_system_config(self): def get_system_config(self):
model_list = self.generate.model_cache.list_models()
return { return {
'model': 'stable diffusion', 'model': 'stable diffusion',
'model_id': args.model, 'model_id': args.model,
'model_hash': self.generate.model_hash, 'model_hash': self.generate.model_hash,
'app_id': APP_ID, 'app_id': APP_ID,
'app_version': APP_VERSION, 'app_version': APP_VERSION,
'available_models': model_list
} }
def generate_images( 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" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>InvokeAI - A Stable Diffusion Toolkit</title> <title>InvokeAI - A Stable Diffusion Toolkit</title>
<link rel="shortcut icon" type="icon" href="./assets/favicon.0d253ced.ico" /> <link rel="shortcut icon" type="icon" href="./assets/favicon.0d253ced.ico" />
<script type="module" crossorigin src="./assets/index.46fb89d7.js"></script> <script type="module" crossorigin src="./assets/index.647e65c7.js"></script>
<link rel="stylesheet" href="./assets/index.fccfd8c3.css"> <link rel="stylesheet" href="./assets/index.549d985b.css">
</head> </head>
<body> <body>

View File

@ -142,8 +142,16 @@ export declare type SystemConfig = {
model_hash: string; model_hash: string;
app_id: string; app_id: string;
app_version: 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. * 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>( export const requestSystemConfig = createAction<undefined>(
'socketio/requestSystemConfig' 'socketio/requestSystemConfig'
); );
export const setModel = createAction<string>('socketio/setModel');

View File

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

View File

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

View File

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

View File

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