Team Sentiment Analysis Tool

Team Sentiment Analysis Tool

Paste team feedback, survey results, or chat logs to analyze overall sentiment.

Input Text

Analysis Results

Your analysis will appear here after you submit text.

Analysis failed. Please try again.
${error.message}

`; emptyState.classList.remove('hidden'); } finally { // Restore UI loadingState.classList.add('hidden'); analyzeBtn.disabled = false; } }; const getAISentiment = async (text) => { const apiKey = ""; // Per instructions, leave empty const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const prompt = `Analyze the sentiment of the following text. Provide a JSON object with the following structure: { "sentiment": "Positive", "Neutral", or "Negative", "score": an integer between 0 and 100, "themes": an array of 3-5 key themes as strings, "key_phrases": an array of 3-5 important phrases from the text that justify the sentiment. } Text to analyze: --- ${text} ---`; const payload = { contents: [{ role: "user", parts: [{ text: prompt }] }], generationConfig: { responseMimeType: "application/json" } }; const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { throw new Error(`API Error: ${response.statusText}`); } const result = await response.json(); const jsonString = result.candidates[0].content.parts[0].text; return JSON.parse(jsonString); }; const renderResults = (data) => { // Overall Sentiment const sentiment = data.sentiment.toLowerCase(); overallSentimentEl.textContent = data.sentiment; overallSentimentEl.className = `sentiment-badge sentiment-${sentiment}`; // Sentiment Score sentimentScoreTextEl.textContent = `${data.score} / 100`; sentimentScoreBarEl.style.width = `${data.score}%`; if (sentiment === 'positive') sentimentScoreBarEl.className = 'h-4 rounded-full bg-green-500'; else if (sentiment === 'neutral') sentimentScoreBarEl.className = 'h-4 rounded-full bg-slate-400'; else sentimentScoreBarEl.className = 'h-4 rounded-full bg-red-500'; // Key Themes keyThemesEl.innerHTML = data.themes.map(theme => `
  • ${theme}
  • `).join(''); // Key Phrases keyPhrasesEl.innerHTML = data.key_phrases.map(phrase => `

    "${phrase}"

    `).join(''); resultsContent.classList.remove('hidden'); }; const generatePDF = async () => { if (!analysisData) { alert("Please analyze some text before downloading a report."); return; } const reportElement = document.getElementById('resultsPanel'); if (!reportElement) { console.error("Results panel element not found for PDF generation."); return; } const originalButtonText = downloadPdfBtn.innerHTML; downloadPdfBtn.innerHTML = 'Generating...'; downloadPdfBtn.disabled = true; try { const canvas = await html2canvas(reportElement, { scale: 2, backgroundColor: '#ffffff', useCORS: true, }); const imgData = canvas.toDataURL('image/png'); if (!imgData || imgData === 'data:,') { throw new Error("html2canvas failed to generate a valid image."); } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = doc.internal.pageSize.getWidth(); const pdfHeight = doc.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth; const imgHeight = pdfWidth / ratio; let heightLeft = imgHeight; let position = 0; doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pdfHeight; while (heightLeft > 0) { position -= pdfHeight; doc.addPage(); doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight); heightLeft -= pdfHeight; } doc.save('sentiment-analysis-report.pdf'); } catch (error) { console.error("PDF generation failed:", error); alert("Sorry, there was an error creating the PDF. Please try again."); } finally { downloadPdfBtn.innerHTML = originalButtonText; downloadPdfBtn.disabled = false; } }; // Event Listeners analyzeBtn.addEventListener('click', handleAnalysis); downloadPdfBtn.addEventListener('click', generatePDF); });
    Scroll to Top