Skip to content
Snippets Groups Projects
Commit 60d57951 authored by ali asaria's avatar ali asaria
Browse files

show a->z in model store vs z->a as default

parent ba0aab35
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ import { ...@@ -20,6 +20,7 @@ import {
import { import {
ArrowDownIcon, ArrowDownIcon,
CheckIcon, CheckIcon,
ChevronDownIcon,
CreativeCommonsIcon, CreativeCommonsIcon,
DownloadIcon, DownloadIcon,
ExternalLinkIcon, ExternalLinkIcon,
...@@ -59,10 +60,10 @@ type Order = 'asc' | 'desc'; ...@@ -59,10 +60,10 @@ type Order = 'asc' | 'desc';
function getComparator<Key extends keyof any>( function getComparator<Key extends keyof any>(
order: Order, order: Order,
orderBy: Key orderBy: Key,
): ( ): (
a: { [key in Key]: number | string }, a: { [key in Key]: number | string },
b: { [key in Key]: number | string } b: { [key in Key]: number | string },
) => number { ) => number {
return order === 'desc' return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy) ? (a, b) => descendingComparator(a, b, orderBy)
...@@ -75,7 +76,7 @@ function getComparator<Key extends keyof any>( ...@@ -75,7 +76,7 @@ function getComparator<Key extends keyof any>(
// with exampleArray.slice().sort(exampleComparator) // with exampleArray.slice().sort(exampleComparator)
function stableSort<T>( function stableSort<T>(
array: readonly T[], array: readonly T[],
comparator: (a: T, b: T) => number comparator: (a: T, b: T) => number,
) { ) {
const stabilizedThis = array.map((el, index) => [el, index] as [T, number]); const stabilizedThis = array.map((el, index) => [el, index] as [T, number]);
stabilizedThis.sort((a, b) => { stabilizedThis.sort((a, b) => {
...@@ -97,7 +98,7 @@ function getModelHuggingFaceURL(model) { ...@@ -97,7 +98,7 @@ function getModelHuggingFaceURL(model) {
const fetcher = (url) => fetch(url).then((res) => res.json()); const fetcher = (url) => fetch(url).then((res) => res.json());
export default function ModelStore() { export default function ModelStore() {
const [order, setOrder] = useState<Order>('desc'); const [order, setOrder] = useState<Order>('asc');
// jobId is null if there is no current download in progress, // jobId is null if there is no current download in progress,
// and it is -1 if a download has been initiated but it hasn't started yet // and it is -1 if a download has been initiated but it hasn't started yet
const [jobId, setJobId] = useState(null); const [jobId, setJobId] = useState(null);
...@@ -118,7 +119,7 @@ export default function ModelStore() { ...@@ -118,7 +119,7 @@ export default function ModelStore() {
const { data: modelDownloadProgress } = useSWR( const { data: modelDownloadProgress } = useSWR(
jobId && jobId != '-1' ? chatAPI.Endpoints.Jobs.Get(jobId) : null, jobId && jobId != '-1' ? chatAPI.Endpoints.Jobs.Get(jobId) : null,
fetcher, fetcher,
{ refreshInterval: 2000 } { refreshInterval: 2000 },
); );
// Creating a separate object to get useEffect for download jobs to work // Creating a separate object to get useEffect for download jobs to work
...@@ -128,12 +129,12 @@ export default function ModelStore() { ...@@ -128,12 +129,12 @@ export default function ModelStore() {
// check if we have a Hugging Face access token // check if we have a Hugging Face access token
const { data: hftoken } = useSWR( const { data: hftoken } = useSWR(
chatAPI.Endpoints.Config.Get('HuggingfaceUserAccessToken'), chatAPI.Endpoints.Config.Get('HuggingfaceUserAccessToken'),
fetcher fetcher,
); );
const { data: canLogInToHuggingFace } = useSWR( const { data: canLogInToHuggingFace } = useSWR(
chatAPI.Endpoints.Models.HuggingFaceLogin(), chatAPI.Endpoints.Models.HuggingFaceLogin(),
fetcher fetcher,
); );
// Set isHFAccessTokenSet to true if message in canLogInToHuggingFace is 'OK' // Set isHFAccessTokenSet to true if message in canLogInToHuggingFace is 'OK'
...@@ -224,7 +225,7 @@ export default function ModelStore() { ...@@ -224,7 +225,7 @@ export default function ModelStore() {
flexDirection: 'column', flexDirection: 'column',
overflow: 'hidden', overflow: 'hidden',
}} }}
> >
<Box <Box
sx={{ sx={{
position: 'relative', position: 'relative',
...@@ -336,7 +337,7 @@ export default function ModelStore() { ...@@ -336,7 +337,7 @@ export default function ModelStore() {
component="button" component="button"
onClick={() => setOrder(order === 'asc' ? 'desc' : 'asc')} onClick={() => setOrder(order === 'asc' ? 'desc' : 'asc')}
fontWeight="lg" fontWeight="lg"
endDecorator={<ArrowDownIcon />} endDecorator={<ChevronDownIcon />}
sx={{ sx={{
'& svg': { '& svg': {
transition: '0.2s', transition: '0.2s',
...@@ -360,7 +361,7 @@ export default function ModelStore() { ...@@ -360,7 +361,7 @@ export default function ModelStore() {
{modelGalleryData && {modelGalleryData &&
stableSort( stableSort(
filterByFilters(modelGalleryData, searchText, filters), filterByFilters(modelGalleryData, searchText, filters),
getComparator(order, 'name') getComparator(order, 'name'),
).map((row) => ( ).map((row) => (
<tr key={row.uniqueID}> <tr key={row.uniqueID}>
<td> <td>
...@@ -473,7 +474,7 @@ export default function ModelStore() { ...@@ -473,7 +474,7 @@ export default function ModelStore() {
'To access gated Hugging Face models you must first:\r\r' + 'To access gated Hugging Face models you must first:\r\r' +
'1. Create a READ access token in your Hugging Face account.\r\r' + '1. Create a READ access token in your Hugging Face account.\r\r' +
'2. Enter the token on the Transformer Lab Settings page.\r\r' + '2. Enter the token on the Transformer Lab Settings page.\r\r' +
'Click OK to go to Settings.' 'Click OK to go to Settings.',
); );
if (confirm_result) { if (confirm_result) {
navigate('/settings'); navigate('/settings');
...@@ -492,19 +493,19 @@ export default function ModelStore() { ...@@ -492,19 +493,19 @@ export default function ModelStore() {
setCurrentlyDownloading(row.name); setCurrentlyDownloading(row.name);
try { try {
let response = await fetch( let response = await fetch(
chatAPI.Endpoints.Jobs.Create() chatAPI.Endpoints.Jobs.Create(),
); );
const newJobId = await response.json(); const newJobId = await response.json();
setJobId(newJobId); setJobId(newJobId);
response = await downloadModelFromGallery( response = await downloadModelFromGallery(
row?.uniqueID, row?.uniqueID,
newJobId newJobId,
); );
if (response?.status == 'error') { if (response?.status == 'error') {
setCurrentlyDownloading(null); setCurrentlyDownloading(null);
setJobId(null); setJobId(null);
return alert( return alert(
`Failed to download:\n${response.message}` `Failed to download:\n${response.message}`,
); );
} else if (response?.status == 'unauthorized') { } else if (response?.status == 'unauthorized') {
setCurrentlyDownloading(null); setCurrentlyDownloading(null);
...@@ -514,7 +515,7 @@ export default function ModelStore() { ...@@ -514,7 +515,7 @@ export default function ModelStore() {
window window
.open( .open(
getModelHuggingFaceURL(row), getModelHuggingFaceURL(row),
'_blank' '_blank',
) )
?.focus(); ?.focus();
} }
...@@ -539,7 +540,7 @@ export default function ModelStore() { ...@@ -539,7 +540,7 @@ export default function ModelStore() {
value={clamp( value={clamp(
modelDownloadProgress?.progress, modelDownloadProgress?.progress,
0, 0,
100 100,
)} )}
sx={{ width: '100px' }} sx={{ width: '100px' }}
variant="solid" variant="solid"
...@@ -550,10 +551,10 @@ export default function ModelStore() { ...@@ -550,10 +551,10 @@ export default function ModelStore() {
<> <>
{clamp( {clamp(
Number.parseFloat( Number.parseFloat(
modelDownloadProgress?.progress modelDownloadProgress?.progress,
), ),
0, 0,
100 100,
).toFixed(0)} ).toFixed(0)}
% %
</> </>
...@@ -570,7 +571,7 @@ export default function ModelStore() { ...@@ -570,7 +571,7 @@ export default function ModelStore() {
modelDownloadProgress?.job_data modelDownloadProgress?.job_data
?.downloaded * ?.downloaded *
1024 * 1024 *
1024 1024,
)} )}
{/* {modelDownloadProgress?.job_data} */} {/* {modelDownloadProgress?.job_data} */}
<ArrowDownIcon size="18px" /> <ArrowDownIcon size="18px" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment