'use client'; import { useState } from 'react'; import { MessageSquare, TrendingUp, TrendingDown, Minus, Sparkles } from 'lucide-react'; import { fetchJson } from '@/lib/http'; interface SentimentResult { label: 'POSITIVE' | 'NEGATIVE' | 'NEUTRAL'; score: number; } interface SentimentData { text: string; sentiment: SentimentResult; timestamp: string; } export default function SentimentAnalyzer() { const [text, setText] = useState(''); const [result, setResult] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const analyzeSentiment = async () => { if (!text.trim()) return; setLoading(true); setError(null); try { const data = await fetchJson>( `/api/sentiment`, { method: 'POST' }, { timeoutMs: 20000, retries: 0, jsonBody: { text } } ); // No-toy: if backend returns no sentiment, we show no label. if (!data || (typeof data !== 'object')) { throw new Error('Invalid sentiment payload'); } if (!('sentiment' in data)) { throw new Error('Invalid sentiment payload'); } setResult(data as unknown as SentimentData); } catch (err) { console.error('Sentiment analysis failed:', err); setResult(null); setError('Duygu analizi servisine ulaşılamadı veya model hazır değil. Bu durumda sonuç üretilmez.'); } finally { setLoading(false); } }; const getSentimentColor = (label: string) => { switch (label) { case 'POSITIVE': return 'text-green-600 bg-green-50 border-green-200'; case 'NEGATIVE': return 'text-red-600 bg-red-50 border-red-200'; default: return 'text-gray-600 bg-gray-50 border-gray-200'; } }; const getSentimentIcon = (label: string) => { switch (label) { case 'POSITIVE': return ; case 'NEGATIVE': return ; default: return ; } }; const getSentimentLabel = (label: string) => { switch (label) { case 'POSITIVE': return 'Pozitif'; case 'NEGATIVE': return 'Negatif'; default: return 'Nötr'; } }; return (

Haber Duygu Analizi