Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +25 -12
index.html
CHANGED
|
@@ -176,21 +176,23 @@
|
|
| 176 |
</div>
|
| 177 |
|
| 178 |
<div class="card mb-6">
|
| 179 |
-
<h2 class="text-xl font-semibold mb-4 text-gray-700">
|
| 180 |
-
<div class="grid grid-cols-1 md:grid-cols-
|
| 181 |
|
| 182 |
-
<!--
|
| 183 |
-
<div>
|
| 184 |
-
<label for="
|
| 185 |
-
<select id="
|
| 186 |
-
<
|
| 187 |
-
<option value="
|
|
|
|
|
|
|
| 188 |
</select>
|
| 189 |
</div>
|
| 190 |
|
| 191 |
<!-- Speed Control -->
|
| 192 |
<div>
|
| 193 |
-
<label for="speedSelector" class="block text-sm font-medium text-gray-700">Speaking Rate</label>
|
| 194 |
<select id="speedSelector" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md shadow-sm">
|
| 195 |
<option value="1.0">Normal (1.0x)</option>
|
| 196 |
<option value="0.75">Slow (0.75x)</option>
|
|
@@ -280,6 +282,7 @@
|
|
| 280 |
const flashcardList = document.getElementById('flashcardList');
|
| 281 |
const noCardsMessage = document.getElementById('noCardsMessage');
|
| 282 |
const speedSelector = document.getElementById('speedSelector');
|
|
|
|
| 283 |
|
| 284 |
const MAX_CHARS = 5000;
|
| 285 |
let isLooping = false;
|
|
@@ -418,22 +421,32 @@
|
|
| 418 |
const spinner = isFlashcard ? document.getElementById('cardSpinner') : document.getElementById('explanationSpinner');
|
| 419 |
const explanationText = isFlashcard ? null : document.getElementById('explanationText');
|
| 420 |
const translationText = isFlashcard ? null : document.getElementById('translationText');
|
|
|
|
|
|
|
| 421 |
|
| 422 |
if (!isFlashcard) {
|
|
|
|
| 423 |
explanationText.textContent = '';
|
| 424 |
translationText.textContent = '';
|
| 425 |
}
|
| 426 |
spinner.classList.remove('hidden');
|
| 427 |
|
| 428 |
try {
|
|
|
|
| 429 |
const response = await fetch('/explain-proxy', {
|
| 430 |
method: 'POST',
|
| 431 |
headers: { 'Content-Type': 'application/json' },
|
| 432 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 433 |
});
|
| 434 |
|
| 435 |
if (!response.ok) {
|
| 436 |
-
const errorMsg = `HTTP Error: ${response.status}. Check if GEMINI_API_KEY is configured in your Space.`;
|
| 437 |
throw new Error(errorMsg);
|
| 438 |
}
|
| 439 |
|
|
@@ -449,7 +462,7 @@
|
|
| 449 |
|
| 450 |
} catch (error) {
|
| 451 |
console.error('Error fetching context from AI:', error);
|
| 452 |
-
const msg =
|
| 453 |
if (!isFlashcard) {
|
| 454 |
explanationText.textContent = msg;
|
| 455 |
translationText.textContent = msg;
|
|
|
|
| 176 |
</div>
|
| 177 |
|
| 178 |
<div class="card mb-6">
|
| 179 |
+
<h2 class="text-xl font-semibold mb-4 text-gray-700">LLM and Audio Controls</h2>
|
| 180 |
+
<div class="grid grid-cols-1 md:grid-cols-4 gap-4 mb-4">
|
| 181 |
|
| 182 |
+
<!-- LLM Provider Selector -->
|
| 183 |
+
<div class="md:col-span-2">
|
| 184 |
+
<label for="modelSelector" class="block text-sm font-medium text-gray-700">AI Model Provider (Context/Translation)</label>
|
| 185 |
+
<select id="modelSelector" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md shadow-sm">
|
| 186 |
+
<!-- Format: provider:model-name -->
|
| 187 |
+
<option value="gemini:gemini-2.5-flash">Google Gemini (Free Tier)</option>
|
| 188 |
+
<option value="groq:mixtral-8x7b-32768">Groq (Mixtral 8x7b - Fast)</option>
|
| 189 |
+
<option value="groq:llama3-8b-8192">Groq (Llama 3 8B)</option>
|
| 190 |
</select>
|
| 191 |
</div>
|
| 192 |
|
| 193 |
<!-- Speed Control -->
|
| 194 |
<div>
|
| 195 |
+
<label for="speedSelector" class="block text-sm font-medium text-gray-700">Speaking Rate (gTTS)</label>
|
| 196 |
<select id="speedSelector" class="mt-1 block w-full pl-3 pr-10 py-2 text-base border-gray-300 focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm rounded-md shadow-sm">
|
| 197 |
<option value="1.0">Normal (1.0x)</option>
|
| 198 |
<option value="0.75">Slow (0.75x)</option>
|
|
|
|
| 282 |
const flashcardList = document.getElementById('flashcardList');
|
| 283 |
const noCardsMessage = document.getElementById('noCardsMessage');
|
| 284 |
const speedSelector = document.getElementById('speedSelector');
|
| 285 |
+
const modelSelector = document.getElementById('modelSelector'); // New Selector
|
| 286 |
|
| 287 |
const MAX_CHARS = 5000;
|
| 288 |
let isLooping = false;
|
|
|
|
| 421 |
const spinner = isFlashcard ? document.getElementById('cardSpinner') : document.getElementById('explanationSpinner');
|
| 422 |
const explanationText = isFlashcard ? null : document.getElementById('explanationText');
|
| 423 |
const translationText = isFlashcard ? null : document.getElementById('translationText');
|
| 424 |
+
|
| 425 |
+
const modelValue = modelSelector.value;
|
| 426 |
|
| 427 |
if (!isFlashcard) {
|
| 428 |
+
// Show loading state in modal
|
| 429 |
explanationText.textContent = '';
|
| 430 |
translationText.textContent = '';
|
| 431 |
}
|
| 432 |
spinner.classList.remove('hidden');
|
| 433 |
|
| 434 |
try {
|
| 435 |
+
// Route for the backend using Gemini/Groq for explanation/translation
|
| 436 |
const response = await fetch('/explain-proxy', {
|
| 437 |
method: 'POST',
|
| 438 |
headers: { 'Content-Type': 'application/json' },
|
| 439 |
+
// Sends the clicked word, context, and the selected model
|
| 440 |
+
body: JSON.stringify({
|
| 441 |
+
word: word,
|
| 442 |
+
context: context,
|
| 443 |
+
for_flashcard: isFlashcard,
|
| 444 |
+
model: modelValue // NEW: Passes provider:model-name
|
| 445 |
+
})
|
| 446 |
});
|
| 447 |
|
| 448 |
if (!response.ok) {
|
| 449 |
+
const errorMsg = `HTTP Error: ${response.status}. Check if GEMINI_API_KEY/GROQ_API_KEY is configured in your Space for the selected model.`;
|
| 450 |
throw new Error(errorMsg);
|
| 451 |
}
|
| 452 |
|
|
|
|
| 462 |
|
| 463 |
} catch (error) {
|
| 464 |
console.error('Error fetching context from AI:', error);
|
| 465 |
+
const msg = `AI analysis failed. Error: ${error.message}`;
|
| 466 |
if (!isFlashcard) {
|
| 467 |
explanationText.textContent = msg;
|
| 468 |
translationText.textContent = msg;
|