clapper / src /components /toolbars /top-menu /lists /MusicGenerationModelList.tsx
jbilcke-hf's picture
jbilcke-hf HF staff
add linter and prettifier
c1f12bf
raw
history blame
2.78 kB
'use client'
import {
MenubarCheckboxItem,
MenubarSub,
MenubarSubContent,
MenubarSubTrigger,
} from '@/components/ui/menubar'
import { TagColor } from '@/components/tags/types'
import { Tag } from '@/components/tags/Tag'
import { ComputeProvider } from '@aitube/clapper-services'
import { availableModelsForMusicGeneration } from '@/components/settings/constants'
import { useSettings } from '@/services/settings'
import { ComputeProviderName } from '@/components/core/providers/ComputeProviderName'
import { ComputeProviderLogo } from '@/components/core/providers/ComputeProviderLogo'
import { cn } from '@/lib/utils'
import { hasNoPublicAPI } from './hasNoPublicAPI'
import { formatProvider } from './formatProvider'
export function MusicGenerationModelList() {
const provider = useSettings((s) => s.musicProvider)
const setProvider = useSettings((s) => s.setMusicProvider)
const model = useSettings((s) => s.musicGenerationModel)
const setModel = useSettings((s) => s.setMusicGenerationModel)
const availableProviders = Object.keys(
availableModelsForMusicGeneration
) as ComputeProvider[]
if (!availableProviders) {
return null
}
return (
<MenubarSub>
<MenubarSubTrigger>
<Tag size="lg" color={TagColor.LIME}>
generate&nbsp;music
</Tag>
<div className={cn(`flex flex-row items-center space-x-2`)}>
<ComputeProviderLogo
provider={provider && model ? provider : undefined}
height={18}
className={cn(`rounded-full`)}
/>
<div>{model || 'None'}</div>
</div>
</MenubarSubTrigger>
<MenubarSubContent>
{availableProviders.map((p) => (
<MenubarSub key={p}>
<MenubarSubTrigger>
<ComputeProviderName>{p}</ComputeProviderName>
</MenubarSubTrigger>
<MenubarSubContent>
{(availableModelsForMusicGeneration[p] || []).map((m) => (
<MenubarCheckboxItem
key={m}
checked={provider === p && model === m}
disabled={hasNoPublicAPI(m)}
onClick={(e) => {
if (hasNoPublicAPI(m)) {
e.stopPropagation()
e.preventDefault()
return false
}
setProvider(p)
setModel(m)
e.stopPropagation()
e.preventDefault()
return false
}}
>
{m}
</MenubarCheckboxItem>
))}
</MenubarSubContent>
</MenubarSub>
))}
</MenubarSubContent>
</MenubarSub>
)
}