Spaces:
Sleeping
Sleeping
Download frontend/src/components/RunStatus.tsx from ilyaRozhkovA/LAMPSUI: direct link, hf CLI and curl.
- Browser
- Download file 3.75 kB
-
https://huggingface.co/spaces/ilyaRozhkovA/LAMPSUI/resolve/main/frontend/src/components/RunStatus.tsx
- Command line
-
hf download hf://spaces/ilyaRozhkovA/LAMPSUI/frontend/src/components/RunStatus.tsx
-
curl -L -o RunStatus.tsx https://huggingface.co/spaces/ilyaRozhkovA/LAMPSUI/resolve/main/frontend/src/components/RunStatus.tsx
3.75 kB
| import { Stack, Title, Text, Badge, Group, RingProgress, Code } from "@mantine/core"; | |
| import { RunInfo } from "../api"; | |
| interface Props { | |
| run: RunInfo | null; | |
| totalSteps: number | null; | |
| /** Last log lines, used to surface error context when status is failed/cancelled. */ | |
| logLines?: string[]; | |
| } | |
| const STATUS_COLOR: Record<RunInfo["status"], string> = { | |
| queued: "gray", | |
| running: "blue", | |
| done: "teal", | |
| failed: "red", | |
| cancelled: "yellow", | |
| }; | |
| function extractErrorContext(lines: string[] | undefined): string[] { | |
| if (!lines || lines.length === 0) return []; | |
| // Prefer lines containing ERROR / Last command | |
| const idx = lines.findIndex((l) => /ERROR|Last command/i.test(l)); | |
| if (idx >= 0) return lines.slice(idx, idx + 4).filter((l) => l.trim()); | |
| // Otherwise show the tail | |
| return lines.slice(-3).filter((l) => l.trim()); | |
| } | |
| export function RunStatus({ run, totalSteps, logLines }: Props) { | |
| if (!run) { | |
| return ( | |
| <Stack gap="xs"> | |
| <Title order={5}>Status</Title> | |
| <Text size="sm" c="dimmed"> | |
| No run submitted. | |
| </Text> | |
| </Stack> | |
| ); | |
| } | |
| const elapsed = | |
| run.finished_at > 0 | |
| ? run.finished_at - run.started_at | |
| : run.started_at > 0 | |
| ? (Date.now() / 1000 - run.started_at) | |
| : 0; | |
| return ( | |
| <Stack gap="sm"> | |
| <Title order={5}>Status</Title> | |
| <Group justify="space-between" wrap="nowrap"> | |
| <Text size="sm">Name</Text> | |
| <Text | |
| size="sm" | |
| fw={500} | |
| style={{ | |
| overflow: "hidden", | |
| textOverflow: "ellipsis", | |
| whiteSpace: "nowrap", | |
| maxWidth: 160, | |
| }} | |
| title={run.name ?? run.example} | |
| > | |
| {run.name ?? run.example} | |
| </Text> | |
| </Group> | |
| <Group justify="space-between"> | |
| <Text size="sm">State</Text> | |
| <Badge color={STATUS_COLOR[run.status]} variant="filled"> | |
| {run.status} | |
| </Badge> | |
| </Group> | |
| <Group justify="space-between"> | |
| <Text size="sm">Run id</Text> | |
| <Text size="sm" ff="monospace"> | |
| {run.id} | |
| </Text> | |
| </Group> | |
| <Group justify="space-between"> | |
| <Text size="sm">Last step</Text> | |
| <Text size="sm" ff="monospace"> | |
| {run.last_step ?? "—"} | |
| </Text> | |
| </Group> | |
| <Group justify="space-between"> | |
| <Text size="sm">Elapsed</Text> | |
| <Text size="sm" ff="monospace"> | |
| {elapsed.toFixed(1)}s | |
| </Text> | |
| </Group> | |
| {(run.status === "failed" || run.status === "cancelled") && ( | |
| <Stack gap={4} mt={4}> | |
| <Text size="xs" c="dimmed"> | |
| {run.status === "cancelled" ? "Cancellation context" : "Error context"} | |
| </Text> | |
| <Code | |
| block | |
| style={{ | |
| fontSize: 11, | |
| maxHeight: 80, | |
| overflow: "auto", | |
| backgroundColor: "var(--mantine-color-red-0)", | |
| color: "var(--mantine-color-red-9)", | |
| }} | |
| > | |
| {extractErrorContext(logLines).join("\n") || "(no context available)"} | |
| </Code> | |
| </Stack> | |
| )} | |
| <Group justify="center" mt="md"> | |
| <RingProgress | |
| size={120} | |
| thickness={10} | |
| sections={[ | |
| { | |
| value: | |
| totalSteps && totalSteps > 0 && run.last_step != null | |
| ? Math.min(100, (run.last_step / totalSteps) * 100) | |
| : 0, | |
| color: STATUS_COLOR[run.status], | |
| }, | |
| ]} | |
| label={ | |
| <Text ta="center" size="xs"> | |
| {run.last_step ?? 0} / {totalSteps ?? "—"} | |
| </Text> | |
| } | |
| /> | |
| </Group> | |
| </Stack> | |
| ); | |
| } | |