File size: 4,674 Bytes
72cab9b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
<!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>
|