MingruiZhang commited on
Commit
54a4eaa
1 Parent(s): 873ec73

feat: new chat page (#31)

Browse files

<img width="1904" alt="image"
src="https://github.com/landing-ai/vision-agent-ui/assets/5669963/45268e97-758d-4c4c-8c05-84f71f7a2fbd">

app/chat/page.tsx CHANGED
@@ -7,13 +7,20 @@ import { fetcher } from '@/lib/utils';
7
  import Image from 'next/image';
8
  import { useRouter } from 'next/navigation';
9
 
10
- type Example = {
11
- url: string;
12
- initMessages: MessageBase[];
13
- };
 
 
 
 
 
14
 
15
- const examples: Example[] = [
16
  {
 
 
17
  url: 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/cereal-example.jpg',
18
  initMessages: [
19
  {
@@ -28,52 +35,83 @@ const examples: Example[] = [
28
  },
29
  ],
30
  },
31
- // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/people-example.jpeg',
32
- // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/house-exmaple.jpg',
33
- // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/safari-example.png',
 
 
 
34
  ];
35
 
36
  export default function Page() {
37
  const router = useRouter();
38
  return (
39
  <div className="mx-auto max-w-2xl px-4 mt-8">
40
- <div className="rounded-lg border bg-background p-8">
41
  <h1 className="mb-2 text-lg font-semibold">Welcome to Vision Agent</h1>
42
  <p>
43
  Vision Agent is a library that helps you utilize agent frameworks for
44
  your vision tasks. Vision Agent aims to provide an in-seconds
45
  experience by allowing users to describe their problem in text and
46
- utilizing agent frameworks to solve the task for them. Check out our
47
- discord for updates and roadmap!
48
  </p>
49
- <ImageSelector />
50
- <p className="mt-4 mb-2">
51
- You can also choose from below examples we provided
52
- </p>
53
- <div className="flex">
54
- {examples.map(({ url, initMessages }, index) => (
55
- <Image
56
- src={url}
57
- key={index}
58
- width={120}
59
- height={120}
60
- alt="example images"
61
- className="object-cover rounded mr-3 shadow-md hover:scale-105 cursor-pointer transition-transform"
62
- onClick={async () => {
63
- const resp = await fetcher<ChatEntity>('/api/upload', {
64
- method: 'POST',
65
- headers: {
66
- 'Content-Type': 'application/json',
67
- },
68
- body: JSON.stringify({ url, initMessages }),
69
- });
70
- if (resp) {
71
- router.push(`/chat/${resp.id}`);
72
- }
73
- }}
74
- />
75
- ))}
76
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  </div>
78
  </div>
79
  );
 
7
  import Image from 'next/image';
8
  import { useRouter } from 'next/navigation';
9
 
10
+ import {
11
+ Tooltip,
12
+ TooltipContent,
13
+ TooltipTrigger,
14
+ } from '@/components/ui/Tooltip';
15
+ import { IconDiscord, IconGitHub } from '@/components/ui/Icons';
16
+ import Link from 'next/link';
17
+ import { Button } from '@/components/ui/Button';
18
+ import Img from '@/components/ui/Img';
19
 
20
+ const exampleMessages = [
21
  {
22
+ heading: 'Counting',
23
+ subheading: 'number of cereals in an image',
24
  url: 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/cereal-example.jpg',
25
  initMessages: [
26
  {
 
35
  },
36
  ],
37
  },
38
+ // {
39
+ // heading: 'Detecting',
40
+ // url: 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/cereal-example.jpg',
41
+ // subheading: 'number of cereals in an image',
42
+ // message: `How many cereals are there in the image?`,
43
+ // },
44
  ];
45
 
46
  export default function Page() {
47
  const router = useRouter();
48
  return (
49
  <div className="mx-auto max-w-2xl px-4 mt-8">
50
+ <div className="rounded-lg border bg-background p-8 mb-6">
51
  <h1 className="mb-2 text-lg font-semibold">Welcome to Vision Agent</h1>
52
  <p>
53
  Vision Agent is a library that helps you utilize agent frameworks for
54
  your vision tasks. Vision Agent aims to provide an in-seconds
55
  experience by allowing users to describe their problem in text and
56
+ utilizing agent frameworks to solve the task for them.
 
57
  </p>
58
+ <div className="my-2">
59
+ <Tooltip>
60
+ <TooltipTrigger asChild>
61
+ <Button variant="link" size="icon" asChild className="mr-2">
62
+ <Link
63
+ href="https://github.com/landing-ai/vision-agent"
64
+ target="_blank"
65
+ >
66
+ <IconGitHub className="size-6" />
67
+ </Link>
68
+ </Button>
69
+ </TooltipTrigger>
70
+ <TooltipContent>Github</TooltipContent>
71
+ </Tooltip>
72
+ <Tooltip>
73
+ <TooltipTrigger asChild>
74
+ <Button variant="link" size="icon" asChild className="mr-2">
75
+ <Link href="https://discord.gg/wZ2A7J69" target="_blank">
76
+ <IconDiscord className="size-6" />
77
+ </Link>
78
+ </Button>
79
+ </TooltipTrigger>
80
+ <TooltipContent>Discord</TooltipContent>
81
+ </Tooltip>
 
 
 
82
  </div>
83
+ <ImageSelector />
84
+ </div>
85
+ <div className="mb-4 grid grid-cols-2 gap-2 px-4 sm:px-0">
86
+ {exampleMessages.map((example, index) => (
87
+ <div
88
+ key={index}
89
+ className={`cursor-pointer rounded-lg border bg-white p-4 hover:bg-zinc-50 dark:bg-zinc-950 dark:hover:bg-zinc-900 flex items-center size-full ${
90
+ index > 1 && 'hidden md:block'
91
+ }`}
92
+ onClick={async () => {
93
+ const resp = await fetcher<ChatEntity>('/api/upload', {
94
+ method: 'POST',
95
+ headers: {
96
+ 'Content-Type': 'application/json',
97
+ },
98
+ body: JSON.stringify({
99
+ url: example.url,
100
+ initMessages: example.initMessages,
101
+ }),
102
+ });
103
+ if (resp) {
104
+ router.push(`/chat/${resp.id}`);
105
+ }
106
+ }}
107
+ >
108
+ <Img src={example.url} alt="example images" className="w-1/4" />
109
+ <div className="flex items-start flex-col h-full ml-3 w-3/4">
110
+ <div className="text-sm font-semibold">{example.heading}</div>
111
+ <div className="text-sm text-zinc-600">{example.subheading}</div>
112
+ </div>
113
+ </div>
114
+ ))}
115
  </div>
116
  </div>
117
  );
components/chat-sidebar/ChatCard.tsx CHANGED
@@ -48,7 +48,7 @@ const ChatCard: React.FC<ChatCardProps> = ({ chat }) => {
48
  classNames={chatIdFromParam === id && 'border-gray-500'}
49
  >
50
  <div className="overflow-hidden flex items-center size-full">
51
- <Img src={url} alt={`chat-${id}-card-image`} className="w-1/4 " />
52
  <div className="flex items-start flex-col h-full ml-3 w-3/4">
53
  <p className="text-sm mb-1">{title}</p>
54
  <p className="text-xs text-gray-500">
 
48
  classNames={chatIdFromParam === id && 'border-gray-500'}
49
  >
50
  <div className="overflow-hidden flex items-center size-full">
51
+ <Img src={url} alt={`chat-${id}-card-image`} className="w-1/4" />
52
  <div className="flex items-start flex-col h-full ml-3 w-3/4">
53
  <p className="text-sm mb-1">{title}</p>
54
  <p className="text-xs text-gray-500">
components/chat/ImageSelector.tsx CHANGED
@@ -8,7 +8,7 @@ import { useRouter } from 'next/navigation';
8
  import Loading from '../ui/Loading';
9
  import toast from 'react-hot-toast';
10
 
11
- export interface ImageSelectorProps { }
12
 
13
  type Example = {
14
  url: string;
@@ -29,23 +29,24 @@ const ImageSelector: React.FC<ImageSelectorProps> = () => {
29
  const reader = new FileReader();
30
  reader.readAsDataURL(files[0]);
31
  reader.onload = async () => {
32
- const { id, signedUrl, publicUrl, fields } = await fetcher<SignedPayload>('/api/sign', {
33
- method: 'POST',
34
- body: JSON.stringify({
35
- fileType: files[0].type,
36
- fileName: files[0].name,
37
- }),
38
- });
 
39
  const formData = new FormData();
40
  Object.entries(fields).forEach(([key, value]) => {
41
- formData.append(key, value as string)
42
- })
43
  formData.append('file', files[0]);
44
 
45
  const uploadResponse = await fetch(signedUrl, {
46
  method: 'POST',
47
  body: formData,
48
- })
49
  if (!uploadResponse.ok) {
50
  toast.error(uploadResponse.statusText);
51
  return;
@@ -64,8 +65,9 @@ const ImageSelector: React.FC<ImageSelectorProps> = () => {
64
  if (resp) {
65
  router.push(`/chat/${resp.id}`);
66
  }
67
- }
68
- });
 
69
  return (
70
  <div
71
  {...getRootProps()}
@@ -75,11 +77,11 @@ const ImageSelector: React.FC<ImageSelectorProps> = () => {
75
  )}
76
  >
77
  <input {...getInputProps()} />
78
- <div className="text-gray-400 text-lg">
79
  {isUploading ? (
80
  <Loading />
81
  ) : (
82
- 'Drag or drop image here, or click to select images'
83
  )}
84
  </div>
85
  </div>
 
8
  import Loading from '../ui/Loading';
9
  import toast from 'react-hot-toast';
10
 
11
+ export interface ImageSelectorProps {}
12
 
13
  type Example = {
14
  url: string;
 
29
  const reader = new FileReader();
30
  reader.readAsDataURL(files[0]);
31
  reader.onload = async () => {
32
+ const { id, signedUrl, publicUrl, fields } =
33
+ await fetcher<SignedPayload>('/api/sign', {
34
+ method: 'POST',
35
+ body: JSON.stringify({
36
+ fileType: files[0].type,
37
+ fileName: files[0].name,
38
+ }),
39
+ });
40
  const formData = new FormData();
41
  Object.entries(fields).forEach(([key, value]) => {
42
+ formData.append(key, value as string);
43
+ });
44
  formData.append('file', files[0]);
45
 
46
  const uploadResponse = await fetch(signedUrl, {
47
  method: 'POST',
48
  body: formData,
49
+ });
50
  if (!uploadResponse.ok) {
51
  toast.error(uploadResponse.statusText);
52
  return;
 
65
  if (resp) {
66
  router.push(`/chat/${resp.id}`);
67
  }
68
+ };
69
+ },
70
+ );
71
  return (
72
  <div
73
  {...getRootProps()}
 
77
  )}
78
  >
79
  <input {...getInputProps()} />
80
+ <div className="text-gray-400 text-md">
81
  {isUploading ? (
82
  <Loading />
83
  ) : (
84
+ 'Start using Vision Agent by selecting an image'
85
  )}
86
  </div>
87
  </div>
components/ui/Icons.tsx CHANGED
@@ -383,6 +383,29 @@ function IconCopy({ className, ...props }: React.ComponentProps<'svg'>) {
383
  );
384
  }
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  function IconCheck({ className, ...props }: React.ComponentProps<'svg'>) {
387
  return (
388
  <svg
@@ -558,4 +581,5 @@ export {
558
  IconChevronUpDown,
559
  IconGoogle,
560
  IconLoading,
 
561
  };
 
383
  );
384
  }
385
 
386
+ function IconDiscord({ className, ...props }: React.ComponentProps<'svg'>) {
387
+ return (
388
+ <svg
389
+ width="800px"
390
+ height="800px"
391
+ viewBox="0 -28.5 256 256"
392
+ version="1.1"
393
+ xmlns="http://www.w3.org/2000/svg"
394
+ preserveAspectRatio="xMidYMid"
395
+ className={cn('size-4', className)}
396
+ {...props}
397
+ >
398
+ <g>
399
+ <path
400
+ d="M216.856339,16.5966031 C200.285002,8.84328665 182.566144,3.2084988 164.041564,0 C161.766523,4.11318106 159.108624,9.64549908 157.276099,14.0464379 C137.583995,11.0849896 118.072967,11.0849896 98.7430163,14.0464379 C96.9108417,9.64549908 94.1925838,4.11318106 91.8971895,0 C73.3526068,3.2084988 55.6133949,8.86399117 39.0420583,16.6376612 C5.61752293,67.146514 -3.4433191,116.400813 1.08711069,164.955721 C23.2560196,181.510915 44.7403634,191.567697 65.8621325,198.148576 C71.0772151,190.971126 75.7283628,183.341335 79.7352139,175.300261 C72.104019,172.400575 64.7949724,168.822202 57.8887866,164.667963 C59.7209612,163.310589 61.5131304,161.891452 63.2445898,160.431257 C105.36741,180.133187 151.134928,180.133187 192.754523,160.431257 C194.506336,161.891452 196.298154,163.310589 198.110326,164.667963 C191.183787,168.842556 183.854737,172.420929 176.223542,175.320965 C180.230393,183.341335 184.861538,190.991831 190.096624,198.16893 C211.238746,191.588051 232.743023,181.531619 254.911949,164.955721 C260.227747,108.668201 245.831087,59.8662432 216.856339,16.5966031 Z M85.4738752,135.09489 C72.8290281,135.09489 62.4592217,123.290155 62.4592217,108.914901 C62.4592217,94.5396472 72.607595,82.7145587 85.4738752,82.7145587 C98.3405064,82.7145587 108.709962,94.5189427 108.488529,108.914901 C108.508531,123.290155 98.3405064,135.09489 85.4738752,135.09489 Z M170.525237,135.09489 C157.88039,135.09489 147.510584,123.290155 147.510584,108.914901 C147.510584,94.5396472 157.658606,82.7145587 170.525237,82.7145587 C183.391518,82.7145587 193.761324,94.5189427 193.539891,108.914901 C193.539891,123.290155 183.391518,135.09489 170.525237,135.09489 Z"
401
+ fill="#5865F2"
402
+ fillRule="nonzero"
403
+ ></path>
404
+ </g>
405
+ </svg>
406
+ );
407
+ }
408
+
409
  function IconCheck({ className, ...props }: React.ComponentProps<'svg'>) {
410
  return (
411
  <svg
 
581
  IconChevronUpDown,
582
  IconGoogle,
583
  IconLoading,
584
+ IconDiscord,
585
  };