orik-ss's picture
Claude Opus 4.5
Initial deployment - Face verification demo
ccb7e46
Raw History Blame Contribute Delete
7.11 kB
import { useState } from 'react'
import { motion, AnimatePresence } from 'framer-motion'
import Header from './components/Header'
import ImageUpload from './components/ImageUpload'
import ResultDisplay from './components/ResultDisplay'
import Features from './components/Features'
import axios from 'axios'
function App() {
const [image1, setImage1] = useState(null)
const [image2, setImage2] = useState(null)
const [result, setResult] = useState(null)
const [loading, setLoading] = useState(false)
const [error, setError] = useState(null)
const handleCompare = async () => {
if (!image1 || !image2) {
setError('Please upload both images')
return
}
setLoading(true)
setError(null)
setResult(null)
try {
const formData = new FormData()
formData.append('image1', image1.file)
formData.append('image2', image2.file)
const response = await axios.post('/api/compare', formData, {
headers: { 'Content-Type': 'multipart/form-data' }
})
setResult(response.data)
} catch (err) {
setError(err.response?.data?.detail || 'Failed to compare faces. Please try again.')
} finally {
setLoading(false)
}
}
const handleReset = () => {
setResult(null)
setImage1(null)
setImage2(null)
setError(null)
}
// Clear result when an image is removed
const handleClearImage1 = () => {
setResult(null)
setImage1(null)
}
const handleClearImage2 = () => {
setResult(null)
setImage2(null)
}
return (
<div className="min-h-screen bg-dark-400 bg-animated">
<div className="relative z-10">
<Header />
<main className="container mx-auto px-4 py-12">
{/* Hero Section */}
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
className="text-center mb-16 scroll-mt-24"
>
<h1 className="text-5xl md:text-7xl font-bold mb-6">
<span className="gradient-text">Face Recognition</span>
</h1>
<p className="text-xl text-gray-400 max-w-2xl mx-auto">
Advanced AI-powered face comparison technology.
<br />
Upload two images to verify if they belong to the same person.
</p>
</motion.div>
{/* Main Content - Side by Side Layout */}
<div className={`flex flex-col ${result ? 'lg:flex-row' : ''} gap-6 max-w-7xl mx-auto mb-12`}>
{/* Upload Section */}
<motion.div
initial={{ opacity: 0, y: 30 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.2 }}
layout
className={`glass-card p-6 md:p-8 ${result ? 'lg:w-1/2' : 'w-full max-w-6xl mx-auto'}`}
>
<div className="grid md:grid-cols-2 gap-6 mb-6">
<ImageUpload
label="First Image"
image={image1}
onImageSelect={setImage1}
onClear={handleClearImage1}
/>
<ImageUpload
label="Second Image"
image={image2}
onImageSelect={setImage2}
onClear={handleClearImage2}
/>
</div>
{/* Action Buttons - Smaller */}
<div className="flex flex-col sm:flex-row gap-3 justify-center">
<motion.button
whileHover={{ scale: 1.02 }}
whileTap={{ scale: 0.98 }}
onClick={handleCompare}
disabled={!image1 || !image2 || loading}
className={`
px-4 py-2 rounded-md font-medium text-sm
transition-all duration-300
${image1 && image2 && !loading
? 'bg-gradient-to-r from-primary-500 via-orange-600 to-orange-500 text-white shadow-lg shadow-primary-500/25 hover:shadow-xl hover:shadow-primary-500/30'
: 'bg-gray-700/50 text-gray-400 cursor-not-allowed'
}
`}
>
{loading ? (
<span className="flex items-center gap-2">
<svg className="animate-spin h-3 w-3" viewBox="0 0 24 24">
<circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" fill="none" />
<path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" />
</svg>
Analyzing...
</span>
) : (
'Compare Faces'
)}
</motion.button>
{(image1 || image2 || result) && (
<motion.button
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
whileHover={{ scale: 1.02 }}
whileTap={{ scale: 0.98 }}
onClick={handleReset}
className="px-4 py-2 rounded-md font-medium text-sm border border-gray-600 text-gray-300 hover:bg-gray-800/50 transition-all"
>
Reset
</motion.button>
)}
</div>
{/* Error Display */}
<AnimatePresence>
{error && (
<motion.div
initial={{ opacity: 0, y: -10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -10 }}
className="mt-4 p-3 bg-red-500/10 border border-red-500/30 rounded-lg text-red-400 text-center text-sm"
>
{error}
</motion.div>
)}
</AnimatePresence>
</motion.div>
{/* Results Section - Shows on Right, exits to Right */}
<AnimatePresence mode="wait">
{result && image1 && image2 && (
<motion.div
key="result"
initial={{ opacity: 0, x: 100 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 100 }}
transition={{ type: 'spring', damping: 25, stiffness: 200 }}
className="lg:w-1/2"
>
<ResultDisplay result={result} image1={image1} image2={image2} />
</motion.div>
)}
</AnimatePresence>
</div>
{/* Features Section */}
<Features />
</main>
{/* Footer */}
<footer className="border-t border-gray-800 py-8 mt-20">
<div className="container mx-auto px-4 text-center text-gray-500">
<p>&copy; 2026 Seventh Sense AI. All rights reserved.</p>
</div>
</footer>
</div>
</div>
)
}
export default App