Clean up dream

This commit is contained in:
Austin Chen 2022-10-06 11:17:57 -04:00
parent ae81ef6ccb
commit 88b7064b66
2 changed files with 32 additions and 36 deletions

View File

@ -22,35 +22,32 @@ export function ImageModal(props: {
const { upload, open, setOpen } = props const { upload, open, setOpen } = props
return ( return (
<Modal open={open} setOpen={setOpen}> <Modal open={open} setOpen={setOpen}>
<Col className="gap-2 rounded bg-white p-6"> <Tabs
<Tabs className="gap-2 rounded bg-white p-6"
tabs={[ tabs={[
{ {
title: 'Upload file', title: 'Upload file',
content: ( content: (
<Col> <FileUploadButton
<FileUploadButton onFiles={(files) => {
onFiles={(files) => { setOpen(false)
setOpen(false) upload.mutate(files)
upload.mutate(files) }}
}} className="relative block w-full rounded-lg border-2 border-dashed border-gray-300 p-12 text-center hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
className="relative block w-full rounded-lg border-2 border-dashed border-gray-300 p-12 text-center hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2" >
> <UploadIcon className="mx-auto h-12 w-12 text-gray-400" />
<UploadIcon className="mx-auto h-12 w-12 text-gray-400" /> <span className="mt-2 block text-sm font-medium text-gray-400">
<span className="mt-2 block text-sm font-medium text-gray-400"> Upload an image file
Upload an image file </span>
</span> </FileUploadButton>
</FileUploadButton> ),
</Col> },
), {
}, title: 'Dream',
{ content: <DreamTab {...props} />,
title: 'Dream', },
content: <DreamTab {...props} />, ]}
}, />
]}
/>
</Col>
</Modal> </Modal>
) )
} }
@ -85,7 +82,7 @@ function DreamTab(props: {
apiKey: API_KEY, apiKey: API_KEY,
} }
const headers = { const headers = {
'api-key': 'quickstart-QUdJIGlzIGNvbWluZy4uLi4K', 'Content-Type': 'application/json',
} }
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
@ -128,7 +125,6 @@ function DreamTab(props: {
{/* Show the current imageUrl */} {/* Show the current imageUrl */}
{imageUrl && ( {imageUrl && (
<> <>
{' '}
<img src={imageUrl} alt="Image" /> <img src={imageUrl} alt="Image" />
<Row className="gap-2"> <Row className="gap-2">
<Button <Button

View File

@ -18,13 +18,13 @@ export default async function route(req: NextApiRequest, res: NextApiResponse) {
methods: 'POST', methods: 'POST',
}) })
const body = JSON.parse(req.body) // const body = JSON.parse(req.body)
// Check that prompt and apiKey are included in the body // Check that prompt and apiKey are included in the body
if (!body.prompt) { if (!req.body.prompt) {
res.status(400).json({ message: 'Missing prompt' }) res.status(400).json({ message: 'Missing prompt' })
return return
} }
if (!body.apiKey) { if (!req.body.apiKey) {
res.status(400).json({ message: 'Missing apiKey' }) res.status(400).json({ message: 'Missing apiKey' })
return return
} }
@ -50,7 +50,7 @@ export default async function route(req: NextApiRequest, res: NextApiResponse) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
const { _dreamResponse, images } = await generateAsync({ const { _dreamResponse, images } = await generateAsync({
...body, ...req.body,
// Don't actually write to disk, because we're going to upload it to Firestore // Don't actually write to disk, because we're going to upload it to Firestore
noStore: true, noStore: true,
}) })
@ -59,7 +59,7 @@ export default async function route(req: NextApiRequest, res: NextApiResponse) {
res.status(200).json({ url }) res.status(200).json({ url })
} catch (e) { } catch (e) {
res.status(501).json({ message: `Error running code: ${e}` }) res.status(500).json({ message: `Error running code: ${e}` })
} }
} }