basic abc frontend support

This commit is contained in:
josc146 2024-01-05 12:45:41 +08:00
parent 16079a3cba
commit 8d84b326b8
3 changed files with 25 additions and 3 deletions

View File

@ -19,6 +19,7 @@ import { useNavigate } from 'react-router';
import { WindowShow } from '../../wailsjs/runtime'; import { WindowShow } from '../../wailsjs/runtime';
import { convertToGGML, convertToSt } from '../utils/convert-model'; import { convertToGGML, convertToSt } from '../utils/convert-model';
import { Precision } from '../types/configs'; import { Precision } from '../types/configs';
import { defaultCompositionABCPrompt, defaultCompositionPrompt } from '../pages/defaultConfigs';
const mainButtonText = { const mainButtonText = {
[ModelStatus.Offline]: 'Run', [ModelStatus.Offline]: 'Run',
@ -257,6 +258,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
commonStore.setStatus({ status: ModelStatus.Working }); commonStore.setStatus({ status: ModelStatus.Working });
let buttonNameMap = { let buttonNameMap = {
'novel': 'Completion', 'novel': 'Completion',
'abc': 'Composition',
'midi': 'Composition' 'midi': 'Composition'
}; };
let buttonName = 'Chat'; let buttonName = 'Chat';
@ -264,6 +266,13 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
const buttonFn = () => { const buttonFn = () => {
navigate({ pathname: '/' + buttonName.toLowerCase() }); navigate({ pathname: '/' + buttonName.toLowerCase() });
}; };
if (modelName.toLowerCase().includes('abc') && commonStore.compositionParams.prompt === defaultCompositionPrompt) {
commonStore.setCompositionParams({
...commonStore.compositionParams,
prompt: defaultCompositionABCPrompt
});
commonStore.setCompositionSubmittedPrompt(defaultCompositionABCPrompt);
}
if (modelConfig.modelParameters.device.startsWith('CUDA') && if (modelConfig.modelParameters.device.startsWith('CUDA') &&
modelConfig.modelParameters.storedLayers < modelConfig.modelParameters.maxStoredLayers && modelConfig.modelParameters.storedLayers < modelConfig.modelParameters.maxStoredLayers &&

View File

@ -15,7 +15,7 @@ import { ArrowSync20Regular, Save28Regular } from '@fluentui/react-icons';
import { PlayerElement, VisualizerElement } from 'html-midi-player'; import { PlayerElement, VisualizerElement } from 'html-midi-player';
import * as mm from '@magenta/music/esm/core.js'; import * as mm from '@magenta/music/esm/core.js';
import { NoteSequence } from '@magenta/music/esm/protobuf.js'; import { NoteSequence } from '@magenta/music/esm/protobuf.js';
import { defaultCompositionPrompt } from './defaultConfigs'; import { defaultCompositionABCPrompt, defaultCompositionPrompt } from './defaultConfigs';
import { import {
CloseMidiPort, CloseMidiPort,
FileExists, FileExists,
@ -370,11 +370,13 @@ const CompositionPanel: FC = observer(() => {
<DialogButton className="grow" text={t('Reset')} title={t('Reset')} <DialogButton className="grow" text={t('Reset')} title={t('Reset')}
contentText={t('Are you sure you want to reset this page? It cannot be undone.')} contentText={t('Are you sure you want to reset this page? It cannot be undone.')}
onConfirm={() => { onConfirm={() => {
commonStore.setCompositionSubmittedPrompt(defaultCompositionPrompt); const isABC = commonStore.getCurrentModelConfig().modelParameters.modelName.toLowerCase().includes('abc');
const defaultPrompt = isABC ? defaultCompositionABCPrompt : defaultCompositionPrompt;
commonStore.setCompositionSubmittedPrompt(defaultPrompt);
setParams({ setParams({
generationStartTime: 0 generationStartTime: 0
}); });
setPrompt(defaultCompositionPrompt); setPrompt(defaultPrompt);
}} /> }} />
<Button className="grow" appearance="primary" onClick={() => { <Button className="grow" appearance="primary" onClick={() => {
if (commonStore.compositionGenerating) { if (commonStore.compositionGenerating) {

View File

@ -2,6 +2,17 @@ import { CompletionPreset } from '../types/completion';
import { ModelConfig } from '../types/configs'; import { ModelConfig } from '../types/configs';
export const defaultCompositionPrompt = '<pad>'; export const defaultCompositionPrompt = '<pad>';
export const defaultCompositionABCPrompt='S:3\n' +
'B:9\n' +
'E:4\n' +
'B:9\n' +
'E:4\n' +
'E:4\n' +
'B:9\n' +
'L:1/8\n' +
'M:3/4\n' +
'K:D\n' +
' Bc |"G" d2 cB"A" A2 FE |"Bm" F2 B4 F^G |'
export const defaultPresets: CompletionPreset[] = [{ export const defaultPresets: CompletionPreset[] = [{
name: 'Writer', name: 'Writer',