Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +91 -2
index.html
CHANGED
|
@@ -275,8 +275,97 @@
|
|
| 275 |
}
|
| 276 |
|
| 277 |
// --- TODAS AS OUTRAS FUNÇÕES (sem alterações) ---
|
| 278 |
-
async function generateActivity() {
|
| 279 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
function initializeSpeechRecognition() { /* ... */ }
|
| 281 |
function handleVoiceInput() { /* ... */ }
|
| 282 |
function handleTextInput() { /* ... */ }
|
|
|
|
| 275 |
}
|
| 276 |
|
| 277 |
// --- TODAS AS OUTRAS FUNÇÕES (sem alterações) ---
|
| 278 |
+
async function generateActivity() {
|
| 279 |
+
const activityType = activityTypeSelector.value;
|
| 280 |
+
const context = contextSelector.value;
|
| 281 |
+
const sourceText = textEditor.innerText;
|
| 282 |
+
generateActivityButton.disabled = true;
|
| 283 |
+
generateActivityButton.innerHTML = '<div class="spinner mr-2"></div> Generating...';
|
| 284 |
+
activityChatDisplay.innerHTML = '<p class="text-gray-500 italic">Generating your exercise...</p>';
|
| 285 |
+
activityResponseArea.classList.add('hidden');
|
| 286 |
+
let prompt = "";
|
| 287 |
+
if (activityType === 'translate_pt_en') {
|
| 288 |
+
prompt = `Based on the '${context}' context, create one single sentence in Portuguese for me to translate into English.`;
|
| 289 |
+
} else if (activityType === 'email_writing') {
|
| 290 |
+
prompt = `Create a scenario for me to write a formal email, related to the '${context}' context. Give me clear instructions on what to write.`;
|
| 291 |
+
} else if (activityType === 'summary_writing') {
|
| 292 |
+
if (!sourceText) {
|
| 293 |
+
alert("Please paste text in the main editor to generate a summary activity.");
|
| 294 |
+
activityChatDisplay.innerHTML = '<p class="text-red-500">Please paste text in the editor in card #1 first.</p>';
|
| 295 |
+
generateActivityButton.disabled = false;
|
| 296 |
+
generateActivityButton.textContent = 'Generate Activity';
|
| 297 |
+
return;
|
| 298 |
+
}
|
| 299 |
+
prompt = `Your task is to summarize the following text in 2 or 3 sentences: "${sourceText}"`;
|
| 300 |
+
} else if (activityType === 'professional_conversation') {
|
| 301 |
+
prompt = `Start a professional role-playing conversation with me related to '${context}'. Ask me an open-ended question to begin.`;
|
| 302 |
+
}
|
| 303 |
+
try {
|
| 304 |
+
const response = await fetch('/explain-proxy', {
|
| 305 |
+
method: 'POST',
|
| 306 |
+
headers: { 'Content-Type': 'application/json' },
|
| 307 |
+
body: JSON.stringify({
|
| 308 |
+
model: modelSelector.value,
|
| 309 |
+
context_focus: context,
|
| 310 |
+
custom_prompt: prompt
|
| 311 |
+
})
|
| 312 |
+
});
|
| 313 |
+
if (!response.ok) throw new Error((await response.json()).error);
|
| 314 |
+
const data = await response.json();
|
| 315 |
+
currentActivityPrompt = data.explanation;
|
| 316 |
+
activityChatDisplay.innerHTML = `<div class="ai-prompt"><strong>Your Task:</strong><p>${currentActivityPrompt}</p></div>`;
|
| 317 |
+
activityResponseArea.classList.remove('hidden');
|
| 318 |
+
} catch (error) {
|
| 319 |
+
activityChatDisplay.innerHTML = `<p class="text-red-600 font-semibold">Failed to generate activity: ${error.message}</p>`;
|
| 320 |
+
} finally {
|
| 321 |
+
generateActivityButton.disabled = false;
|
| 322 |
+
generateActivityButton.textContent = 'Generate Activity';
|
| 323 |
+
}
|
| 324 |
+
}
|
| 325 |
+
async function submitActivityResponse() {
|
| 326 |
+
const userResponse = activityInput.value.trim();
|
| 327 |
+
if (!userResponse) {
|
| 328 |
+
alert("Please write a response.");
|
| 329 |
+
return;
|
| 330 |
+
}
|
| 331 |
+
submitActivityBtn.disabled = true;
|
| 332 |
+
submitActivityBtn.innerHTML = '<div class="spinner mr-2"></div> Getting Feedback...';
|
| 333 |
+
const oldFeedback = activityChatDisplay.querySelector('.ai-feedback');
|
| 334 |
+
if(oldFeedback) oldFeedback.remove();
|
| 335 |
+
const oldResponse = activityChatDisplay.querySelector('.user-response-display');
|
| 336 |
+
if(oldResponse) oldResponse.remove();
|
| 337 |
+
const userResponseDiv = document.createElement('div');
|
| 338 |
+
userResponseDiv.className = 'user-response-display';
|
| 339 |
+
userResponseDiv.innerHTML = `<strong>Your Response:</strong><p>${userResponse}</p>`;
|
| 340 |
+
activityChatDisplay.appendChild(userResponseDiv);
|
| 341 |
+
try {
|
| 342 |
+
const response = await fetch('/activity-feedback', {
|
| 343 |
+
method: 'POST',
|
| 344 |
+
headers: { 'Content-Type': 'application/json' },
|
| 345 |
+
body: JSON.stringify({
|
| 346 |
+
model: modelSelector.value,
|
| 347 |
+
context_focus: contextSelector.value,
|
| 348 |
+
original_prompt: currentActivityPrompt,
|
| 349 |
+
user_response: userResponse
|
| 350 |
+
})
|
| 351 |
+
});
|
| 352 |
+
if (!response.ok) throw new Error((await response.json()).error);
|
| 353 |
+
const data = await response.json();
|
| 354 |
+
const feedbackDiv = document.createElement('div');
|
| 355 |
+
feedbackDiv.className = 'ai-feedback';
|
| 356 |
+
feedbackDiv.innerHTML = `<strong>Feedback:</strong><div class="prose prose-sm max-w-none">${marked.parse(data.feedback)}</div>`;
|
| 357 |
+
activityChatDisplay.appendChild(feedbackDiv);
|
| 358 |
+
activityInput.value = '';
|
| 359 |
+
} catch (error) {
|
| 360 |
+
const errorDiv = document.createElement('div');
|
| 361 |
+
errorDiv.className = 'ai-feedback';
|
| 362 |
+
errorDiv.innerHTML = `<p class="text-red-600 font-semibold">Failed to get feedback: ${error.message}</p>`;
|
| 363 |
+
activityChatDisplay.appendChild(errorDiv);
|
| 364 |
+
} finally {
|
| 365 |
+
submitActivityBtn.disabled = false;
|
| 366 |
+
submitActivityBtn.textContent = 'Submit Answer';
|
| 367 |
+
}
|
| 368 |
+
}
|
| 369 |
function initializeSpeechRecognition() { /* ... */ }
|
| 370 |
function handleVoiceInput() { /* ... */ }
|
| 371 |
function handleTextInput() { /* ... */ }
|