Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/t UI 374 download model functionality #406

Merged
merged 6 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/app/MlHub/Models/ModelDetails.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@
border-bottom: 1px solid black;
margin-bottom: 8px;
}

.download-links {
flex-grow: 1;
display: flex;
flex-direction: column;
padding-bottom: 5px;
}

.download-url-button {
height: 40px;
}
62 changes: 56 additions & 6 deletions src/app/MlHub/Models/ModelDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { useState } from 'react';
import React, { Key, useState } from 'react';
import { Models } from '@tapis/tapis-typescript';
NotChristianGarcia marked this conversation as resolved.
Show resolved Hide resolved
import { MLHub as Hooks } from '@tapis/tapisui-hooks';
import { QueryWrapper } from '@tapis/tapisui-common';
import { Button } from 'reactstrap';
import styles from './ModelDetails.module.scss';
import { Icon, JSONDisplay, GenericModal } from '@tapis/tapisui-common';
import { useDownloadLinks } from '@tapis/tapisui-hooks/dist/ml-hub/models/index';
import { string } from 'prop-types';
import InferenceServerInfo from './InferenceServerInfo';

type ModelDetailsProps = {
Expand Down Expand Up @@ -92,16 +94,41 @@ const Buttons: React.FC<{ modelId: string }> = ({ modelId }) => {
const [currentModal, setCurrentModal] = useState<string | undefined>(
undefined
);
const { data } = Hooks.Models.useDetails({ modelId });
const { data, error, isLoading } = Hooks.Models.useDetails({ modelId });
const modelCardDetails: Models.ModelFullInfo = data?.result ?? {};
const modelRepositoryInfo: Array<string> =
modelCardDetails.repository_content || [];
const {
data: downloadLinkData,
error: downloadLinkError,
isLoading: downloadLinkIsLoading,
} = Hooks.Models.useDownloadLinks({ modelId });
const downloadLinkInfo: Models.ModelDownloadInfo =
downloadLinkData?.result ?? {};
const downloadOnClick = (url: string, filename: string) => {
fetch(url).then((response) => {
response.blob().then((blob) => {
const fileURL = window.URL.createObjectURL(blob);
let alink = document.createElement('a');
alink.href = fileURL;
alink.download = filename;
document.body.appendChild(alink);
alink.click();
document.body.removeChild(alink);

window.URL.revokeObjectURL(fileURL);
});
});
};

return (
<div className={`${styles['buttons-container']}`}>
<Button
onClick={() => {
setCurrentModal('inferenceinfo');
}}
>
{'Inference Service Info'}
{'Inference Service Info '}
<span>
<Icon name="push-right" />
</span>
Expand All @@ -111,7 +138,7 @@ const Buttons: React.FC<{ modelId: string }> = ({ modelId }) => {
setCurrentModal('downloadmodel');
}}
>
{'Download Model'}
{'Download Model '}
<span>
<Icon name="push-right" />
</span>
Expand All @@ -121,7 +148,7 @@ const Buttons: React.FC<{ modelId: string }> = ({ modelId }) => {
setCurrentModal('modelcard');
}}
>
{'Model Card'}
{'Model Card '}
<span>
<Icon name="push-right" />
</span>
Expand Down Expand Up @@ -159,11 +186,34 @@ const Buttons: React.FC<{ modelId: string }> = ({ modelId }) => {
)}
{currentModal === 'downloadmodel' && (
<GenericModal
size="lg"
toggle={() => {
setCurrentModal(undefined);
}}
title="Download Model"
body={<div>"DOWNLOAD ME"</div>}
body={
<div className={`${styles['download-body']}`}>
{downloadLinkInfo?.download_links &&
Object.entries(downloadLinkInfo.download_links).map(
([filename, url]) => {
return (
<div className={`${styles['download-links']}`}>
<div>{filename}:</div>
<div></div>
<div className={`${styles['download-url-button']}`}>
<Button
onClick={() => downloadOnClick(url, filename)}
>
{' '}
Download{' '}
</Button>
</div>
</div>
);
}
)}
</div>
}
/>
)}
</div>
Expand Down
Loading