update machine learning
This commit is contained in:
parent
1d544c8c4d
commit
406754195b
2 changed files with 74 additions and 77 deletions
|
@ -3,106 +3,89 @@
|
|||
notificationController,
|
||||
NotificationType,
|
||||
} from '$lib/components/shared-components/notification/notification';
|
||||
import { handleError } from '$lib/utils/handle-error';
|
||||
import { api, SystemConfigDto } from '@api';
|
||||
import { isEqual } from 'lodash-es';
|
||||
import { fade } from 'svelte/transition';
|
||||
import SettingButtonsRow from '../setting-buttons-row.svelte';
|
||||
import SettingInputField, { SettingInputFieldType } from '../setting-input-field.svelte';
|
||||
import SettingSwitch from '../setting-switch.svelte';
|
||||
import type { SystemConfigMachineLearningDto } from '@api';
|
||||
import { createEventDispatcher } from 'svelte';
|
||||
|
||||
export let disabled = false;
|
||||
|
||||
let config: SystemConfigDto;
|
||||
let defaultConfig: SystemConfigDto;
|
||||
export let machineLearningConfig: SystemConfigMachineLearningDto; // this is the config that is being edited
|
||||
export let machineLearningDefault: SystemConfigMachineLearningDto;
|
||||
export let savedConfig: SystemConfigMachineLearningDto;
|
||||
|
||||
async function refreshConfig() {
|
||||
[config, defaultConfig] = await Promise.all([
|
||||
api.systemConfigApi.getConfig().then((res) => res.data),
|
||||
api.systemConfigApi.getDefaults().then((res) => res.data),
|
||||
]);
|
||||
}
|
||||
const dispatch = createEventDispatcher<{
|
||||
save: SystemConfigMachineLearningDto;
|
||||
}>();
|
||||
|
||||
async function reset() {
|
||||
const { data: resetConfig } = await api.systemConfigApi.getConfig();
|
||||
config = resetConfig;
|
||||
machineLearningConfig = { ...savedConfig };
|
||||
notificationController.show({ message: 'Reset to the last saved settings', type: NotificationType.Info });
|
||||
}
|
||||
|
||||
async function saveSetting() {
|
||||
try {
|
||||
const { data: current } = await api.systemConfigApi.getConfig();
|
||||
await api.systemConfigApi.updateConfig({
|
||||
systemConfigDto: { ...current, machineLearning: config.machineLearning },
|
||||
});
|
||||
await refreshConfig();
|
||||
notificationController.show({ message: 'Settings saved', type: NotificationType.Info });
|
||||
} catch (error) {
|
||||
handleError(error, 'Unable to save settings');
|
||||
}
|
||||
}
|
||||
|
||||
async function resetToDefault() {
|
||||
await refreshConfig();
|
||||
const { data: defaults } = await api.systemConfigApi.getDefaults();
|
||||
config = defaults;
|
||||
machineLearningConfig = { ...machineLearningDefault };
|
||||
|
||||
notificationController.show({ message: 'Reset settings to defaults', type: NotificationType.Info });
|
||||
notificationController.show({
|
||||
message: 'Reset storage template to default',
|
||||
type: NotificationType.Info,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="mt-2">
|
||||
{#await refreshConfig() then}
|
||||
<div in:fade={{ duration: 500 }}>
|
||||
<form autocomplete="off" on:submit|preventDefault class="mx-4 flex flex-col gap-4 py-4">
|
||||
<SettingSwitch
|
||||
title="Enabled"
|
||||
subtitle="Use machine learning features"
|
||||
{disabled}
|
||||
bind:checked={config.machineLearning.enabled}
|
||||
/>
|
||||
<div in:fade={{ duration: 500 }}>
|
||||
<form autocomplete="off" on:submit|preventDefault class="mx-4 flex flex-col gap-4 py-4">
|
||||
<SettingSwitch
|
||||
title="Enabled"
|
||||
subtitle="Use machine learning features"
|
||||
{disabled}
|
||||
bind:checked={machineLearningConfig.enabled}
|
||||
/>
|
||||
|
||||
<hr />
|
||||
<hr />
|
||||
|
||||
<SettingInputField
|
||||
inputType={SettingInputFieldType.TEXT}
|
||||
label="URL"
|
||||
desc="URL of machine learning server"
|
||||
bind:value={config.machineLearning.url}
|
||||
required={true}
|
||||
disabled={disabled || !config.machineLearning.enabled}
|
||||
isEdited={!(config.machineLearning.url === config.machineLearning.url)}
|
||||
/>
|
||||
<SettingInputField
|
||||
inputType={SettingInputFieldType.TEXT}
|
||||
label="URL"
|
||||
desc="URL of machine learning server"
|
||||
bind:value={machineLearningConfig.url}
|
||||
required={true}
|
||||
disabled={disabled || !machineLearningConfig.enabled}
|
||||
isEdited={!(machineLearningConfig.url === machineLearningConfig.url)}
|
||||
/>
|
||||
|
||||
<SettingSwitch
|
||||
title="SMART SEARCH"
|
||||
subtitle="Extract CLIP embeddings for smart search"
|
||||
bind:checked={config.machineLearning.clipEncodeEnabled}
|
||||
disabled={disabled || !config.machineLearning.enabled}
|
||||
/>
|
||||
<SettingSwitch
|
||||
title="SMART SEARCH"
|
||||
subtitle="Extract CLIP embeddings for smart search"
|
||||
bind:checked={machineLearningConfig.clipEncodeEnabled}
|
||||
disabled={disabled || !machineLearningConfig.enabled}
|
||||
/>
|
||||
|
||||
<SettingSwitch
|
||||
title="FACIAL RECOGNITION"
|
||||
subtitle="Recognize and group faces in photos"
|
||||
disabled={disabled || !config.machineLearning.enabled}
|
||||
bind:checked={config.machineLearning.facialRecognitionEnabled}
|
||||
/>
|
||||
<SettingSwitch
|
||||
title="FACIAL RECOGNITION"
|
||||
subtitle="Recognize and group faces in photos"
|
||||
disabled={disabled || !machineLearningConfig.enabled}
|
||||
bind:checked={machineLearningConfig.facialRecognitionEnabled}
|
||||
/>
|
||||
|
||||
<SettingSwitch
|
||||
title="IMAGE TAGGING"
|
||||
subtitle="Tag and classify images"
|
||||
disabled={disabled || !config.machineLearning.enabled}
|
||||
bind:checked={config.machineLearning.tagImageEnabled}
|
||||
/>
|
||||
<SettingSwitch
|
||||
title="IMAGE TAGGING"
|
||||
subtitle="Tag and classify images"
|
||||
disabled={disabled || !machineLearningConfig.enabled}
|
||||
bind:checked={machineLearningConfig.tagImageEnabled}
|
||||
/>
|
||||
|
||||
<SettingButtonsRow
|
||||
on:reset={reset}
|
||||
on:save={saveSetting}
|
||||
on:reset-to-default={resetToDefault}
|
||||
showResetToDefault={!isEqual(config, defaultConfig)}
|
||||
{disabled}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
{/await}
|
||||
<SettingButtonsRow
|
||||
on:reset={reset}
|
||||
on:save={() => dispatch('save', machineLearningConfig)}
|
||||
on:reset-to-default={resetToDefault}
|
||||
showResetToDefault={!isEqual(machineLearningConfig, machineLearningDefault)}
|
||||
{disabled}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -154,7 +154,21 @@
|
|||
/>
|
||||
</SettingAccordion>
|
||||
<SettingAccordion title="Machine Learning" subtitle="Manage machine learning settings">
|
||||
<MachineLearningSettings disabled={$featureFlags.configFile} />
|
||||
<MachineLearningSettings
|
||||
bind:savedConfig={currentConfig.machineLearning}
|
||||
bind:machineLearningConfig={config.machineLearning}
|
||||
machineLearningDefault={defaultConfig.machineLearning}
|
||||
disabled={$featureFlags.configFile}
|
||||
on:save={({ detail: machineLearning }) => {
|
||||
handleSave(
|
||||
{
|
||||
...currentConfig,
|
||||
machineLearning,
|
||||
},
|
||||
'Machine Learning',
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</SettingAccordion>
|
||||
<SettingAccordion title="OAuth Authentication" subtitle="Manage the login with OAuth settings">
|
||||
<OAuthSettings
|
||||
|
|
Loading…
Add table
Reference in a new issue