Spaces:
Running
Running
File size: 7,113 Bytes
ccb7e46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | 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>© 2026 Seventh Sense AI. All rights reserved.</p>
</div>
</footer>
</div>
</div>
)
}
export default App |