-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from goodguysarvagya/main
Redesigned the model component.
- Loading branch information
Showing
19 changed files
with
463 additions
and
431 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,72 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import * as DOMPurify from "dompurify"; | ||
import { ArrowBigDownDash } from "lucide-react"; | ||
import { | ||
Select, | ||
SelectContent, | ||
SelectGroup, | ||
SelectItem, | ||
SelectLabel, | ||
SelectTrigger, | ||
SelectValue, | ||
} from "./ui/select"; | ||
|
||
const getModels = async () => { | ||
const response = await fetch("https://gpt4all.io/models/models2.json"); | ||
const jsonData = await response.json(); | ||
return jsonData; | ||
} | ||
const response = await fetch("https://gpt4all.io/models/models2.json"); | ||
//const response = await fetch( | ||
//"https://raw.githubusercontent.com/nomic-ai/gpt4all/main/gpt4all-chat/metadata/models.json" | ||
//); | ||
const jsonData = await response.json(); | ||
return jsonData; | ||
}; | ||
|
||
const ModelsTable = () => | ||
{ | ||
const [models, setModels] = useState([]); | ||
const [selectedModel, setSelectedModel] = useState({}); | ||
const ModelsTable = () => { | ||
const [models, setModels] = useState([]); | ||
|
||
// TODO: handle errors | ||
useEffect(() => { | ||
async function fetchData() { | ||
const modelData = await getModels(); | ||
setModels(modelData); | ||
setSelectedModel(modelData[0]); | ||
} | ||
fetchData(); | ||
}, []); | ||
|
||
const onSelect = (val) => { | ||
models.forEach((obj,idx) => { | ||
|
||
if(obj.filename === val) { | ||
setSelectedModel(models[idx]); | ||
} | ||
}); | ||
useEffect(() => { | ||
async function fetchData() { | ||
const modelData = await getModels(); | ||
setModels(modelData); | ||
} | ||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<div className="flex flex-col justify-center gap-4 mx-auto"> | ||
<h2 className="text-4xl font-bold text-center mb-2">Model Explorer</h2> | ||
<Select onValueChange={onSelect}> | ||
<SelectTrigger className="w-[300px] sm:w-[400px] mx-auto"> | ||
<SelectValue placeholder={models[0] && models[0].filename}/> | ||
</SelectTrigger> | ||
<SelectContent> | ||
<SelectGroup> | ||
<SelectLabel>Model Explorer</SelectLabel> | ||
{ | ||
models.map((obj, idx) => | ||
<SelectItem value={obj.filename} key={idx}>{obj.filename}</SelectItem> | ||
) | ||
} | ||
</SelectGroup> | ||
</SelectContent> | ||
</Select> | ||
|
||
<div className="w-[600px] sm:w-[800px] py-4 border-t border-b border-dashed flex justify-center relative"> | ||
<div className="absolute top-0 left-0 w-[600px] border-l border-r border-dashed translate-x-24 -translate-y-4 h-72"></div> | ||
<div className="w-[350px] sm:w-[400px] min-h-64 sm:min-h-56 relative p-4 rounded-md border shadow-md"> | ||
<div className="w-full h-full rounded-md bg-white p-4 flex flex-col relative"> | ||
<div className="border-b pb-2 mb-2"> | ||
<h4 className="text-xl font-bold">{selectedModel.filename}</h4> | ||
</div> | ||
return ( | ||
<div className="flex flex-col justify-center gap-4 mx-auto"> | ||
<div className="flex justify-end mt-4"></div> | ||
<h2 className="text-4xl font-bold text-center mb-2">Model Explorer</h2> | ||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3"> | ||
{models.map((model, idx) => ( | ||
<div | ||
key={idx} | ||
className="rounded-xl bg-white dark:bg-gray-800 p-4 border dark:border-gray-600 shadow-md flex flex-col justify-between hover:shadow-xl" | ||
> | ||
<div className="mt-0"> | ||
<span className="inline-block bg-red-300 rounded-sm px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2"> | ||
SIZE: {(model.filesize / 1024 ** 3).toFixed(2)} GB | ||
</span> | ||
<span className="inline-block bg-blue-300 rounded-sm px-3 py-1 text-sm font-semibold text-gray-700 mr-2 mb-2"> | ||
RAM: {model.ramrequired} GB | ||
</span> | ||
</div> | ||
<div> | ||
<h4 className="text-xl font-bold mb-2">{model.filename}</h4> | ||
<div | ||
dangerouslySetInnerHTML={{ | ||
__html: DOMPurify.sanitize(model.description), | ||
}} | ||
className="text-gray-600 mb-2" | ||
/> | ||
</div> | ||
|
||
<div dangerouslySetInnerHTML={ | ||
{ | ||
__html: DOMPurify.sanitize(selectedModel.description) | ||
} | ||
}/> | ||
|
||
<a className="place-self-end" href={'url' in selectedModel ? `${selectedModel.url}` : `https://gpt4all.io/models/${selectedModel.filename}`}> | ||
<ArrowBigDownDash className="w-6 h-6"/> | ||
</a> | ||
|
||
</div> | ||
</div> | ||
<div className="mt-3"> | ||
<a | ||
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 mr-2 mb-2" | ||
href={ | ||
"url" in model | ||
? `${model.url}` | ||
: `https://gpt4all.io/models/${model.filename}` | ||
} | ||
> | ||
Download <ArrowBigDownDash className="w-4 h-6 inline" /> | ||
</a> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ModelsTable; | ||
export default ModelsTable; |