import React, { useState, useEffect, useRef } from 'react'; import { Send, Loader2, Heart, Frown, Smile, Zap, Meh, AlertCircle, TrendingUp, Moon, Sun } from 'lucide-react'; import MovieCarousel from './components/MovieCarousel'; const EmotionDetector = () => { const [text, setText] = useState(''); const [result, setResult] = useState(null); const [movies, setMovies] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const [apiHealth, setApiHealth] = useState(null); const [isDark, setIsDark] = useState(true); const textareaRef = useRef(null); // API endpoint - change this to your deployed backend URL const API_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:8000'; // Emotion configurations with colors and icons const emotionConfig = { joy: { color: '#FFD700', gradient: 'from-yellow-400 to-amber-500', icon: Smile, emoji: '😊' }, love: { color: '#FF69B4', gradient: 'from-pink-400 to-rose-500', icon: Heart, emoji: '❤️' }, surprise: { color: '#9370DB', gradient: 'from-purple-400 to-violet-500', icon: Zap, emoji: '😲' }, neutral: { color: '#94A3B8', gradient: 'from-slate-400 to-gray-500', icon: Meh, emoji: '😐' }, sadness: { color: '#4682B4', gradient: 'from-blue-400 to-cyan-600', icon: Frown, emoji: '😢' }, anger: { color: '#DC143C', gradient: 'from-red-500 to-orange-600', icon: AlertCircle, emoji: '😠' }, fear: { color: '#8B4513', gradient: 'from-amber-700 to-orange-800', icon: TrendingUp, emoji: '😨' } }; // Check API health on mount useEffect(() => { checkHealth(); }, []); const checkHealth = async () => { try { const response = await fetch(`${API_URL}/health`); if (response.ok) { const data = await response.json(); setApiHealth(data); } } catch (err) { console.error('Health check failed:', err); } }; const handleSubmit = async (e) => { e.preventDefault(); if (!text.trim()) { setError('Please enter some text'); return; } if (text.length > 5000) { setError('Text too long (max 5000 characters)'); return; } setLoading(true); setError(null); setResult(null); setMovies(null); try { // Call the new /recommendations endpoint const response = await fetch(`${API_URL}/recommendations`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ text: text.trim() }), }); if (!response.ok) { const errorData = await response.json(); throw new Error(errorData.detail || 'Prediction failed'); } const data = await response.json(); setResult({ emotion: data.emotion, confidence: data.confidence, }); setMovies(data.recommendations); } catch (err) { setError(err.message || 'Failed to connect to server'); console.error('Prediction error:', err); } finally { setLoading(false); } }; const handleTextChange = (e) => { setText(e.target.value); setError(null); }; const handleClear = () => { setText(''); setResult(null); setMovies(null); setError(null); textareaRef.current?.focus(); }; const tryExample = (exampleText) => { setText(exampleText); setError(null); setResult(null); setMovies(null); }; const exampleTexts = [ "I'm so excited about my vacation next week!", "This situation makes me really frustrated and angry.", "I miss my family so much, feeling lonely today.", "You mean everything to me, I love you.", "I'm worried about the exam results tomorrow.", "Just another regular day at work.", "Wow! I can't believe this just happened!" ]; // Dark theme: Blade Runner 2049 - Neon pink/purple cyberpunk // Light theme: Joker 2019 - Neon orange suit inspired const bgLight = 'bg-gradient-to-br from-orange-50 via-amber-50 to-red-50'; const bgDark = 'bg-gradient-to-br from-slate-950 via-purple-950 to-slate-950'; const headerLight = 'bg-gradient-to-r from-orange-500 via-red-500 to-orange-600 border-orange-400'; const headerDark = 'bg-gradient-to-r from-fuchsia-900 via-purple-900 to-violet-900 border-fuchsia-600'; const cardLight = 'bg-white border-orange-400 shadow-lg'; const cardDark = 'bg-slate-900/80 border-fuchsia-500 shadow-2xl shadow-fuchsia-500/20'; const sortedEmotions = result ? Object.entries(result.all_probabilities || {}).sort((a, b) => b[1] - a[1]) : []; return (
{/* Header */}

MoodFlix

Emotion-based Movie Recommendations

{apiHealth && (
API Online
)} {/* Theme Toggle */}
{/* Main Content */}
{/* Left Column - Input */}
{/* Input Card */}

How are you feeling?