Skip to content

Commit

Permalink
Added calculation hub label
Browse files Browse the repository at this point in the history
  • Loading branch information
urmauur committed Jan 10, 2024
1 parent db99a8d commit aca6fee
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions web/screens/ExploreModels/ExploreModelItemHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { useMainViewState } from '@/hooks/useMainViewState'

import { toGibibytes } from '@/utils/converter'

import { totalRamAtom, usedRamAtom } from '@/helpers/atoms/SystemBar.atom'

type Props = {
model: Model
onClick: () => void
Expand All @@ -34,6 +36,8 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {
const { downloadedModels } = useGetDownloadedModels()
const { modelDownloadStateAtom, downloadStates } = useDownloadState()
const { requestCreateNewThread } = useCreateNewThread()
const totalRam = useAtomValue(totalRamAtom)
const usedRam = useAtomValue(usedRamAtom)

const downloadAtom = useMemo(
() => atom((get) => get(modelDownloadStateAtom)[model.id]),
Expand Down Expand Up @@ -79,6 +83,33 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {
downloadButton = <ModalCancelDownload model={model} />
}

const getLabel = (size: number) => {
const minimumRamModel = size * 1.25
const availableRam = totalRam - usedRam

if (minimumRamModel > totalRam) {
return (
<Badge className="rounded-md bg-red-500 text-white">
Not enough RAM
</Badge>
)
}
if (minimumRamModel < availableRam) {
return (
<Badge className="rounded-md bg-green-500 text-white">
Recommended
</Badge>
)
}
if (minimumRamModel < totalRam && minimumRamModel > availableRam) {
return (
<Badge className="rounded-md bg-yellow-500 text-white">
Slow on your device
</Badge>
)
}
}

return (
<div
className="cursor-pointer rounded-t-md bg-background"
Expand All @@ -101,19 +132,8 @@ const ExploreModelItemHeader: React.FC<Props> = ({ model, onClick, open }) => {
<span className="mr-4 font-semibold text-muted-foreground">
{toGibibytes(model.metadata.size)}
</span>
{model.metadata.size && (
<>
<Badge className="rounded-md bg-green-500 text-white">
Recommended
</Badge>
<Badge className="rounded-md bg-yellow-500 text-white">
Slow on your device
</Badge>
<Badge className="rounded-md bg-red-500 text-white">
Not enough RAM
</Badge>
</>
)}
{getLabel(model.metadata.size)}

{downloadButton}
<ChevronDownIcon
className={twMerge(
Expand Down

0 comments on commit aca6fee

Please sign in to comment.