File size: 2,044 Bytes
0573fbf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React, { useState } from 'react';
import { Button, Box, Link, Typography } from '@mui/material';
import { CloudDownload as CloudDownloadIcon } from 'lucide-react';
import api from '../api';
import { modelUnwrapButtonStyles } from '../theme';

export default function ModelUnwrapButton({ model, onUnwrap, onRefresh }) {
    const [loading, setLoading] = useState(false);
    const [result, setResult] = useState(null);
    const [error, setError] = useState(null);

    const handleUnwrap = async () => {
        setLoading(true);
        setResult(null);
        setError(null);

        try {
            const response = await api.post('/api/unwrap-model', {
                model_config: model.configPath,
                ckpt_path: model.ckptPath,
                name: model.name + '_unwrapped'
            });
            setResult(response.data);
            if (onUnwrap) onUnwrap(response.data);
            if (onRefresh) onRefresh();
        } catch (err) {
            console.error('Unwrap error:', err);
            setError(err.response?.data?.error || err.message);
        } finally {
            setLoading(false);
        }
    };

    return (
        <Box sx={modelUnwrapButtonStyles.root}>
            <Button
                variant="outlined"
                color="primary"
                size="small"
                startIcon={<CloudDownloadIcon />}
                onClick={handleUnwrap}
                disabled={loading}
            >
                {loading ? 'Unwrapping...' : 'Unwrap for Inference'}
            </Button>
            {result && result.unwrapped_path && (
                <Box sx={modelUnwrapButtonStyles.result}>
                    <Link href={`file://${result.unwrapped_path}`} target="_blank" rel="noopener noreferrer">
                        Download Unwrapped Model
                    </Link>
                </Box>
            )}
            {error && (
                <Typography sx={modelUnwrapButtonStyles.error}>{error}</Typography>
            )}
        </Box>
    );
}