Spaces:
Running
Running
Download index.html from physicswon/leap-demos: direct link, hf CLI and curl.
- Browser
- Download file 36.7 kB
-
https://huggingface.co/spaces/physicswon/leap-demos/resolve/main/index.html
- Command line
-
hf download hf://spaces/physicswon/leap-demos/index.html
-
curl -L -o index.html https://huggingface.co/spaces/physicswon/leap-demos/resolve/main/index.html
36.7 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Prose Mood Tracker</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/chart.js"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .sentiment-text { | |
| transition: background-color 0.3s ease; | |
| } | |
| .joy { background-color: rgba(52, 211, 153, 0.3); } | |
| .sadness { background-color: rgba(59, 130, 246, 0.3); } | |
| .anger { background-color: rgba(239, 68, 68, 0.3); } | |
| .fear { background-color: rgba(139, 92, 246, 0.3); } | |
| .surprise { background-color: rgba(249, 168, 37, 0.3); } | |
| .neutral { background-color: rgba(156, 163, 175, 0.3); } | |
| #radarChartContainer { | |
| position: relative; | |
| height: 300px; | |
| width: 100%; | |
| } | |
| .history-item { | |
| transition: all 0.3s ease; | |
| } | |
| .history-item:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); | |
| } | |
| .timeline-item { | |
| position: relative; | |
| padding-left: 30px; | |
| } | |
| .timeline-item:before { | |
| content: ''; | |
| position: absolute; | |
| left: 6px; | |
| top: 0; | |
| height: 100%; | |
| width: 2px; | |
| background: #e5e7eb; | |
| } | |
| .timeline-item:last-child:before { | |
| height: 50%; | |
| } | |
| .timeline-dot { | |
| position: absolute; | |
| left: 0; | |
| top: 0; | |
| width: 14px; | |
| height: 14px; | |
| border-radius: 50%; | |
| } | |
| .fade-in { | |
| animation: fadeIn 0.5s ease-in-out; | |
| } | |
| @keyframes fadeIn { | |
| from { opacity: 0; } | |
| to { opacity: 1; } | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-8"> | |
| <header class="text-center mb-12"> | |
| <h1 class="text-4xl font-bold text-indigo-700 mb-2">Prose Mood Tracker</h1> | |
| <p class="text-lg text-gray-600">understand your own writing emotionally</p> | |
| </header> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-8"> | |
| <!-- Input Section --> | |
| <div class="lg:col-span-2 bg-white rounded-xl shadow-md p-6"> | |
| <div class="flex items-center justify-between mb-4"> | |
| <h2 class="text-xl font-semibold text-gray-800">Express your feelings</h2> | |
| <div class="flex space-x-2"> | |
| <button id="clearBtn" class="px-3 py-1 bg-gray-200 text-gray-700 rounded-md hover:bg-gray-300 transition"> | |
| <i class="fas fa-eraser mr-1"></i> Clear | |
| </button> | |
| <button id="analyzeBtn" class="px-3 py-1 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 transition flex items-center"> | |
| <i class="fas fa-brain mr-1"></i> Analyze | |
| </button> | |
| </div> | |
| </div> | |
| <div id="textInput" contenteditable="true" class="w-full h-64 p-4 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent text-gray-700 overflow-auto"></div> | |
| <div class="mt-4 flex justify-between items-center"> | |
| <div class="text-sm text-gray-500"> | |
| <span id="wordCount">0</span> words | |
| </div> | |
| <div id="currentSentiment" class="px-3 py-1 rounded-full text-sm font-medium bg-gray-200 text-gray-800"> | |
| Ready for analysis | |
| </div> | |
| </div> | |
| <div id="loadingIndicator" class="hidden mt-4 p-4 bg-blue-50 rounded-lg text-blue-800 flex items-center"> | |
| <i class="fas fa-circle-notch fa-spin mr-2"></i> | |
| <span>Analyzing your emotions with DeepSeek AI...</span> | |
| </div> | |
| <div id="errorDisplay" class="hidden mt-4 p-4 bg-red-50 rounded-lg text-red-800"> | |
| <i class="fas fa-exclamation-circle mr-2"></i> | |
| <span id="errorMessage"></span> | |
| </div> | |
| </div> | |
| <!-- Visualization Section --> | |
| <div class="bg-white rounded-xl shadow-md p-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Emotional Spectrum</h2> | |
| <div id="radarChartContainer"> | |
| <canvas id="emotionRadar"></canvas> | |
| </div> | |
| <div class="mt-6"> | |
| <h3 class="font-medium text-gray-700 mb-2">Dominant Emotion</h3> | |
| <div id="dominantEmotion" class="text-2xl font-bold text-indigo-600">-</div> | |
| <div id="confidenceScore" class="text-sm text-gray-500">Confidence: -</div> | |
| </div> | |
| <div class="mt-6 grid grid-cols-2 gap-3"> | |
| <div class="bg-emerald-50 p-3 rounded-lg"> | |
| <div class="text-emerald-800 font-medium">Positivity</div> | |
| <div id="positivityScore" class="text-xl font-bold text-emerald-600">-</div> | |
| </div> | |
| <div class="bg-red-50 p-3 rounded-lg"> | |
| <div class="text-red-800 font-medium">Negativity</div> | |
| <div id="negativityScore" class="text-xl font-bold text-red-600">-</div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- History Section --> | |
| <div class="mt-12 bg-white rounded-xl shadow-md p-6"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Your Emotional Journey</h2> | |
| <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6"> | |
| <div class="bg-indigo-50 p-4 rounded-lg"> | |
| <div class="text-indigo-800 font-medium">Current State</div> | |
| <div id="overallMood" class="text-2xl font-bold text-indigo-600">-</div> | |
| <div class="text-sm text-indigo-600">based on recent analysis</div> | |
| </div> | |
| <div class="bg-emerald-50 p-4 rounded-lg"> | |
| <div class="text-emerald-800 font-medium">Positive Trend</div> | |
| <div id="positiveTrend" class="text-2xl font-bold text-emerald-600">0%</div> | |
| <div class="text-sm text-emerald-600">of your entries</div> | |
| </div> | |
| <div class="bg-red-50 p-4 rounded-lg"> | |
| <div class="text-red-800 font-medium">Negative Trend</div> | |
| <div id="negativeTrend" class="text-2xl font-bold text-red-600">0%</div> | |
| <div class="text-sm text-red-600">of your entries</div> | |
| </div> | |
| </div> | |
| <div class="flex space-x-4 mb-4"> | |
| <button id="showTimeline" class="px-3 py-1 bg-indigo-600 text-white rounded-md">Timeline</button> | |
| <button id="showList" class="px-3 py-1 bg-gray-200 text-gray-700 rounded-md">List View</button> | |
| </div> | |
| <div id="timelineView" class="space-y-4"> | |
| <!-- Timeline will be generated here --> | |
| </div> | |
| <div id="listView" class="hidden space-y-3 max-h-96 overflow-y-auto pr-2"> | |
| <!-- List items will be generated here --> | |
| <div class="text-center py-8 text-gray-400"> | |
| <i class="fas fa-history text-4xl mb-2"></i> | |
| <p>Your analysis history will appear here</p> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Modal for detailed view --> | |
| <div id="detailModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden"> | |
| <div class="bg-white rounded-xl p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto"> | |
| <div class="flex justify-between items-start mb-4"> | |
| <h3 class="text-xl font-semibold" id="modalTitle">Analysis Details</h3> | |
| <button id="closeModal" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div id="modalContent"> | |
| <!-- Content will be loaded here --> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| // Initialize variables | |
| let history = JSON.parse(localStorage.getItem('sentimentHistory')) || []; | |
| let radarChart = null; | |
| // DOM elements | |
| const textInput = document.getElementById('textInput'); | |
| const wordCount = document.getElementById('wordCount'); | |
| const currentSentiment = document.getElementById('currentSentiment'); | |
| const clearBtn = document.getElementById('clearBtn'); | |
| const analyzeBtn = document.getElementById('analyzeBtn'); | |
| const loadingIndicator = document.getElementById('loadingIndicator'); | |
| const errorDisplay = document.getElementById('errorDisplay'); | |
| const errorMessage = document.getElementById('errorMessage'); | |
| const dominantEmotion = document.getElementById('dominantEmotion'); | |
| const confidenceScore = document.getElementById('confidenceScore'); | |
| const positivityScore = document.getElementById('positivityScore'); | |
| const negativityScore = document.getElementById('negativityScore'); | |
| const overallMood = document.getElementById('overallMood'); | |
| const positiveTrend = document.getElementById('positiveTrend'); | |
| const negativeTrend = document.getElementById('negativeTrend'); | |
| const timelineView = document.getElementById('timelineView'); | |
| const listView = document.getElementById('listView'); | |
| const showTimeline = document.getElementById('showTimeline'); | |
| const showList = document.getElementById('showList'); | |
| const detailModal = document.getElementById('detailModal'); | |
| const closeModal = document.getElementById('closeModal'); | |
| const modalTitle = document.getElementById('modalTitle'); | |
| const modalContent = document.getElementById('modalContent'); | |
| // Event listeners | |
| textInput.addEventListener('input', updateWordCount); | |
| clearBtn.addEventListener('click', clearInput); | |
| analyzeBtn.addEventListener('click', analyzeWithDeepseek); | |
| showTimeline.addEventListener('click', () => { | |
| showTimeline.classList.add('bg-indigo-600', 'text-white'); | |
| showTimeline.classList.remove('bg-gray-200', 'text-gray-700'); | |
| showList.classList.add('bg-gray-200', 'text-gray-700'); | |
| showList.classList.remove('bg-indigo-600', 'text-white'); | |
| timelineView.classList.remove('hidden'); | |
| listView.classList.add('hidden'); | |
| }); | |
| showList.addEventListener('click', () => { | |
| showList.classList.add('bg-indigo-600', 'text-white'); | |
| showList.classList.remove('bg-gray-200', 'text-gray-700'); | |
| showTimeline.classList.add('bg-gray-200', 'text-gray-700'); | |
| showTimeline.classList.remove('bg-indigo-600', 'text-white'); | |
| listView.classList.remove('hidden'); | |
| timelineView.classList.add('hidden'); | |
| }); | |
| closeModal.addEventListener('click', () => { | |
| detailModal.classList.add('hidden'); | |
| }); | |
| // Initialize the app | |
| updateWordCount(); | |
| updateHistoryDisplay(); | |
| updateTrends(); | |
| initRadarChart(); | |
| // Functions | |
| function updateWordCount() { | |
| const text = textInput.innerText.trim(); | |
| const words = text.split(/\s+/).filter(word => word.length > 0); | |
| wordCount.textContent = words.length; | |
| } | |
| function clearInput() { | |
| textInput.innerHTML = ''; | |
| wordCount.textContent = '0'; | |
| currentSentiment.textContent = 'Ready for analysis'; | |
| currentSentiment.className = 'px-3 py-1 rounded-full text-sm font-medium bg-gray-200 text-gray-800'; | |
| errorDisplay.classList.add('hidden'); | |
| } | |
| async function analyzeWithDeepseek() { | |
| const text = textInput.innerText.trim(); | |
| if (text.length === 0) { | |
| showError('Please enter some text before analyzing.'); | |
| return; | |
| } | |
| // Show loading state | |
| loadingIndicator.classList.remove('hidden'); | |
| analyzeBtn.disabled = true; | |
| errorDisplay.classList.add('hidden'); | |
| try { | |
| // In a real implementation, you would call the DeepSeek API here | |
| // For this example, we'll simulate the API response | |
| const analysisResult = await simulateDeepseekAPI(text); | |
| // Process the results | |
| processAnalysisResults(text, analysisResult); | |
| // Save to history | |
| saveAnalysis(text, analysisResult); | |
| } catch (error) { | |
| showError(error.message || 'Failed to analyze text. Please try again.'); | |
| } finally { | |
| loadingIndicator.classList.add('hidden'); | |
| analyzeBtn.disabled = false; | |
| } | |
| } | |
| // Simulate DeepSeek API response | |
| async function simulateDeepseekAPI(text) { | |
| // In a real implementation, you would make an actual API call: | |
| /* | |
| const response = await fetch('https://api.deepseek.com/sentiment', { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': 'Bearer YOUR_API_KEY' | |
| }, | |
| body: JSON.stringify({ | |
| text: text, | |
| language: 'en', | |
| detailed: true | |
| }) | |
| }); | |
| if (!response.ok) { | |
| throw new Error('API request failed'); | |
| } | |
| return await response.json(); | |
| */ | |
| // Simulated response based on DeepSeek's capabilities | |
| return new Promise((resolve) => { | |
| setTimeout(() => { | |
| // Generate simulated sentiment analysis | |
| const wordCount = text.split(/\s+/).length; | |
| const emotions = ['joy', 'sadness', 'anger', 'fear', 'surprise', 'neutral']; | |
| // Generate random scores that sum to 1 (for demo purposes) | |
| const scores = {}; | |
| let remaining = 1; | |
| emotions.slice(0, -1).forEach(emotion => { | |
| scores[emotion] = Math.random() * remaining * 0.7; | |
| remaining -= scores[emotion]; | |
| }); | |
| scores[emotions[emotions.length - 1]] = remaining; | |
| // Determine dominant emotion | |
| let dominant = 'neutral'; | |
| let maxScore = 0; | |
| for (const [emotion, score] of Object.entries(scores)) { | |
| if (score > maxScore) { | |
| maxScore = score; | |
| dominant = emotion; | |
| } | |
| } | |
| // Generate sentiment scores | |
| const sentiment = { | |
| positive: scores['joy'] * 0.8 + (scores['surprise'] * 0.5), | |
| negative: scores['sadness'] + scores['anger'] + scores['fear'], | |
| neutral: scores['neutral'] | |
| }; | |
| // Normalize sentiment | |
| const sentimentSum = sentiment.positive + sentiment.negative + sentiment.neutral; | |
| sentiment.positive = (sentiment.positive / sentimentSum) * 100; | |
| sentiment.negative = (sentiment.negative / sentimentSum) * 100; | |
| sentiment.neutral = (sentiment.neutral / sentimentSum) * 100; | |
| resolve({ | |
| text: text, | |
| emotions: scores, | |
| dominant_emotion: dominant, | |
| confidence: maxScore, | |
| sentiment: sentiment, | |
| analyzed_at: new Date().toISOString(), | |
| word_count: wordCount, | |
| entities: extractEntities(text), | |
| keywords: extractKeywords(text) | |
| }); | |
| }, 1500); // Simulate API delay | |
| }); | |
| } | |
| function extractEntities(text) { | |
| // Simulate entity extraction | |
| const entities = []; | |
| const words = text.toLowerCase().split(/\s+/); | |
| // People (words starting with capital letters) | |
| const people = words.filter(word => word.length > 2 && word[0] === word[0].toUpperCase()); | |
| if (people.length > 0) { | |
| entities.push({ | |
| type: 'person', | |
| values: [...new Set(people)].slice(0, 3) | |
| }); | |
| } | |
| // Places | |
| const places = ['home', 'work', 'school', 'park', 'store', 'restaurant'] | |
| .filter(place => text.toLowerCase().includes(place)); | |
| if (places.length > 0) { | |
| entities.push({ | |
| type: 'place', | |
| values: places | |
| }); | |
| } | |
| // Activities | |
| const activities = ['running', 'eating', 'working', 'sleeping', 'reading', 'watching'] | |
| .filter(activity => text.toLowerCase().includes(activity)); | |
| if (activities.length > 0) { | |
| entities.push({ | |
| type: 'activity', | |
| values: activities | |
| }); | |
| } | |
| return entities; | |
| } | |
| function extractKeywords(text) { | |
| // Simulate keyword extraction | |
| const keywords = []; | |
| const words = text.toLowerCase().split(/\s+/); | |
| const meaningfulWords = words.filter(word => word.length > 3 && !['that', 'this', 'with', 'have', 'they'].includes(word)); | |
| // Take up to 5 unique words | |
| return [...new Set(meaningfulWords)].slice(0, 5); | |
| } | |
| function processAnalysisResults(text, result) { | |
| // Update current sentiment display | |
| const sentimentClass = getSentimentClass(result.dominant_emotion); | |
| currentSentiment.textContent = result.dominant_emotion.charAt(0).toUpperCase() + result.dominant_emotion.slice(1); | |
| currentSentiment.className = `px-3 py-1 rounded-full text-sm font-medium ${sentimentClass}`; | |
| // Update dominant emotion display | |
| dominantEmotion.textContent = result.dominant_emotion.charAt(0).toUpperCase() + result.dominant_emotion.slice(1); | |
| dominantEmotion.className = `text-2xl font-bold ${getTextColorClass(result.dominant_emotion)}`; | |
| confidenceScore.textContent = `Confidence: ${Math.round(result.confidence * 100)}%`; | |
| // Update sentiment scores | |
| positivityScore.textContent = `${Math.round(result.sentiment.positive)}%`; | |
| negativityScore.textContent = `${Math.round(result.sentiment.negative)}%`; | |
| // Update radar chart | |
| updateRadarChart(result.emotions); | |
| // Color code the text based on emotions | |
| colorCodeText(text, result.emotions); | |
| } | |
| function getSentimentClass(emotion) { | |
| const classes = { | |
| joy: 'bg-emerald-100 text-emerald-800', | |
| sadness: 'bg-blue-100 text-blue-800', | |
| anger: 'bg-red-100 text-red-800', | |
| fear: 'bg-purple-100 text-purple-800', | |
| surprise: 'bg-amber-100 text-amber-800', | |
| neutral: 'bg-gray-100 text-gray-800' | |
| }; | |
| return classes[emotion] || classes['neutral']; | |
| } | |
| function getTextColorClass(emotion) { | |
| const classes = { | |
| joy: 'text-emerald-600', | |
| sadness: 'text-blue-600', | |
| anger: 'text-red-600', | |
| fear: 'text-purple-600', | |
| surprise: 'text-amber-600', | |
| neutral: 'text-gray-600' | |
| }; | |
| return classes[emotion] || classes['neutral']; | |
| } | |
| function colorCodeText(text, emotions) { | |
| // This is a simplified version - in reality you'd need proper NLP | |
| // to determine which words contribute to which emotions | |
| // For demo purposes, we'll just highlight some random words | |
| const words = text.split(/(\s+)/); | |
| const emotionClasses = Object.keys(emotions); | |
| textInput.innerHTML = words.map(word => { | |
| if (word.trim().length === 0) return word; | |
| // Randomly assign an emotion class based on the emotion distribution | |
| const rand = Math.random(); | |
| let cumulative = 0; | |
| let selectedEmotion = 'neutral'; | |
| for (const emotion of emotionClasses) { | |
| cumulative += emotions[emotion]; | |
| if (rand <= cumulative) { | |
| selectedEmotion = emotion; | |
| break; | |
| } | |
| } | |
| return `<span class="sentiment-text ${selectedEmotion}">${word}</span>`; | |
| }).join(''); | |
| } | |
| function initRadarChart() { | |
| const ctx = document.getElementById('emotionRadar').getContext('2d'); | |
| radarChart = new Chart(ctx, { | |
| type: 'radar', | |
| data: { | |
| labels: ['Joy', 'Sadness', 'Anger', 'Fear', 'Surprise', 'Neutral'], | |
| datasets: [{ | |
| label: 'Emotion Intensity', | |
| data: [0, 0, 0, 0, 0, 0], | |
| backgroundColor: 'rgba(99, 102, 241, 0.2)', | |
| borderColor: 'rgba(99, 102, 241, 1)', | |
| borderWidth: 2, | |
| pointBackgroundColor: 'rgba(99, 102, 241, 1)', | |
| pointRadius: 4 | |
| }] | |
| }, | |
| options: { | |
| scales: { | |
| r: { | |
| angleLines: { | |
| display: true | |
| }, | |
| suggestedMin: 0, | |
| suggestedMax: 1, | |
| ticks: { | |
| display: false, | |
| stepSize: 0.2 | |
| } | |
| } | |
| }, | |
| plugins: { | |
| legend: { | |
| display: false | |
| } | |
| }, | |
| elements: { | |
| line: { | |
| tension: 0.1 | |
| } | |
| } | |
| } | |
| }); | |
| } | |
| function updateRadarChart(emotions) { | |
| radarChart.data.datasets[0].data = [ | |
| emotions.joy || 0, | |
| emotions.sadness || 0, | |
| emotions.anger || 0, | |
| emotions.fear || 0, | |
| emotions.surprise || 0, | |
| emotions.neutral || 0 | |
| ]; | |
| radarChart.update(); | |
| } | |
| function saveAnalysis(text, analysisResult) { | |
| const analysis = { | |
| text, | |
| dominant_emotion: analysisResult.dominant_emotion, | |
| confidence: analysisResult.confidence, | |
| emotions: analysisResult.emotions, | |
| sentiment: analysisResult.sentiment, | |
| entities: analysisResult.entities, | |
| keywords: analysisResult.keywords, | |
| date: new Date(analysisResult.analyzed_at).toLocaleString(), | |
| timestamp: new Date(analysisResult.analyzed_at).getTime() | |
| }; | |
| history.push(analysis); | |
| localStorage.setItem('sentimentHistory', JSON.stringify(history)); | |
| updateHistoryDisplay(); | |
| updateTrends(); | |
| // Show confirmation | |
| const confirmation = document.createElement('div'); | |
| confirmation.className = 'fixed bottom-4 right-4 bg-green-500 text-white px-4 py-2 rounded-lg shadow-lg flex items-center fade-in'; | |
| confirmation.innerHTML = ` | |
| <i class="fas fa-check-circle mr-2"></i> | |
| <span>Analysis saved successfully!</span> | |
| `; | |
| document.body.appendChild(confirmation); | |
| setTimeout(() => { | |
| confirmation.classList.add('opacity-0', 'transition-opacity', 'duration-500'); | |
| setTimeout(() => confirmation.remove(), 500); | |
| }, 2000); | |
| } | |
| function updateHistoryDisplay() { | |
| if (history.length === 0) { | |
| timelineView.innerHTML = ` | |
| <div class="text-center py-8 text-gray-400"> | |
| <i class="fas fa-history text-4xl mb-2"></i> | |
| <p>Your analysis history will appear here</p> | |
| </div> | |
| `; | |
| listView.innerHTML = ` | |
| <div class="text-center py-8 text-gray-400"> | |
| <i class="fas fa-history text-4xl mb-2"></i> | |
| <p>Your analysis history will appear here</p> | |
| </div> | |
| `; | |
| return; | |
| } | |
| // Update timeline view | |
| timelineView.innerHTML = history.slice().reverse().map((item, index) => { | |
| const date = new Date(item.timestamp); | |
| const timeStr = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); | |
| const dateStr = date.toLocaleDateString(); | |
| return ` | |
| <div class="timeline-item"> | |
| <div class="timeline-dot ${getDotColorClass(item.dominant_emotion)}"></div> | |
| <div class="bg-white p-4 rounded-lg border border-gray-200 hover:border-indigo-200 cursor-pointer" onclick="showAnalysisDetail(${history.length - 1 - index})"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <div class="font-medium ${getTextColorClass(item.dominant_emotion)}"> | |
| ${item.dominant_emotion.charAt(0).toUpperCase() + item.dominant_emotion.slice(1)} | |
| </div> | |
| <p class="text-gray-600 mt-1 text-sm line-clamp-2">${item.text}</p> | |
| </div> | |
| <div class="text-xs text-gray-500 whitespace-nowrap ml-2"> | |
| ${timeStr}<br>${dateStr} | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| }).join(''); | |
| // Update list view | |
| listView.innerHTML = history.slice().reverse().map((item, index) => { | |
| return ` | |
| <div class="history-item bg-white p-4 rounded-lg border border-gray-200 hover:border-indigo-200 cursor-pointer" onclick="showAnalysisDetail(${history.length - 1 - index})"> | |
| <div class="flex justify-between items-start"> | |
| <div> | |
| <span class="${getSentimentClass(item.dominant_emotion)} px-3 py-1 rounded-full text-sm font-medium"> | |
| ${item.dominant_emotion.charAt(0).toUpperCase() + item.dominant_emotion.slice(1)} | |
| </span> | |
| <p class="text-gray-600 mt-2 line-clamp-2">${item.text}</p> | |
| </div> | |
| <div class="text-sm text-gray-500 whitespace-nowrap ml-2">${item.date}</div> | |
| </div> | |
| <div class="flex mt-3 space-x-2"> | |
| <div class="text-xs bg-emerald-50 text-emerald-800 px-2 py-1 rounded">+${Math.round(item.sentiment.positive)}%</div> | |
| <div class="text-xs bg-gray-50 text-gray-800 px-2 py-1 rounded">~${Math.round(item.sentiment.neutral)}%</div> | |
| <div class="text-xs bg-red-50 text-red-800 px-2 py-1 rounded">-${Math.round(item.sentiment.negative)}%</div> | |
| </div> | |
| </div> | |
| `; | |
| }).join(''); | |
| } | |
| function getDotColorClass(emotion) { | |
| const classes = { | |
| joy: 'bg-emerald-400', | |
| sadness: 'bg-blue-400', | |
| anger: 'bg-red-400', | |
| fear: 'bg-purple-400', | |
| surprise: 'bg-amber-400', | |
| neutral: 'bg-gray-400' | |
| }; | |
| return classes[emotion] || classes['neutral']; | |
| } | |
| function showAnalysisDetail(index) { | |
| const item = history[index]; | |
| // Format emotions for display | |
| const emotionsHtml = Object.entries(item.emotions) | |
| .map(([emotion, score]) => ` | |
| <div class="flex justify-between py-1"> | |
| <span class="capitalize">${emotion}</span> | |
| <span class="font-medium">${Math.round(score * 100)}%</span> | |
| </div> | |
| `) | |
| .join(''); | |
| // Format entities if they exist | |
| let entitiesHtml = '<p class="text-gray-500 italic">No significant entities detected</p>'; | |
| if (item.entities && item.entities.length > 0) { | |
| entitiesHtml = item.entities.map(entity => ` | |
| <div class="mb-2"> | |
| <div class="font-medium capitalize">${entity.type}:</div> | |
| <div class="text-sm text-gray-700">${entity.values.join(', ')}</div> | |
| </div> | |
| `).join(''); | |
| } | |
| // Format keywords if they exist | |
| let keywordsHtml = '<p class="text-gray-500 italic">No keywords extracted</p>'; | |
| if (item.keywords && item.keywords.length > 0) { | |
| keywordsHtml = item.keywords.map(keyword => ` | |
| <span class="inline-block bg-gray-100 rounded-full px-3 py-1 text-sm font-medium text-gray-700 mr-2 mb-2"> | |
| ${keyword} | |
| </span> | |
| `).join(''); | |
| } | |
| // Set modal content | |
| modalTitle.textContent = `Analysis from ${item.date}`; | |
| modalContent.innerHTML = ` | |
| <div class="space-y-4"> | |
| <div> | |
| <h4 class="font-medium text-gray-700 mb-1">Text Analyzed</h4> | |
| <div class="bg-gray-50 p-3 rounded">${item.text}</div> | |
| </div> | |
| <div class="grid grid-cols-1 md:grid-cols-2 gap-4"> | |
| <div> | |
| <h4 class="font-medium text-gray-700 mb-1">Emotion Breakdown</h4> | |
| <div class="bg-gray-50 p-3 rounded"> | |
| ${emotionsHtml} | |
| </div> | |
| </div> | |
| <div> | |
| <h4 class="font-medium text-gray-700 mb-1">Sentiment Analysis</h4> | |
| <div class="bg-gray-50 p-3 rounded"> | |
| <div class="flex justify-between py-1"> | |
| <span>Positive</span> | |
| <span class="font-medium">${Math.round(item.sentiment.positive)}%</span> | |
| </div> | |
| <div class="flex justify-between py-1"> | |
| <span>Neutral</span> | |
| <span class="font-medium">${Math.round(item.sentiment.neutral)}%</span> | |
| </div> | |
| <div class="flex justify-between py-1"> | |
| <span>Negative</span> | |
| <span class="font-medium">${Math.round(item.sentiment.negative)}%</span> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <div> | |
| <h4 class="font-medium text-gray-700 mb-1">Detected Entities</h4> | |
| <div class="bg-gray-50 p-3 rounded"> | |
| ${entitiesHtml} | |
| </div> | |
| </div> | |
| <div> | |
| <h4 class="font-medium text-gray-700 mb-1">Key Phrases</h4> | |
| <div class="bg-gray-50 p-3 rounded"> | |
| ${keywordsHtml} | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| // Show modal | |
| detailModal.classList.remove('hidden'); | |
| } | |
| function updateTrends() { | |
| if (history.length === 0) { | |
| overallMood.textContent = '-'; | |
| positiveTrend.textContent = '0%'; | |
| negativeTrend.textContent = '0%'; | |
| return; | |
| } | |
| // Calculate overall mood based on last entry | |
| const lastEntry = history[history.length - 1]; | |
| overallMood.textContent = lastEntry.dominant_emotion.charAt(0).toUpperCase() + lastEntry.dominant_emotion.slice(1); | |
| overallMood.className = `text-2xl font-bold ${getTextColorClass(lastEntry.dominant_emotion)}`; | |
| // Calculate trends | |
| const positiveEntries = history.filter(item => item.sentiment.positive > item.sentiment.negative).length; | |
| const negativeEntries = history.filter(item => item.sentiment.negative > item.sentiment.positive).length; | |
| positiveTrend.textContent = `${Math.round((positiveEntries / history.length) * 100)}%`; | |
| negativeTrend.textContent = `${Math.round((negativeEntries / history.length) * 100)}%`; | |
| } | |
| function showError(message) { | |
| errorMessage.textContent = message; | |
| errorDisplay.classList.remove('hidden'); | |
| } | |
| // Make functions available globally for event handlers | |
| window.showAnalysisDetail = showAnalysisDetail; | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=physicswon/leap-demos" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |