Shreyas Pulle
Upload 9 files
5ac332c verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How Am I Feeling? - AI Emotion Detector</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 30px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
max-width: 800px;
width: 100%;
padding: 50px;
animation: fadeIn 0.5s ease-in;
}
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.header {
text-align: center;
margin-bottom: 40px;
}
h1 {
font-size: 3em;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
margin-bottom: 10px;
animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse {
0%, 100% {
transform: scale(1);
}
50% {
transform: scale(1.02);
}
}
.subtitle {
color: #666;
font-size: 1.2em;
margin-bottom: 10px;
}
.tagline {
color: #999;
font-size: 0.95em;
font-style: italic;
}
.input-section {
margin-bottom: 30px;
}
textarea {
width: 100%;
min-height: 150px;
padding: 20px;
border: 2px solid #e0e0e0;
border-radius: 15px;
font-size: 1.1em;
font-family: inherit;
resize: vertical;
transition: all 0.3s ease;
}
textarea:focus {
outline: none;
border-color: #667eea;
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}
.button-container {
display: flex;
gap: 15px;
margin-bottom: 30px;
}
button {
flex: 1;
padding: 18px 30px;
font-size: 1.1em;
font-weight: 600;
border: none;
border-radius: 15px;
cursor: pointer;
transition: all 0.3s ease;
font-family: inherit;
}
.analyze-btn {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
}
.analyze-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 25px rgba(102, 126, 234, 0.4);
}
.analyze-btn:active {
transform: translateY(0);
}
.clear-btn {
background: #f0f0f0;
color: #666;
}
.clear-btn:hover {
background: #e0e0e0;
}
.loading {
text-align: center;
padding: 30px;
display: none;
}
.loading.active {
display: block;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #667eea;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
margin: 0 auto 15px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.results {
display: none;
}
.results.active {
display: block;
animation: slideIn 0.5s ease-out;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateX(-20px);
}
to {
opacity: 1;
transform: translateX(0);
}
}
.results-header {
font-size: 1.5em;
color: #333;
margin-bottom: 25px;
text-align: center;
}
.emotion-card {
background: white;
border-radius: 15px;
padding: 20px;
margin-bottom: 15px;
border: 2px solid #f0f0f0;
transition: all 0.3s ease;
cursor: pointer;
}
.emotion-card:hover {
transform: translateX(5px);
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}
.emotion-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 12px;
}
.emotion-name {
display: flex;
align-items: center;
gap: 12px;
font-size: 1.3em;
font-weight: 600;
text-transform: capitalize;
}
.emotion-emoji {
font-size: 1.8em;
}
.emotion-percentage {
font-size: 1.5em;
font-weight: 700;
}
.progress-bar-container {
background: #f0f0f0;
border-radius: 10px;
height: 12px;
overflow: hidden;
}
.progress-bar {
height: 100%;
border-radius: 10px;
transition: width 0.8s ease-out;
animation: fillBar 0.8s ease-out;
}
@keyframes fillBar {
from {
width: 0;
}
}
.error {
background: #fee;
border: 2px solid #fcc;
color: #c33;
padding: 20px;
border-radius: 15px;
text-align: center;
display: none;
}
.error.active {
display: block;
animation: shake 0.5s ease-in-out;
}
@keyframes shake {
0%, 100% { transform: translateX(0); }
25% { transform: translateX(-10px); }
75% { transform: translateX(10px); }
}
.examples {
margin-top: 40px;
padding-top: 30px;
border-top: 2px solid #f0f0f0;
}
.examples-title {
font-size: 1.2em;
color: #666;
margin-bottom: 15px;
text-align: center;
}
.example-buttons {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
}
.example-btn {
padding: 10px 20px;
background: #f8f8f8;
border: 2px solid #e0e0e0;
border-radius: 20px;
font-size: 0.9em;
cursor: pointer;
transition: all 0.3s ease;
color: #666;
}
.example-btn:hover {
background: #667eea;
color: white;
border-color: #667eea;
transform: translateY(-2px);
}
.footer {
text-align: center;
margin-top: 40px;
padding-top: 20px;
border-top: 2px solid #f0f0f0;
color: #999;
font-size: 0.9em;
}
.models-warning {
background: #fff3cd;
border: 2px solid #ffc107;
color: #856404;
padding: 20px;
border-radius: 15px;
text-align: center;
margin-bottom: 30px;
}
@media (max-width: 600px) {
.container {
padding: 30px 20px;
}
h1 {
font-size: 2em;
}
.button-container {
flex-direction: column;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>How Am I Feeling?</h1>
<p class="subtitle">AI-Powered Emotion Detection</p>
<p class="tagline">Discover the emotions hidden in your words</p>
</div>
{% if not models_loaded %}
<div class="models-warning">
<strong>⚠️ Models Not Loaded</strong><br>
Please run the training scripts (02-06.py) to train the models first.
</div>
{% endif %}
<div class="input-section">
<textarea
id="textInput"
placeholder="Type or paste your text here... How are you feeling today?"
{% if not models_loaded %}disabled{% endif %}
></textarea>
</div>
<div class="button-container">
<button class="analyze-btn" onclick="analyzeText()" {% if not models_loaded %}disabled{% endif %}>
✨ Analyze My Emotions
</button>
<button class="clear-btn" onclick="clearAll()">
🔄 Clear
</button>
</div>
<div class="error" id="error"></div>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>Analyzing your emotions...</p>
</div>
<div class="results" id="results"></div>
<div class="examples">
<p class="examples-title">💡 Try these examples:</p>
<div class="example-buttons">
<button class="example-btn" onclick="tryExample('I am so excited about the weekend! Can\'t wait to see everyone!')">Excited</button>
<button class="example-btn" onclick="tryExample('I miss my family and feel so alone in this new city.')">Lonely</button>
<button class="example-btn" onclick="tryExample('I can\'t believe they would do this to me! This is unacceptable!')">Angry</button>
<button class="example-btn" onclick="tryExample('I love spending time with you. You make everything better.')">Loving</button>
<button class="example-btn" onclick="tryExample('I\'m really worried about the exam tomorrow. What if I fail?')">Anxious</button>
<button class="example-btn" onclick="tryExample('Today has been absolutely wonderful! Everything went perfectly!')">Happy</button>
</div>
</div>
<div class="footer">
<p>Powered by Word2Vec + Neural Network | Trained on 100K emotion-labeled sentences</p>
<p style="margin-top: 8px; font-size: 0.85em;">
Built with 💜 |
<a href="https://github.com" style="color: #667eea; text-decoration: none;">View on GitHub</a>
</p>
</div>
</div>
<script>
async function analyzeText() {
const text = document.getElementById('textInput').value.trim();
const loading = document.getElementById('loading');
const results = document.getElementById('results');
const error = document.getElementById('error');
// Clear previous results
results.classList.remove('active');
error.classList.remove('active');
if (!text) {
showError('Please enter some text to analyze!');
return;
}
// Show loading
loading.classList.add('active');
try {
const response = await fetch('/analyze', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: text })
});
const data = await response.json();
loading.classList.remove('active');
if (data.error) {
showError(data.error);
return;
}
displayResults(data.predictions);
} catch (err) {
loading.classList.remove('active');
showError('An error occurred. Please try again.');
console.error(err);
}
}
function displayResults(predictions) {
const results = document.getElementById('results');
let html = '<h2 class="results-header">🎭 Your Emotions Detected</h2>';
predictions.forEach((pred, index) => {
html += `
<div class="emotion-card" style="animation-delay: ${index * 0.1}s">
<div class="emotion-header">
<div class="emotion-name">
<span class="emotion-emoji">${pred.emoji}</span>
<span style="color: ${pred.color}">${pred.emotion}</span>
</div>
<div class="emotion-percentage" style="color: ${pred.color}">
${pred.percentage}%
</div>
</div>
<div class="progress-bar-container">
<div class="progress-bar"
style="width: ${pred.percentage}%; background: ${pred.gradient}">
</div>
</div>
</div>
`;
});
results.innerHTML = html;
results.classList.add('active');
}
function showError(message) {
const error = document.getElementById('error');
error.textContent = message;
error.classList.add('active');
setTimeout(() => {
error.classList.remove('active');
}, 5000);
}
function clearAll() {
document.getElementById('textInput').value = '';
document.getElementById('results').classList.remove('active');
document.getElementById('error').classList.remove('active');
document.getElementById('textInput').focus();
}
function tryExample(text) {
document.getElementById('textInput').value = text;
document.getElementById('textInput').focus();
// Auto-analyze after a short delay
setTimeout(() => analyzeText(), 300);
}
// Allow Enter + Ctrl/Cmd to submit
document.getElementById('textInput').addEventListener('keydown', function(e) {
if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
analyzeText();
}
});
// Auto-focus on text input
window.addEventListener('load', () => {
document.getElementById('textInput').focus();
});
</script>
</body>
</html>