Remove folder picker

This commit is contained in:
blessedcoolant 2022-12-28 06:19:23 +13:00
parent 1a65d43569
commit 7cb2fcf8b4
6 changed files with 42 additions and 34 deletions

View File

@ -9,8 +9,6 @@ import io
import base64 import base64
import os import os
import json import json
import tkinter as tk
import sys
from werkzeug.utils import secure_filename from werkzeug.utils import secure_filename
from flask import Flask, redirect, send_from_directory, request, make_response from flask import Flask, redirect, send_from_directory, request, make_response
@ -301,21 +299,8 @@ class InvokeAIWebServer:
socketio.emit("systemConfig", config) socketio.emit("systemConfig", config)
@socketio.on('searchForModels') @socketio.on('searchForModels')
def handle_search_models(): def handle_search_models(search_folder: str):
try: try:
# Using tkinter to get the filepath because JS doesn't allow
root = tk.Tk()
root.title('InvokeAI')
root.withdraw()
root.iconbitmap(default=os.path.join(os.getcwd(), '../backend/logo.ico'))
if root.wm_state() == 'withdrawn':
root.iconify()
root.wm_attributes('-topmost', 1)
root.focus_force()
search_folder = filedialog.askdirectory(parent=root, title='Select Checkpoint Folder')
root.quit()
root.destroy()
if not search_folder: if not search_folder:
socketio.emit( socketio.emit(
"foundModels", "foundModels",

View File

@ -30,9 +30,7 @@ export const requestSystemConfig = createAction<undefined>(
'socketio/requestSystemConfig' 'socketio/requestSystemConfig'
); );
export const searchForModels = createAction<undefined>( export const searchForModels = createAction<string>('socketio/searchForModels');
'socketio/searchForModels'
);
export const addNewModel = createAction<InvokeAI.InvokeModelConfigProps>( export const addNewModel = createAction<InvokeAI.InvokeModelConfigProps>(
'socketio/addNewModel' 'socketio/addNewModel'

View File

@ -159,8 +159,8 @@ const makeSocketIOEmitters = (
emitRequestSystemConfig: () => { emitRequestSystemConfig: () => {
socketio.emit('requestSystemConfig'); socketio.emit('requestSystemConfig');
}, },
emitSearchForModels: () => { emitSearchForModels: (modelFolder: string) => {
socketio.emit('searchForModels'); socketio.emit('searchForModels', modelFolder);
}, },
emitAddNewModel: (modelConfig: InvokeAI.InvokeModelConfigProps) => { emitAddNewModel: (modelConfig: InvokeAI.InvokeModelConfigProps) => {
socketio.emit('addNewModel', modelConfig); socketio.emit('addNewModel', modelConfig);

View File

@ -185,7 +185,7 @@ export const socketioMiddleware = () => {
} }
case 'socketio/searchForModels': { case 'socketio/searchForModels': {
emitSearchForModels(); emitSearchForModels(action.payload);
break; break;
} }

View File

@ -6,6 +6,7 @@ interface IAIInputProps extends InputProps {
label?: string; label?: string;
width?: string | number; width?: string | number;
value?: string; value?: string;
size?: string;
onChange?: (e: ChangeEvent<HTMLInputElement>) => void; onChange?: (e: ChangeEvent<HTMLInputElement>) => void;
} }
@ -16,6 +17,7 @@ export default function IAIInput(props: IAIInputProps) {
isDisabled = false, isDisabled = false,
fontSize = 'sm', fontSize = 'sm',
width, width,
size = 'sm',
isInvalid, isInvalid,
...rest ...rest
} = props; } = props;
@ -39,7 +41,7 @@ export default function IAIInput(props: IAIInputProps) {
{label} {label}
</FormLabel> </FormLabel>
)} )}
<Input {...rest} className="input-entry" size={'sm'} width={width} /> <Input {...rest} className="input-entry" size={size} width={width} />
</FormControl> </FormControl>
); );
} }

View File

@ -5,7 +5,7 @@ import IAIIconButton from 'common/components/IAIIconButton';
import { createSelector } from '@reduxjs/toolkit'; import { createSelector } from '@reduxjs/toolkit';
import { systemSelector } from 'features/system/store/systemSelectors'; import { systemSelector } from 'features/system/store/systemSelectors';
import { Box, Flex, VStack } from '@chakra-ui/react'; import { Box, Flex, FormControl, HStack, VStack } from '@chakra-ui/react';
import { useAppDispatch, useAppSelector } from 'app/storeHooks'; import { useAppDispatch, useAppSelector } from 'app/storeHooks';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
@ -24,6 +24,8 @@ import _ from 'lodash';
import type { RootState } from 'app/store'; import type { RootState } from 'app/store';
import type { ReactNode, ChangeEvent } from 'react'; import type { ReactNode, ChangeEvent } from 'react';
import type { FoundModel } from 'app/invokeai'; import type { FoundModel } from 'app/invokeai';
import IAIInput from 'common/components/IAIInput';
import { Field, Formik } from 'formik';
const existingModelsSelector = createSelector([systemSelector], (system) => { const existingModelsSelector = createSelector([systemSelector], (system) => {
const { model_list } = system; const { model_list } = system;
@ -136,8 +138,8 @@ export default function SearchModels() {
setModelsToAdd([]); setModelsToAdd([]);
}; };
const findModelsHandler = () => { const findModelsHandler = (values: { checkpointFolder: string }) => {
dispatch(searchForModels()); dispatch(searchForModels(values.checkpointFolder));
}; };
const addAllToSelected = () => { const addAllToSelected = () => {
@ -250,15 +252,36 @@ export default function SearchModels() {
/> />
</Flex> </Flex>
) : ( ) : (
<IAIButton <Formik
aria-label={t('modelmanager:findModels')} initialValues={{ checkpointFolder: '' }}
onClick={findModelsHandler} onSubmit={(values) => {
findModelsHandler(values);
}}
> >
<Flex columnGap={'0.5rem'}> {({ handleSubmit }) => (
<MdFindInPage fontSize={20} /> <form onSubmit={handleSubmit}>
{t('modelmanager:selectFolder')} <HStack columnGap="0.5rem">
</Flex> <FormControl isRequired width="max-content">
</IAIButton> <Field
as={IAIInput}
id="checkpointFolder"
name="checkpointFolder"
type="text"
width="lg"
size="md"
label={t('modelmanager:checkpointFolder')}
/>
</FormControl>
<IAIIconButton
icon={<MdFindInPage />}
aria-label={t('modelmanager:findModels')}
tooltip={t('modelmanager:findModels')}
type="submit"
/>
</HStack>
</form>
)}
</Formik>
)} )}
{foundModels && ( {foundModels && (
<Flex flexDirection={'column'} rowGap={'1rem'}> <Flex flexDirection={'column'} rowGap={'1rem'}>