-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathmodel-details-properties.tsx
270 lines (254 loc) · 7.86 KB
/
model-details-properties.tsx
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import { useToast } from "@/app/providers/toast-provider";
import { Image } from "@/components/ui/image";
import ToolTip from "@/components/ui/tooltip/tooltip";
import {
useTrainingDetails,
useTrainingStatus,
} from "@/features/models/hooks/use-training";
import { useEffect, useMemo, useState } from "react";
import AccuracyDisplay from "./accuracy-display";
import { Link } from "@/components/ui/link";
import { ExternalLinkIcon } from "@/components/ui/icons";
import { ModelPropertiesSkeleton } from "./skeletons";
import CodeBlock from "@/components/ui/codeblock/codeblock";
import ChevronDownIcon from "@/components/ui/icons/chevron-down";
import { APP_CONTENT, cn } from "@/utils";
import { ENVS } from "@/config/env";
enum TrainingStatus {
FAILED = "FAILED",
IN_PROGRESS = "IN PROGRESS",
}
const LinkDisplay = ({ value, label }: { value: string; label: string }) => {
return (
<Link
href={value as string}
blank
nativeAnchor
className="flex items-center gap-x-3"
title={label}
>
<span className="text-dark font-semibold text-title-3">URL</span>
<ExternalLinkIcon className="w-4 h-4 " />
</Link>
);
};
type PropertyDisplayProps = {
label: string;
value?: string | number | null;
tooltip?: string;
isAccuracy?: boolean;
isTMS?: boolean;
animate?: boolean;
};
const PropertyDisplay: React.FC<PropertyDisplayProps> = ({
label,
value,
tooltip,
isAccuracy,
isTMS,
animate,
}) => (
<div className="row-span-1 col-span-1 flex flex-col gap-y-5">
<span className="text-gray text-body-2 flex items-center gap-x-4 text-nowrap ">
{label}
{tooltip && <ToolTip content={tooltip} />}
</span>
{isAccuracy ? (
<AccuracyDisplay accuracy={typeof value === "number" ? value : 0} />
) : isTMS ? (
<LinkDisplay value={value as string} label={label} />
) : (
<span
className={cn(
`${animate && "animate-pulse"} text-dark font-semibold text-title-3`,
)}
>
{value ?? "N/A"}
</span>
)}
</div>
);
type ModelPropertiesProps = {
trainingId: number;
accuracy?: number;
datasetId?: number;
isTrainingDetailsDialog?: boolean;
};
const ModelProperties: React.FC<ModelPropertiesProps> = ({
trainingId,
datasetId,
isTrainingDetailsDialog = false,
}) => {
const { isPending, data, error, isError } = useTrainingDetails(trainingId);
const { notify } = useToast();
useEffect(() => {
//@ts-expect-error bad type definition
if (isError && error?.response?.data?.detail) {
//@ts-expect-error bad type definition
notify(error.response.data.detail, "danger");
}
}, [isError, error, notify]);
const {
accuracy: trainingAccuracy,
chips_length,
zoom_level,
epochs,
batch_size,
input_contact_spacing,
input_boundary_width,
source_imagery,
} = data || {};
const trainingResultsGraph = `${ENVS.BASE_API_URL}workspace/download/dataset_${datasetId}/output/training_${data?.id}/graphs/training_validation_sparse_categorical_accuracy.png`;
const content = useMemo(() => {
if (isPending) {
return <ModelPropertiesSkeleton isTrainingDetailsDialog />;
}
return (
<div
className={cn(
`grid ${isTrainingDetailsDialog ? "grid-cols-2" : "grid-cols-1 lg:grid-cols-5"} gap-14 items-center `,
)}
>
<div className="col-span-3 grid grid-cols-1 sm:grid-cols-2 grid-rows-4 gap-y-4 md:gap-y-10">
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.zoomLevels.title
}
value={zoom_level?.join(" ") || "N/A"}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.zoomLevels.tooltip
}
/>
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.accuracy.title
}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.accuracy.tooltip
}
value={trainingAccuracy}
isAccuracy
/>
<PropertyDisplay
label={APP_CONTENT.models.modelsDetailsCard.properties.epochs.title}
value={epochs}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.epochs.tooltip
}
/>
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.batchSize.title
}
value={batch_size}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.batchSize.tooltip
}
/>
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.contactSpacing
.title
}
value={input_contact_spacing}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.contactSpacing
.tooltip
}
/>
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.boundaryWidth
.title
}
value={input_boundary_width}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.boundaryWidth
.tooltip
}
/>
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.currentDatasetSize
.title
}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.currentDatasetSize
.tooltip
}
value={chips_length}
/>
{/* Animate the status when it's in progress. */}
{isTrainingDetailsDialog && (
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.trainingInfoDialog.status
}
value={data?.status}
animate={data?.status === TrainingStatus.IN_PROGRESS}
/>
)}
<PropertyDisplay
label={
APP_CONTENT.models.modelsDetailsCard.properties.sourceImage.title
}
tooltip={
APP_CONTENT.models.modelsDetailsCard.properties.sourceImage
.tooltip
}
value={source_imagery}
isTMS
/>
</div>
<div
className={`col-span-3 lg:col-span-2 ${isTrainingDetailsDialog && "lg:col-span-3"}`}
>
<Image src={trainingResultsGraph} alt={""} />
</div>
{/* Show logs only in modal and when status failed */}
{isTrainingDetailsDialog && data?.status === TrainingStatus.FAILED && (
//@ts-expect-error bad type definition
<FailedTrainingTraceBack taskId={data?.task_id} />
)}
</div>
);
}, [
isPending,
trainingAccuracy,
epochs,
zoom_level,
batch_size,
input_contact_spacing,
input_boundary_width,
source_imagery,
trainingResultsGraph,
]);
return isError ? (
<ModelPropertiesSkeleton isTrainingDetailsDialog />
) : (
content
);
};
export default ModelProperties;
const FailedTrainingTraceBack = ({ taskId }: { taskId: string }) => {
const { data, isPending } = useTrainingStatus(taskId);
const [showLogs, setShowLogs] = useState(false);
if (isPending) {
return (
<div className="h-40 col-span-5 w-full animate-pulse bg-light-gray"></div>
);
}
return (
<div className="col-span-5 flex flex-col gap-y-4">
<div
onClick={() => setShowLogs(!showLogs)}
role="button"
className="flex items-center gap-x-2"
>
<p>{APP_CONTENT.models.modelsDetailsCard.trainingInfoDialog.logs}</p>
<ChevronDownIcon className={`icon ${showLogs && "rotate-180"}`} />
</div>
{showLogs && <CodeBlock content={data?.traceback as string} />}
</div>
);
};