File size: 2,030 Bytes
d02c2a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import { CaptionJobConfig } from "@/types";
import { captionerTypes } from "./captionOptions";
export const defaultCaptionJobConfig: CaptionJobConfig = {
job: 'extension',
config: {
name: 'Caption Directory',
process: [
{
type: 'AceStepCaptioner',
sqlite_db_path: './aitk_db.db',
device: 'cuda',
caption: {
model_name_or_path: "ACE-Step/acestep-transcriber",
model_name_or_path2: "ACE-Step/acestep-captioner",
dtype: 'bf16',
quantize: true,
qtype: 'float8',
low_vram: true,
extensions: ['mp3', 'wav', 'flac', 'ogg'],
path_to_caption: '',
recaption: false,
},
},
],
},
};
const repairDefaults = (defaults: { [key: string]: any }) => {
let newDefaults: { [key: string]: any } = {};
// if the key doesnt start with config.process[0]., then add it
for (const key in defaults) {
if (!key.startsWith('config.process[0].')) {
newDefaults[`config.process[0].${key}`] = defaults[key];
} else {
newDefaults[key] = defaults[key];
}
}
return newDefaults;
}
export const handleCaptionerTypeChange = (
currentTypeName: string,
newTypeName: string,
jobConfig: CaptionJobConfig,
setJobConfig: (value: any, key: string) => void,
) => {
const currentType = captionerTypes.find(a => a.name === currentTypeName);
if (!currentType || currentType.name === newTypeName) {
return;
}
// update the defaults when a model is selected
const newType = captionerTypes.find(model => model.name === newTypeName);
let currentDefaults = repairDefaults(currentType.defaults || {});
let newDefaults = repairDefaults(newType?.defaults || {});
// set new model
setJobConfig(newTypeName, 'config.process[0].type');
// revert defaults from previous model
for (const key in currentDefaults) {
setJobConfig(currentDefaults[key][1], key);
}
for (const key in newDefaults) {
setJobConfig(newDefaults[key][0], key);
}
};
|