import React, { useCallback, useEffect, useState } from "react"; import { TextField, Grid, Paper } from "@mui/material"; function App() { const [inputPrompt, setInputPrompt] = useState(""); const [images, setImages] = useState(Array(9).fill("images/white.jpg")); const fetchImages = useCallback(async () => { try { const response = await fetch("/api/predict", { method: "POST", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ prompt: inputPrompt }) }); const data = await response.json(); const imageUrls = data.base64_images.map((base64: string) => `data:image/jpeg;base64,${base64}`); setImages(imageUrls); } catch (error) { console.error("Error fetching images:", error); } }, [inputPrompt]); const handlePromptChange = (event: React.ChangeEvent) => { setInputPrompt(event.target.value); fetchImages(); }; return (
{images.map((image, index) => ( {`Generated ))}
); } export default App;