import React, { useState, useEffect, FormEvent, ChangeEvent } from 'react'; interface InputData { prompt: string; width: number; height: number; steps: number; fps: number; seed?: number; } interface OutputData { prediction: any; timestamp: string; prompt: string; } const TruncatedText = ({ text }: { text: string }) => { const [isTruncated, setIsTruncated] = useState(true); const toggleTruncated = () => { setIsTruncated(!isTruncated); }; if (text.length < 34) { return {text}; } return ( {isTruncated ? `${text.substring(0, 24)}...` : text} ); }; const IndexPage = () => { const [inputData, setInputData] = useState({ prompt: '', width: 1024, height: 576, steps: 40, fps: 15, seed: undefined, }); const [output, setOutput] = useState([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const savedOutput = localStorage.getItem('output'); if (savedOutput) { setOutput(JSON.parse(savedOutput)); } }, []); const handleChange = (e: ChangeEvent) => { const { name, value } = e.target; setInputData((prevData) => ({ ...prevData, [name]: value })); }; const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); try { const response = await fetch('/api/replicate', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(inputData), }); const result = await response.json(); if (response.ok) { const timestamp = new Date().toISOString(); const newOutput = { prediction: result.prediction, timestamp, prompt: inputData.prompt, }; const updatedOutput = [...output, newOutput]; setOutput(updatedOutput); localStorage.setItem('output', JSON.stringify(updatedOutput)); setInputData({ prompt: '', width: 1024, height: 576, steps: 40, fps: 15, seed: undefined, }); } } catch (error) { console.error("An error occurred:", error); } finally { setIsLoading(false); } }; return (

Video Generation App

{output.map((video, index) => (

Generated Video {index + 1}:

{/* Download Button */}

Date: {new Date(video.timestamp).toLocaleDateString()} Time: {new Date(video.timestamp).toLocaleTimeString()}

))}
); }; export default IndexPage;