From 5c55d9f8ba5268d025fdcf8d0c4762e3825cc2a4 Mon Sep 17 00:00:00 2001 From: Felipe Cardoso Date: Thu, 23 Jan 2025 14:40:42 +0100 Subject: [PATCH] Add better samples components support Signed-off-by: Felipe Cardoso --- frontend/src/app/samples/page.tsx | 77 +++++++++++----------- frontend/src/components/SampleCard.tsx | 43 ++++++++++++ frontend/src/components/SamplesGallery.tsx | 2 +- 3 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 frontend/src/components/SampleCard.tsx diff --git a/frontend/src/app/samples/page.tsx b/frontend/src/app/samples/page.tsx index ad7acf5..db34f24 100644 --- a/frontend/src/app/samples/page.tsx +++ b/frontend/src/app/samples/page.tsx @@ -2,9 +2,10 @@ "use client" import {useSamples} from '@/contexts/SamplesContext' -import Image from 'next/image' import Link from "next/link" import {useMemo} from 'react' +import {useTraining} from "@/contexts/TrainingContext"; +import {SampleCard} from "@/components/SampleCard"; // Helper function to parse sample information const parseSampleInfo = (filename: string) => { @@ -18,7 +19,11 @@ const parseSampleInfo = (filename: string) => { } export default function SamplesPage() { - const {samples, isLoading, error} = useSamples() + const {samples, isLoading: samplesLoading, error: samplesError} = useSamples() + const {config, isLoading: configLoading} = useTraining() + + // Get prompts from config + const prompts = config?.config?.process[0]?.sample?.prompts || [] // Group samples by batch number using a memoized calculation const groupedSamples = useMemo(() => { @@ -45,25 +50,26 @@ export default function SamplesPage() { return new Map([...groups].sort((a, b) => b[0] - a[0])) }, [samples]) - // Handle loading and error states with appropriate styling - if (isLoading) return ( + // Handle loading and error states + if (samplesLoading || configLoading) return (
-
Loading samples...
+
Loading...
) - if (error) return ( + if (samplesError) return (
-
Error: {error.message}
+
Error: {samplesError.message}
) + return (
{/* Header with navigation */}
-

Sample Gallery

+

Samples Gallery

+ + {/* Prompts display */} +
+

+ Generation Prompts +

+
+ {prompts.map((prompt, index) => ( +
+ {index}: + {prompt} +
+ ))} +
+
+ {/* Sample groups */}
{Array.from(groupedSamples).map(([batch, items]) => (

- Step {batch} + Steps {batch}

{/* Scrollable container for samples */}
{items.map((sample: any) => ( -
- {/* Image container with hover effects */} -
- {`Sample -
- - {/* Sample information */} -
-
- {new Date(sample.created_at).toLocaleString()} -
- - Sample {sample.index} - -
-
+ sample={sample} + prompt={prompts[sample.index]} + /> ))}
diff --git a/frontend/src/components/SampleCard.tsx b/frontend/src/components/SampleCard.tsx new file mode 100644 index 0000000..258e9c0 --- /dev/null +++ b/frontend/src/components/SampleCard.tsx @@ -0,0 +1,43 @@ +"use client" + +import Image from 'next/image' + +interface SampleCardProps { + sample: { + filename: string + url: string + created_at: string + index: number + } + prompt?: string // Associated prompt from config +} + +export function SampleCard({sample, prompt}: SampleCardProps) { + return ( +
+
+ {`Sample +
+ +
+
+ {new Date(sample.created_at).toLocaleString()} +
+ + Sample {sample.index} + +
+
+ ) +} \ No newline at end of file diff --git a/frontend/src/components/SamplesGallery.tsx b/frontend/src/components/SamplesGallery.tsx index 96fad9b..10d8e44 100644 --- a/frontend/src/components/SamplesGallery.tsx +++ b/frontend/src/components/SamplesGallery.tsx @@ -43,7 +43,7 @@ export function SamplesGallery() { {/* Style the filename with appropriate dark mode colors */}

- {sample.url.split('__')[1]} + {sample.url.split('__')[1].split(".")[0]}

))}