import React, { useState, useEffect } from "react"; import { Box, Grid, Card, CardContent, Typography, CircularProgress, Chip, Stack, } from "@mui/material"; import { Palette as PaletteIcon, Person as PersonIcon, Category as CategoryIcon, AccessTime as AccessTimeIcon, } from "@mui/icons-material"; import { storyApi, universeApi } from "../utils/api"; const UniverseCard = ({ universe, imagePrompt }) => { const [imageUrl, setImageUrl] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const generateImage = async () => { try { const result = await storyApi.generateImage(imagePrompt, 512, 512); if (result && result.success) { setImageUrl(`data:image/png;base64,${result.image_base64}`); } } catch (error) { console.error("Error generating image:", error); } finally { setIsLoading(false); } }; generateImage(); }, [imagePrompt]); return ( {isLoading ? ( ) : ( )} {universe.style.name} {universe.style.selected_artist && ( {universe.style.selected_artist} )} {universe.genre} {universe.epoch} ); }; export function Universe() { const [universes, setUniverses] = useState([]); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const generateUniverses = async () => { try { const generatedUniverses = await Promise.all( Array(6) .fill() .map(async () => { const universe = await universeApi.generate(); return { ...universe, imagePrompt: `${ universe.style.selected_artist || universe.style.references[0].artist } style, epic wide shot of a detailed scene -- A dramatic establishing shot of a ${universe.genre.toLowerCase()} world in ${ universe.epoch }, with rich atmosphere and dynamic composition. The scene should reflect the essence of ${ universe.style.name } visual style, with appropriate lighting and mood. In the scene, Sarah is a young woman in her late twenties with short dark hair, wearing a mysterious amulet around her neck. Her blue eyes hide untold secrets.`, }; }) ); setUniverses(generatedUniverses); } catch (error) { console.error("Error generating universes:", error); } finally { setIsLoading(false); } }; generateUniverses(); }, []); if (isLoading) { return ( ); } return ( Univers Parallèles {universes.map((universe, index) => ( ))} ); } export default Universe;