mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Adds initial model switching UI
This commit is contained in:
parent
d6815f61ee
commit
a5915ccd2c
@ -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(
|
||||
|
527
frontend/dist/assets/index.35e26a9a.js
vendored
527
frontend/dist/assets/index.35e26a9a.js
vendored
File diff suppressed because one or more lines are too long
517
frontend/dist/assets/index.46fb89d7.js
vendored
517
frontend/dist/assets/index.46fb89d7.js
vendored
File diff suppressed because one or more lines are too long
1
frontend/dist/assets/index.549d985b.css
vendored
Normal file
1
frontend/dist/assets/index.549d985b.css
vendored
Normal file
File diff suppressed because one or more lines are too long
517
frontend/dist/assets/index.647e65c7.js
vendored
Normal file
517
frontend/dist/assets/index.647e65c7.js
vendored
Normal file
File diff suppressed because one or more lines are too long
527
frontend/dist/assets/index.ddebc79c.js
vendored
527
frontend/dist/assets/index.ddebc79c.js
vendored
File diff suppressed because one or more lines are too long
1
frontend/dist/assets/index.fccfd8c3.css
vendored
1
frontend/dist/assets/index.fccfd8c3.css
vendored
File diff suppressed because one or more lines are too long
4
frontend/dist/index.html
vendored
4
frontend/dist/index.html
vendored
@ -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>
|
||||
|
8
frontend/src/app/invokeai.d.ts
vendored
8
frontend/src/app/invokeai.d.ts
vendored
@ -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.
|
||||
*/
|
||||
|
@ -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');
|
||||
|
@ -177,6 +177,9 @@ const makeSocketIOEmitters = (
|
||||
emitRequestSystemConfig: () => {
|
||||
socketio.emit('requestSystemConfig');
|
||||
},
|
||||
emitSetModel: (modelName: string) => {
|
||||
socketio.emit('setModel', modelName);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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)"
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user