import { useState } from 'react' import FileUploader from './components/FileUploader' import OptionsPanel from './components/OptionsPanel' import ResultViewer from './components/ResultViewer' import './App.css' function App() { const [file, setFile] = useState(null) const [fileType, setFileType] = useState(null) // 'image' or 'video' const [options, setOptions] = useState({ model: 'u2net', alphaMatting: false, alphaMattingForegroundThreshold: 240, alphaMattingBackgroundThreshold: 10, alphaMattingErodeStructureSize: 10, alphaMattingBaseSize: 1000, backgroundColor: '', backgroundImage: null, // Video options tv: false, mk: false, tov: false, toi: false, gb: false, wn: false, fr: null, fl: null, }) const [processing, setProcessing] = useState(false) const [result, setResult] = useState(null) const [error, setError] = useState(null) const handleFileSelect = (selectedFile) => { setFile(selectedFile) setResult(null) setError(null) if (selectedFile.type.startsWith('image/')) { setFileType('image') } else if (selectedFile.type.startsWith('video/')) { setFileType('video') } else { setError('Please select an image or video file') setFile(null) } } const handleProcess = async () => { if (!file) { setError('Please select a file first') return } setProcessing(true) setError(null) setResult(null) try { const formData = new FormData() formData.append('file', file) // Add options based on file type if (fileType === 'image') { formData.append('model', options.model) formData.append('alpha_matting', options.alphaMatting) if (options.alphaMatting) { formData.append('alpha_matting_foreground_threshold', options.alphaMattingForegroundThreshold) formData.append('alpha_matting_background_threshold', options.alphaMattingBackgroundThreshold) formData.append('alpha_matting_erode_structure_size', options.alphaMattingErodeStructureSize) formData.append('alpha_matting_base_size', options.alphaMattingBaseSize) } if (options.backgroundColor) { formData.append('background_color', options.backgroundColor) } if (options.backgroundImage) { formData.append('background_image', options.backgroundImage) } // Use relative URL so nginx can proxy the request const apiUrl = import.meta.env.VITE_API_URL || '' const response = await fetch(`${apiUrl}/remove-image`, { method: 'POST', body: formData, }) if (!response.ok) { const errorData = await response.json().catch(() => ({ detail: 'Processing failed' })) throw new Error(errorData.detail || 'Processing failed') } const blob = await response.blob() const url = URL.createObjectURL(blob) setResult({ url, type: 'image' }) } else { // Video processing formData.append('model', options.model) formData.append('tv', options.tv) formData.append('mk', options.mk) formData.append('tov', options.tov) formData.append('toi', options.toi) formData.append('gb', options.gb) formData.append('wn', options.wn) if (options.fr !== null) formData.append('fr', options.fr) if (options.fl !== null) formData.append('fl', options.fl) if (options.backgroundColor) { formData.append('background_color', options.backgroundColor) } if (options.backgroundImage) { formData.append('background_image', options.backgroundImage) } // Use relative URL so nginx can proxy the request const apiUrl = import.meta.env.VITE_API_URL || '' const response = await fetch(`${apiUrl}/remove-video`, { method: 'POST', body: formData, }) if (!response.ok) { const errorData = await response.json().catch(() => ({ detail: 'Processing failed' })) throw new Error(errorData.detail || 'Processing failed') } const blob = await response.blob() // Verify blob is valid if (blob.size === 0) { throw new Error('Received empty video file') } // Check content type const contentType = response.headers.get('content-type') if (!contentType || !contentType.includes('video')) { throw new Error(`Unexpected content type: ${contentType}`) } const url = URL.createObjectURL(blob) setResult({ url, type: 'video' }) } } catch (err) { setError(err.message || 'An error occurred during processing') } finally { setProcessing(false) } } return (

Background Remover

Remove backgrounds from images and videos using AI

{file && ( <>
)} {error && (
Error: {error}
)} {processing && (
Processing your {fileType}... This may take a few moments.
)} {result && (
)}
) } export default App