File size: 9,600 Bytes
343bf49 |
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SmartLearn - Step-by-Step Explanations</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
.translate-link {
font-size: 14px;
color: #3498db;
cursor: pointer;
text-decoration: underline;
position: absolute;
right: 15px;
bottom: 10px;
}
.translate-link:hover {
color: #2980b9;
}
body {
font-family: 'Arial', sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
overflow: hidden;
}
#background-video {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -1;
}
.container {
background-color: rgba(255, 255, 255, 0.7);
backdrop-filter: blur(10px);
border-radius: 20px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
padding: 30px;
width: 90%;
max-width: 800px;
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
font-size: 2.5em;
}
.chat-container {
background-color: rgba(248, 249, 250, 0.8);
border-radius: 15px;
overflow: hidden;
}
.chat-messages {
height: 400px;
overflow-y: auto;
padding: 20px;
}
.message {
margin-bottom: 15px;
padding: 10px 15px;
border-radius: 20px;
max-width: 80%;
animation: fadeIn 0.5s;
word-wrap: break-word;
position: relative;
}
.user-message {
background-color: rgba(0, 123, 255, 0.8);
color: white;
align-self: flex-end;
margin-left: auto;
}
.ai-message {
background-color: rgba(21, 106, 192, 0.2);
color: #333;
}
.chat-input {
display: flex;
padding: 15px;
background-color: rgba(255, 255, 255, 0.8);
}
#user-input {
flex-grow: 1;
border: none;
padding: 10px 15px;
border-radius: 30px;
font-size: 16px;
background-color: rgba(241, 243, 245, 0.8);
}
button {
background-color: rgba(0, 123, 255, 0.8);
color: white;
border: none;
padding: 10px 20px;
border-radius: 30px;
cursor: pointer;
transition: background-color 0.3s;
font-size: 16px;
margin-left: 10px;
}
button:hover {
background-color: rgba(0, 86, 179, 0.8);
}
.back-button {
position: absolute;
top: 20px;
left: 20px;
background-color: rgba(108, 117, 125, 0.8);
}
.back-button:hover {
background-color: rgba(90, 98, 104, 0.8);
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.typing-animation {
display: inline-block;
white-space: pre-wrap;
word-wrap: break-word;
border-right: 2px solid #333;
padding-right: 2px;
max-width: 100%;
}
</style>
</head>
<body>
<video autoplay muted loop id="background-video">
<source src="../static/stepbystep.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
<div class="container">
<button class="back-button" onclick="goBack()"><i class="fas fa-arrow-left"></i> Back</button>
<h1><i class="fas fa-graduation-cap"></i> Step By Step Explanation</h1>
<div class="chat-container">
<div id="chat-messages" class="chat-messages">
<!-- Messages will be added here dynamically -->
</div>
<div class="chat-input">
<input type="text" id="user-input" placeholder="Ask your question here...">
<button onclick="sendMessage()"><i class="fas fa-paper-plane"></i> Send</button>
</div>
</div>
</div>
<script>
const chatMessages = document.getElementById('chat-messages');
const userInput = document.getElementById('user-input');
const initialMessage = "Hey there! I'm here to assist you. You can ask any question, and I'll explain it step by step to make it professional.";
function typeWriter(text, element, index = 0) {
if (index < text.length) {
element.innerHTML += text.charAt(index);
index++;
setTimeout(() => typeWriter(text, element, index), 10);
} else {
element.style.borderRight = 'none';
}
}
function addMessage(content, isUser) {
// Remove any existing typing animation
const existingTyping = chatMessages.querySelector('.typing-animation');
if (existingTyping) {
existingTyping.parentElement.remove();
}
const messageDiv = document.createElement('div');
messageDiv.className = `message ${isUser ? 'user-message' : 'ai-message'}`;
messageDiv.innerHTML = content.replace(/\n/g, '<br>');
if (!isUser) {
const translateLink = document.createElement('span');
translateLink.className = 'translate-link';
translateLink.textContent = 'Translate';
translateLink.onclick = function() {
translateMessage(messageDiv);
};
messageDiv.appendChild(translateLink);
}
chatMessages.appendChild(messageDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
if (!isUser) {
const typingSpan = document.createElement('span');
typingSpan.className = 'typing-animation';
typeWriter(content, typingSpan);
}
}
function showTypingIndicator() {
const typingDiv = document.createElement('div');
typingDiv.className = 'typing-indicator';
typingDiv.innerHTML = 'AI is typing<div class="dots"><div class="dot"></div><div class="dot"></div><div class="dot"></div></div>';
chatMessages.appendChild(typingDiv);
chatMessages.scrollTop = chatMessages.scrollHeight;
}
function hideTypingIndicator() {
const typingIndicator = document.querySelector('.typing-indicator');
if (typingIndicator) {
typingIndicator.remove();
}
}
function translateMessage(messageDiv) {
const text = messageDiv.textContent;
fetch('/translate', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ text: text })
})
.then(response => response.json())
.then(data => {
if (data.translated_text) {
messageDiv.innerHTML = data.translated_text;
}
})
.catch(error => {
console.error('Error:', error);
});
}
function sendMessage() {
const message = userInput.value.trim();
if (message) {
addMessage(message, true);
userInput.value = '';
showTypingIndicator();
fetch('/generate_step_by_step_explanation', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ question: message }),
})
.then(response => response.json())
.then(data => {
hideTypingIndicator();
addMessage(data.answer, false);
})
.catch(error => {
console.error('Error:', error);
hideTypingIndicator();
addMessage("Sorry, there was an error processing your request.", false);
});
}
}
userInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
sendMessage();
}
});
function goBack() {
window.history.back();
}
window.onload = function() {
addMessage(initialMessage, false);
};
</script>
</body>
</html> |