'use client'; import { useState } from 'react'; export default function Page() { const [inputValue, setInputValue] = useState(''); const [imageSrc, setImageSrc] = useState(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (event: React.FormEvent) => { event.preventDefault(); setIsLoading(true); setImageSrc(null); setError(null); try { const response = await fetch('/api/generate-image', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: inputValue }), }); if (response.ok) { const image = await response.json(); setImageSrc(`data:image/png;base64,${image}`); return; } setError(await response.text()); } finally { setIsLoading(false); } }; return (

Image Generator

Generate images.

setInputValue(e.target.value)} disabled={isLoading} />
{error && (
{error}
)}
{isLoading ? (
) : ( imageSrc && ( Generated Image ) )}
); }