Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 5,564 Bytes
ff8c636 | 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | import { useEffect, useState } from 'react';
import {
Box,
Button,
Dialog,
DialogActions,
DialogContent,
DialogContentText,
DialogTitle,
FormControl,
InputLabel,
MenuItem,
Select,
Typography,
} from '@mui/material';
const HF_PRICING_URL = 'https://huggingface.co/pricing';
interface JobsUpgradeDialogProps {
open: boolean;
mode: 'upgrade' | 'namespace';
message: string;
eligibleNamespaces: string[];
onUpgrade: () => void;
onDecline: () => void;
onClose: () => void;
onContinueWithNamespace: (namespace: string) => void;
}
export default function JobsUpgradeDialog({
open,
mode,
message,
eligibleNamespaces,
onUpgrade,
onDecline,
onClose,
onContinueWithNamespace,
}: JobsUpgradeDialogProps) {
const [selectedNamespace, setSelectedNamespace] = useState('');
useEffect(() => {
if (!open) return;
setSelectedNamespace(eligibleNamespaces[0] || '');
}, [open, eligibleNamespaces]);
return (
<Dialog
open={open}
onClose={onClose}
slotProps={{
backdrop: { sx: { backgroundColor: 'rgba(0,0,0,0.5)', backdropFilter: 'blur(4px)' } },
}}
PaperProps={{
sx: {
bgcolor: 'var(--panel)',
border: '1px solid var(--border)',
borderRadius: 'var(--radius-md)',
boxShadow: 'var(--shadow-1)',
maxWidth: 500,
mx: 2,
},
}}
>
<DialogTitle
sx={{ color: 'var(--text)', fontWeight: 700, fontSize: '1rem', pt: 2.5, pb: 0, px: 3 }}
>
{mode === 'namespace' ? 'Choose the org for this job' : 'Jobs need Pro or a paid org'}
</DialogTitle>
<DialogContent sx={{ px: 3, pt: 1.25, pb: 0 }}>
<DialogContentText
sx={{ color: 'var(--muted-text)', fontSize: '0.85rem', lineHeight: 1.6 }}
>
{message}
</DialogContentText>
{eligibleNamespaces.length > 0 && (
<Box
sx={{
mt: 2,
p: 1.5,
borderRadius: '8px',
bgcolor: 'var(--accent-yellow-weak)',
border: '1px solid var(--border)',
}}
>
<Typography
variant="caption"
sx={{
display: 'block',
fontWeight: 700,
color: 'var(--text)',
fontSize: '0.78rem',
mb: 1,
letterSpacing: '0.02em',
}}
>
Eligible namespaces
</Typography>
{mode === 'namespace' ? (
<FormControl fullWidth size="small">
<InputLabel id="jobs-namespace-label">Organization</InputLabel>
<Select
labelId="jobs-namespace-label"
value={selectedNamespace}
label="Organization"
onChange={(e) => setSelectedNamespace(String(e.target.value))}
>
{eligibleNamespaces.map((namespace) => (
<MenuItem key={namespace} value={namespace}>
{namespace}
</MenuItem>
))}
</Select>
</FormControl>
) : (
<Typography
variant="caption"
sx={{ display: 'block', color: 'var(--muted-text)', fontSize: '0.78rem', lineHeight: 1.55 }}
>
{eligibleNamespaces.join(', ')}
</Typography>
)}
</Box>
)}
<Typography
variant="caption"
sx={{ display: 'block', mt: 2, color: 'var(--muted-text)', fontSize: '0.78rem', lineHeight: 1.55 }}
>
If you decline, the agent will have to find another way forward without `hf_jobs`.
</Typography>
</DialogContent>
<DialogActions sx={{ px: 3, pb: 2.5, pt: 2, gap: 1 }}>
{mode === 'namespace' ? (
<Button
onClick={() => onContinueWithNamespace(selectedNamespace)}
disabled={!selectedNamespace}
variant="contained"
size="small"
sx={{
fontSize: '0.82rem',
px: 2.5,
bgcolor: 'var(--accent-yellow)',
color: '#000',
textTransform: 'none',
fontWeight: 700,
boxShadow: 'none',
'&:hover': { bgcolor: '#FFB340', boxShadow: 'none' },
}}
>
Run under selected org
</Button>
) : (
<Button
component="a"
href={HF_PRICING_URL}
target="_blank"
rel="noopener noreferrer"
onClick={onUpgrade}
variant="contained"
size="small"
sx={{
fontSize: '0.82rem',
px: 2.5,
bgcolor: 'var(--accent-yellow)',
color: '#000',
textTransform: 'none',
fontWeight: 700,
boxShadow: 'none',
'&:hover': { bgcolor: '#FFB340', boxShadow: 'none' },
}}
>
Upgrade to Pro
</Button>
)}
<Button
onClick={onDecline}
size="small"
sx={{
color: 'var(--muted-text)',
fontSize: '0.82rem',
px: 2,
textTransform: 'none',
'&:hover': { bgcolor: 'var(--hover-bg)' },
}}
>
Decline tool call
</Button>
</DialogActions>
</Dialog>
);
}
|