import React, { useRef, useState } from "react"; import axios from "axios"; import ImageDisplay from "./ImageDisplay"; const MainContent = () => { const fileInput = useRef(null); const [isSuccessUpload, setIsSuccessUpload] = useState(false); const [uid, setUid] = useState(""); const [videoPreview, setVideoPreview] = useState(null); const [isLoading, setIsLoading] = useState(false); const handleFileSelect = () => { const file = fileInput.current.files[0]; if (file) { setVideoPreview(URL.createObjectURL(file)); } }; const handleUpload = async () => { setIsLoading(true); const formData = new FormData(); formData.append('file', fileInput.current.files[0]); try { const response = await axios.post('http://localhost:8000/uploadvideo/', formData, { headers: { 'Content-Type': 'multipart/form-data', }, }); alert(response.data.message); setUid(response.data.uid); setIsSuccessUpload(true); } catch (error) { alert('Failed to upload video. ' + error.message); } finally { setIsLoading(false); } }; return (
Video Face Swap
{videoPreview && ( )} {isSuccessUpload && (
)}
); }; export default MainContent;