'use client'; import React from 'react'; import Image from 'next/image'; import useImageUpload from '../../lib/hooks/useImageUpload'; import { fetcher } from '@/lib/utils'; import { ChatEntity, MessageBase } from '@/lib/types'; import { useRouter } from 'next/navigation'; export interface ImageSelectorProps {} type Example = { url: string; initMessages: MessageBase[]; }; const examples: Example[] = [ { url: 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/cereal-example.jpg', initMessages: [ { role: 'user', content: 'how many cereals are there in the image?', id: 'fake-id-1', }, ], }, // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/people-example.jpeg', // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/house-exmaple.jpg', // 'https://landing-lens-support.s3.us-east-2.amazonaws.com/vision-agent-examples/safari-example.png', ]; const ImageSelector: React.FC = () => { const router = useRouter(); const { getRootProps, getInputProps } = useImageUpload( undefined, async files => { const formData = new FormData(); if (files.length !== 1) { throw new Error('Only one image can be uploaded at a time'); } console.log(); const reader = new FileReader(); reader.readAsDataURL(files[0]); reader.onload = async () => { const resp = await fetcher('/api/upload', { method: 'POST', body: JSON.stringify({ base64: reader.result as string, fileType: files[0].type, }), }); if (resp) { router.push(`/chat/${resp.id}`); } }; }, ); return (

Welcome to Vision Agent

Lets start by choosing an image

Drag or drop image here, or click to select images

You can also choose from below examples we provided

{examples.map(({ url, initMessages }, index) => ( example images { const resp = await fetcher('/api/upload', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ url, initMessages }), }); if (resp) { router.push(`/chat/${resp.id}`); } }} /> ))}
); }; export default ImageSelector;