Keras
Ritikjain44's picture
Upload 9 files
72cab9b verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Emotion Detection</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f0f0;
text-align: center;
}
h1 {
margin-top: 30px;
color: #333;
}
#upload-form {
margin-top: 20px;
}
#result {
margin-top: 20px;
font-weight: bold;
}
#result.emotion-happy {
color: #00cc00;
}
#result.emotion-sad {
color: #3333ff;
}
#result.emotion-angry {
color: #cc0000;
}
#result.emotion-neutral {
color: #666666;
}
#result.emotion-surprise {
color: #ff9900;
}
input[type="file"] {
display: none;
}
.custom-file-upload {
display: inline-block;
padding: 10px 20px;
cursor: pointer;
background-color: #4CAF50;
color: white;
border-radius: 5px;
transition: background-color 0.3s;
}
.custom-file-upload:hover {
background-color: #45a049;
}
#uploaded-image {
margin-top: 20px;
max-width: 400px;
border-radius: 5px;
}
#upload-button {
display: none;
}
#reset-button {
margin-top: 20px;
padding: 10px 20px;
background-color: #f44336;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
#reset-button:hover {
background-color: #d32f2f;
}
</style>
</head>
<body>
<h1>Emotion Detection</h1>
<form id="upload-form" enctype="multipart/form-data">
<label for="image" class="custom-file-upload">
Choose File
</label>
<input type="file" id="image" name="image" accept="image/*" required>
<button id="upload-button" type="submit">Upload Image</button>
</form>
<div id="result"></div>
<img id="uploaded-image" src="#" alt="Uploaded Image">
<button id="reset-button">Reset</button>
<script>
document.getElementById('image').addEventListener('change', function(event) {
var fileInput = event.target;
var file = fileInput.files[0];
var uploadedImage = document.getElementById('uploaded-image');
var uploadButton = document.getElementById('upload-button');
if (file) {
uploadedImage.src = URL.createObjectURL(file);
uploadButton.style.display = 'inline-block';
} else {
uploadedImage.src = '#';
uploadButton.style.display = 'none';
}
});
document.getElementById('upload-form').addEventListener('submit', function(event) {
event.preventDefault();
var formData = new FormData(this);
fetch('/predict', {
method: 'POST',
body: formData
})
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
var resultDiv = document.getElementById('result');
resultDiv.innerText = 'Detected Emotion: ' + data.emotion;
resultDiv.className = 'emotion-' + data.emotion.toLowerCase();
})
.catch(error => {
var resultDiv = document.getElementById('result');
resultDiv.innerText = 'Error: ' + error.message;
resultDiv.className = '';
});
});
document.getElementById('reset-button').addEventListener('click', function(event) {
var form = document.getElementById('upload-form');
form.reset();
var uploadedImage = document.getElementById('uploaded-image');
uploadedImage.src = '#';
var resultDiv = document.getElementById('result');
resultDiv.innerText = '';
resultDiv.className = '';
var uploadButton = document.getElementById('upload-button');
uploadButton.style.display = 'none';
});
</script>
</body>
</html>