|
|
"use client"; |
|
|
|
|
|
import { RemoveBackground } from '@/lib/removeBackground'; |
|
|
import { useState, useEffect } from 'react'; |
|
|
import { Toaster, toast } from 'sonner'; |
|
|
import { FileDropzone } from '@/components/FileDropzone'; |
|
|
|
|
|
export default function Homepage() { |
|
|
const { isLoadingModel, error, processImage } = RemoveBackground(); |
|
|
const [processedImageUrl, setProcessedImageUrl] = useState<string | null>(null); |
|
|
|
|
|
|
|
|
const handleDropFile = async (fileBase64: string) => { |
|
|
const processed = await processImage(fileBase64); |
|
|
if (processed) { |
|
|
setProcessedImageUrl(processed); |
|
|
toast.success('图像处理成功!'); |
|
|
} else { |
|
|
toast.error('图像处理失败!'); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
if (isLoadingModel) { |
|
|
toast('模型加载中...'); |
|
|
} |
|
|
|
|
|
if (error) { |
|
|
toast.error(`模型加载错误: ${error.message}`); |
|
|
} |
|
|
}, [isLoadingModel, error]); |
|
|
|
|
|
return ( |
|
|
<div className="flex flex-col items-center h-screen bg-gray-100 p-4 sm:p-6 overflow-hidden"> |
|
|
<Toaster /> |
|
|
<div className="w-full text-center flex flex-col items-center"> |
|
|
<h1 className="text-xl sm:text-2xl md:text-3xl font-semibold mb-3 sm:mb-4"> |
|
|
Image Processing |
|
|
</h1> |
|
|
<p className="text-xs sm:text-sm md:text-base text-gray-600 mb-4 sm:mb-6"> |
|
|
Upload an image to process it. |
|
|
</p> |
|
|
<FileDropzone |
|
|
onDropFile={handleDropFile} |
|
|
processedImageUrl={processedImageUrl || undefined} |
|
|
/> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|