Skip to content

Commit

Permalink
Larger images
Browse files Browse the repository at this point in the history
  • Loading branch information
machado2 committed Jul 4, 2024
1 parent 165e29b commit 2197619
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 50 deletions.
2 changes: 0 additions & 2 deletions ui/src/components/ImageById.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const ImageById: React.FC<Props> = ({
alt=""
data-src={imageUrl}
onClick={handleClick}
maxW="128px"
maxH="128px"
objectFit="contain"
loading="lazy"
/>
Expand Down
84 changes: 36 additions & 48 deletions ui/src/components/StylePromptTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
Box,
Button,
Center,
Flex,
Heading,
Modal,
ModalBody,
ModalCloseButton,
Expand All @@ -11,13 +13,8 @@ import {
ModalHeader,
ModalOverlay,
Spinner,
Table,
Tbody,
Td,
Textarea,
Th,
Thead,
Tr,
Text,
useBreakpointValue,
useDisclosure,
} from '@chakra-ui/react';
Expand All @@ -31,6 +28,11 @@ interface CheckpointPromptTableProps {
handleClick: (prompt_id: number, style_id: number) => void;
}

interface Image {
style: Style;
prompt: Prompt;
}

const StylePromptTable: React.FC<CheckpointPromptTableProps> = ({
prompts,
styles,
Expand Down Expand Up @@ -59,50 +61,36 @@ const StylePromptTable: React.FC<CheckpointPromptTableProps> = ({

};


let images: Image[] = []
for (let style in styles) {
for (let prompt in prompts) {
const img = {style: styles[style], prompt: prompts[prompt]}
images.push(img)
}
}

return (
<>
<Box overflowX="auto" maxWidth={boxSize}>
<Table variant="striped" colorScheme="orange">
<Thead>
<Tr>
<Th>Style</Th>
{prompts.map((prompt) => (
<Th key={prompt.id}>{prompt.text}</Th>
))}
</Tr>
</Thead>
<Tbody>
{styles.map((style) => (
<Tr key={style.id}>
<Td
cursor="pointer"
onClick={() => handleStyleClick(style.id)}
>
{style.name}
</Td>
{prompts.map((prompt) => (
<Td key={prompt.id}>
<Box
display="flex"
alignItems="center"
justifyContent="center"
maxW="128px"
maxH="128px"
>
<ImageById
prompt_id={prompt.id}
style_id={style.id}
onClick={handleClick}
/>
</Box>
</Td>
))}
</Tr>
))}
</Tbody>
</Table>
</Box>

<Flex wrap="wrap" justifyContent="space-around">
{images.map((image) => (
<Box float={"left"} key={image.style.id + image.prompt.id}>
<Box margin="5px">
<Text fontSize="lg" fontWeight="bold" width="500px" textOverflow="ellipsis" overflow="hidden"
whiteSpace="nowrap" onClick={() => {
handleStyleClick(image.style.id)
}}>{image.style.name}</Text>
<Text fontSize="md" width="500px" textOverflow="ellipsis" overflow="hidden"
whiteSpace="nowrap">{image.prompt.text}</Text>
<ImageById
prompt_id={image.prompt.id}
style_id={image.style.id}
onClick={handleClick}
/>
</Box>
</Box>
))}
</Flex>
<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay/>
<ModalContent>
Expand Down
136 changes: 136 additions & 0 deletions ui/src/components/StylePromptTable2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import React, {useState} from 'react';
import {
Box,
Button,
Center,
Modal,
ModalBody,
ModalCloseButton,
ModalContent,
ModalFooter,
ModalHeader,
ModalOverlay,
Spinner,
Table,
Tbody,
Td,
Textarea,
Th,
Thead,
Tr,
useBreakpointValue,
useDisclosure,
} from '@chakra-ui/react';
import axios from 'axios';
import ImageById from './ImageById';
import {Prompt, Style} from './SimpleTypes';

interface CheckpointPromptTableProps {
prompts: Prompt[];
styles: Style[];
handleClick: (prompt_id: number, style_id: number) => void;
}

const StylePromptTable: React.FC<CheckpointPromptTableProps> = ({
prompts,
styles,
handleClick,
}) => {
const boxSize = useBreakpointValue({base: '90vw', md: 'auto'});
const {isOpen, onOpen, onClose} = useDisclosure();
const [modalContent, setModalContent] = useState<string | null>(null);
const [loading, setLoading] = useState<boolean>(false);

const fetchStyleDetails = async (style_id: number) => {
setLoading(true);
try {
const response = await axios.get(`/style?style_id=${style_id}`);
setModalContent(JSON.stringify(response.data, null, 2)); // Format JSON content
} catch (error) {
console.error('Error fetching style details:', error);
setModalContent('Error loading content');
}
setLoading(false);
};

const handleStyleClick = (style_id: number) => {
fetchStyleDetails(style_id).then();
onOpen();

};

return (
<>
<Box overflowX="auto" maxWidth={boxSize}>
<Table variant="striped" colorScheme="orange">
<Thead>
<Tr>
<Th>Style</Th>
{prompts.map((prompt) => (
<Th key={prompt.id}>{prompt.text}</Th>
))}
</Tr>
</Thead>
<Tbody>
{styles.map((style) => (
<Tr key={style.id}>
<Td
cursor="pointer"
onClick={() => handleStyleClick(style.id)}
>
{style.name}
</Td>
{prompts.map((prompt) => (
<Td key={prompt.id}>
<Box
display="flex"
alignItems="center"
justifyContent="center"
maxW="128px"
maxH="128px"
>
<ImageById
prompt_id={prompt.id}
style_id={style.id}
onClick={handleClick}
/>
</Box>
</Td>
))}
</Tr>
))}
</Tbody>
</Table>
</Box>

<Modal isOpen={isOpen} onClose={onClose} size="xl">
<ModalOverlay/>
<ModalContent>
<ModalHeader>Style Details</ModalHeader>
<ModalCloseButton/>
<ModalBody>
{loading ? (
<Center>
<Spinner size="xl"/>
</Center>
) : (
<Textarea
value={modalContent || ''}
readOnly
height="200px"
whiteSpace="pre-wrap"
/>
)}
</ModalBody>
<ModalFooter>
<Button colorScheme="blue" onClick={onClose}>
Close
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</>
);
};

export default StylePromptTable;

0 comments on commit 2197619

Please sign in to comment.