NHLOCAL commited on
Commit
2ad4451
·
1 Parent(s): b4402e1

שיפור: כפתור לעורך הכתוביות, ניסוח ועיצוב קל

Browse files
Files changed (1) hide show
  1. templates/index.html +37 -55
templates/index.html CHANGED
@@ -10,6 +10,8 @@
10
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
  <link href="https://fonts.googleapis.com/css2?family=Assistant:wght@300;400;600;700&display=swap" rel="stylesheet">
12
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
 
 
13
 
14
  <style>
15
  :root {
@@ -55,13 +57,13 @@
55
  .file-input-wrapper input[type="file"] { display: none; }
56
  .file-name { margin-top: 1rem; font-weight: 600; color: var(--md-sys-color-secondary); }
57
  #results-section { display: none; margin-top: 2rem; }
58
- .results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
59
  .results-header h2 { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
60
  .view-toggle { display: flex; border: 1px solid var(--md-sys-color-outline); border-radius: 99px; overflow: hidden; }
61
  .view-btn { background: transparent; border: none; padding: 6px 16px; cursor: pointer; font-weight: 600; font-family: 'Assistant', sans-serif; font-size: 0.9rem; color: var(--md-sys-color-primary); transition: all 0.2s ease-in-out; }
62
  .view-btn.active { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
63
- #results-output { width: 100%; height: 300px; padding: 1rem; border: 1px solid var(--md-sys-color-outline); border-radius: var(--border-radius-small); font-family: monospace; background-color: var(--md-sys-color-surface); font-size: 0.9rem; resize: vertical; }
64
- .buttons-container { display: flex; gap: 1rem; margin-top: 1rem; justify-content: center; }
65
  #status-container { margin-top: 1.5rem; display: none; }
66
  #status-message { text-align: center; padding: 1rem; font-weight: 600; border-radius: var(--border-radius-small) var(--border-radius-small) 0 0; }
67
  #status-message.loading { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
@@ -73,8 +75,8 @@
73
  footer a { color: var(--md-sys-color-primary); text-decoration: none; font-weight: 600; }
74
  footer a:hover { text-decoration: underline; }
75
  .github-link { margin-left: 8px; vertical-align: middle; display: inline-flex; align-items: center; justify-content: center; }
76
- .github-link svg { width: 16px; height: 16px; fill: var(--md-sys-color-primary); transition: fill 0.2s ease-in-out; }
77
- .github-link:hover svg { fill: #5a3f92; }
78
  </style>
79
  </head>
80
  <body>
@@ -125,7 +127,7 @@
125
  <span class="material-symbols-outlined">rocket_launch</span> התחל תמלול
126
  </button>
127
  <a href="https://tools.ze-kal.top/tools/subtitle_editor.html" target="_blank" class="btn btn-secondary" title="עריכה, סנכרון ותיקון של קובץ כתוביות קיים" style="padding: 16px 32px; font-size: 1.2rem;">
128
- <span class="material-symbols-outlined">edit_note</span> עריכת כתוביות
129
  </a>
130
  </div>
131
  </form>
@@ -158,17 +160,20 @@
158
  <div class="results-header">
159
  <h2>תוצאות התמלול</h2>
160
  <div class="view-toggle">
161
- <button id="view-srt-btn" class="view-btn">SRT</button>
162
  <button id="view-txt-btn" class="view-btn">טקסט</button>
163
  </div>
164
  </div>
165
  <textarea id="results-output" readonly></textarea>
166
  <div class="buttons-container">
167
  <a id="download-srt-button" class="btn btn-primary">
168
- <span class="material-symbols-outlined">download</span> הורד קובץ SRT
169
  </a>
 
 
 
170
  <a id="download-txt-button" class="btn btn-secondary">
171
- <span class="material-symbols-outlined">article</span> הורד קובץ טקסט
172
  </a>
173
  </div>
174
  </section>
@@ -177,7 +182,6 @@
177
 
178
  <script>
179
  document.addEventListener('DOMContentLoaded', () => {
180
- // --- Element Selection ---
181
  const form = document.getElementById('transcribe-form');
182
  const apiKeyInput = document.getElementById('api-key-input');
183
  const audioFileInput = document.getElementById('audio-file-input');
@@ -195,17 +199,14 @@
195
  const chunkInfoSection = document.getElementById('chunk-info-section');
196
  const chunkInfoMessage = document.getElementById('chunk-info-message');
197
  const chunkTimestampsOutput = document.getElementById('chunk-timestamps-output');
198
- // Result view elements
199
  const resultsOutput = document.getElementById('results-output');
200
  const viewSrtBtn = document.getElementById('view-srt-btn');
201
  const viewTxtBtn = document.getElementById('view-txt-btn');
202
 
203
- // --- State variables ---
204
  let audioFile = null;
205
  let srtContent = '';
206
  let textContent = null;
207
 
208
- // --- UI and State Functions ---
209
  function checkInputs() {
210
  submitButton.disabled = !(apiKeyInput.value.trim() && audioFile);
211
  }
@@ -218,8 +219,19 @@
218
  statusMessage.className = isError ? 'error' : 'loading';
219
  }
220
 
 
 
 
 
 
 
 
 
 
 
 
221
  function resetUI() {
222
- submitButton.disabled = false;
223
  statusContainer.style.display = 'none';
224
  resultsSection.style.display = 'none';
225
  chunkInfoSection.style.display = 'none';
@@ -237,7 +249,6 @@
237
  localStorage.setItem('geminiApiKey', apiKeyInput.value);
238
  }
239
 
240
- // --- Event Listeners ---
241
  loadApiKey();
242
  apiKeyInput.addEventListener('input', () => { saveApiKey(); checkInputs(); });
243
 
@@ -251,13 +262,13 @@
251
  modelCustomInput.style.display = (modelSelect.value === 'custom') ? 'block' : 'none';
252
  });
253
 
254
- // Drag and Drop
255
  ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
256
  audioDropZone.addEventListener(eventName, e => { e.preventDefault(); e.stopPropagation(); });
257
  });
258
- audioDropZone.addEventListener('dragover', () => audioDropZone.classList.add('drag-over'));
259
  audioDropZone.addEventListener('dragleave', () => audioDropZone.classList.remove('drag-over'));
260
  audioDropZone.addEventListener('drop', e => {
 
261
  audioDropZone.classList.remove('drag-over');
262
  const droppedFile = e.dataTransfer.files[0];
263
  if (droppedFile && droppedFile.type.startsWith('audio/')) {
@@ -271,12 +282,8 @@
271
  checkInputs();
272
  });
273
 
274
- // --- Download and View Logic ---
275
  downloadTxtButton.addEventListener('click', async () => {
276
- if (!srtContent) {
277
- alert('אין תוכן תמלול להמרה.');
278
- return;
279
- }
280
  try {
281
  const response = await fetch('/convert-to-text', {
282
  method: 'POST',
@@ -293,58 +300,42 @@
293
  a.download = `${originalFileName}_transcript.txt`;
294
  document.body.appendChild(a); a.click(); document.body.removeChild(a);
295
  URL.revokeObjectURL(url);
296
- } catch (error) {
297
- alert(`אירעה שגיאה בהמרת הקובץ: ${error.message}`);
298
- }
299
  });
300
 
301
  viewSrtBtn.addEventListener('click', () => {
302
  if (viewSrtBtn.classList.contains('active')) return;
303
  viewSrtBtn.classList.add('active'); viewTxtBtn.classList.remove('active');
304
  resultsOutput.value = srtContent;
305
- resultsOutput.dir = 'ltr'; resultsOutput.style.textAlign = 'left';
306
  });
307
 
308
  viewTxtBtn.addEventListener('click', async () => {
309
  if (viewTxtBtn.classList.contains('active')) return;
310
  viewTxtBtn.classList.add('active'); viewSrtBtn.classList.remove('active');
311
- resultsOutput.dir = 'rtl'; resultsOutput.style.textAlign = 'right';
312
-
313
  if (textContent !== null) { resultsOutput.value = textContent; return; }
314
  if (!srtContent) { resultsOutput.value = ''; return; }
315
-
316
  resultsOutput.value = 'ממיר לתצוגת טקסט...';
317
  try {
318
  const response = await fetch('/convert-to-text', {
319
- method: 'POST',
320
- headers: { 'Content-Type': 'application/json' },
321
- body: JSON.stringify({ srt_data: srtContent })
322
  });
323
  if (!response.ok) throw new Error((await response.json()).detail || 'שגיאה בהמרת הקובץ');
324
  const data = await response.json();
325
  textContent = data.text;
326
  resultsOutput.value = textContent;
327
- } catch (error) {
328
- resultsOutput.value = `אירעה שגיאה בהמרת התצוגה: ${error.message}`;
329
- }
330
  });
331
 
332
- // --- Form Submission and Streaming ---
333
  form.addEventListener('submit', async (e) => {
334
  e.preventDefault();
335
  if (submitButton.disabled) return;
336
  resetUI();
337
-
338
- // Disable form elements during processing
339
- submitButton.disabled = true;
340
- audioFileInput.disabled = true;
341
- audioDropZone.classList.add('disabled');
342
-
343
  updateStatus('מתחיל את התהליך...', 0);
344
  let modelName = modelSelect.value === 'custom' ? modelCustomInput.value.trim() : modelSelect.value;
345
  if (modelSelect.value === 'custom' && !modelName) {
346
  updateStatus('יש להזין שם מודל מותאם אישית', 100, true);
347
- submitButton.disabled = false; audioFileInput.disabled = false; audioDropZone.classList.remove('disabled');
348
  return;
349
  }
350
  const formData = new FormData();
@@ -356,7 +347,6 @@
356
  try {
357
  const response = await fetch('/transcribe-stream', { method: 'POST', body: formData });
358
  if (!response.ok) throw new Error((await response.json()).detail || `שגיאת שרת: ${response.status}`);
359
-
360
  const reader = response.body.getReader();
361
  const decoder = new TextDecoder();
362
  let buffer = '';
@@ -382,8 +372,6 @@
382
  srtContent = event.data;
383
  textContent = null;
384
  resultsOutput.value = srtContent;
385
- resultsOutput.dir = 'ltr';
386
- resultsOutput.style.textAlign = 'left';
387
  viewSrtBtn.classList.add('active');
388
  viewTxtBtn.classList.remove('active');
389
 
@@ -400,15 +388,11 @@
400
  }
401
  }
402
  }
403
- submitButton.disabled = false;
404
- audioFileInput.disabled = false;
405
- audioDropZone.classList.remove('disabled');
406
  } catch (error) {
407
  console.error('Transcription error:', error);
408
  updateStatus(`אירעה שגיאה: ${error.message}`, 100, true);
409
- submitButton.disabled = false;
410
- audioFileInput.disabled = false;
411
- audioDropZone.classList.remove('disabled');
412
  }
413
  });
414
  });
@@ -416,9 +400,7 @@
416
  <footer>
417
  <p>
418
  <a href="https://github.com/NHLOCAL/" target="_blank" class="github-link">
419
- <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="currentColor">
420
- <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.835 2.809 1.305 3.493.998.108-.776.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
421
- </svg>
422
  </a>
423
  נוצר על ידי <a href="https://nhlocal.github.io" target="_blank">Nh Local</a>
424
  </p>
 
10
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
11
  <link href="https://fonts.googleapis.com/css2?family=Assistant:wght@300;400;600;700&display=swap" rel="stylesheet">
12
  <link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" rel="stylesheet" />
13
+ <!-- Font Awesome for brand icons -->
14
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha512-DTOQO9RWCH3ppGqcWaEA1BIZOC6xxalwEsw9c2QQeAIftl+Vegovlnee1c9QX4TctnWMn13TZye+giMm8e2LwA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
15
 
16
  <style>
17
  :root {
 
57
  .file-input-wrapper input[type="file"] { display: none; }
58
  .file-name { margin-top: 1rem; font-weight: 600; color: var(--md-sys-color-secondary); }
59
  #results-section { display: none; margin-top: 2rem; }
60
+ .results-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 1rem; }
61
  .results-header h2 { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
62
  .view-toggle { display: flex; border: 1px solid var(--md-sys-color-outline); border-radius: 99px; overflow: hidden; }
63
  .view-btn { background: transparent; border: none; padding: 6px 16px; cursor: pointer; font-weight: 600; font-family: 'Assistant', sans-serif; font-size: 0.9rem; color: var(--md-sys-color-primary); transition: all 0.2s ease-in-out; }
64
  .view-btn.active { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
65
+ #results-output { width: 100%; height: 300px; padding: 1rem; border: 1px solid var(--md-sys-color-outline); border-radius: var(--border-radius-small); font-family: monospace; background-color: var(--md-sys-color-surface); font-size: 0.9rem; resize: vertical; direction: rtl; text-align: right; }
66
+ .buttons-container { display: flex; gap: 1rem; margin-top: 1rem; justify-content: center; flex-wrap: wrap; }
67
  #status-container { margin-top: 1.5rem; display: none; }
68
  #status-message { text-align: center; padding: 1rem; font-weight: 600; border-radius: var(--border-radius-small) var(--border-radius-small) 0 0; }
69
  #status-message.loading { background-color: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
 
75
  footer a { color: var(--md-sys-color-primary); text-decoration: none; font-weight: 600; }
76
  footer a:hover { text-decoration: underline; }
77
  .github-link { margin-left: 8px; vertical-align: middle; display: inline-flex; align-items: center; justify-content: center; }
78
+ .github-link i { font-size: 18px; color: var(--md-sys-color-primary); transition: color 0.2s ease-in-out; vertical-align: middle; }
79
+ .github-link:hover i { color: #5a3f92; }
80
  </style>
81
  </head>
82
  <body>
 
127
  <span class="material-symbols-outlined">rocket_launch</span> התחל תמלול
128
  </button>
129
  <a href="https://tools.ze-kal.top/tools/subtitle_editor.html" target="_blank" class="btn btn-secondary" title="עריכה, סנכרון ותיקון של קובץ כתוביות קיים" style="padding: 16px 32px; font-size: 1.2rem;">
130
+ <span class="material-symbols-outlined">edit_note</span> עורך כתוביות
131
  </a>
132
  </div>
133
  </form>
 
160
  <div class="results-header">
161
  <h2>תוצאות התמלול</h2>
162
  <div class="view-toggle">
163
+ <button id="view-srt-btn" class="view-btn">כתוביות</button>
164
  <button id="view-txt-btn" class="view-btn">טקסט</button>
165
  </div>
166
  </div>
167
  <textarea id="results-output" readonly></textarea>
168
  <div class="buttons-container">
169
  <a id="download-srt-button" class="btn btn-primary">
170
+ <span class="material-symbols-outlined">download</span> הורד כתוביות (SRT)
171
  </a>
172
+ <a href="https://tools.ze-kal.top/tools/subtitle_editor.html" target="_blank" class="btn btn-secondary" title="עריכה, סנכרון ותיקון של קובץ כתוביות קיים">
173
+ <span class="material-symbols-outlined">edit_note</span> ערוך כתוביות
174
+ </a>
175
  <a id="download-txt-button" class="btn btn-secondary">
176
+ <span class="material-symbols-outlined">article</span> הורד כטקסט
177
  </a>
178
  </div>
179
  </section>
 
182
 
183
  <script>
184
  document.addEventListener('DOMContentLoaded', () => {
 
185
  const form = document.getElementById('transcribe-form');
186
  const apiKeyInput = document.getElementById('api-key-input');
187
  const audioFileInput = document.getElementById('audio-file-input');
 
199
  const chunkInfoSection = document.getElementById('chunk-info-section');
200
  const chunkInfoMessage = document.getElementById('chunk-info-message');
201
  const chunkTimestampsOutput = document.getElementById('chunk-timestamps-output');
 
202
  const resultsOutput = document.getElementById('results-output');
203
  const viewSrtBtn = document.getElementById('view-srt-btn');
204
  const viewTxtBtn = document.getElementById('view-txt-btn');
205
 
 
206
  let audioFile = null;
207
  let srtContent = '';
208
  let textContent = null;
209
 
 
210
  function checkInputs() {
211
  submitButton.disabled = !(apiKeyInput.value.trim() && audioFile);
212
  }
 
219
  statusMessage.className = isError ? 'error' : 'loading';
220
  }
221
 
222
+ function setFormEnabled(enabled) {
223
+ submitButton.disabled = !enabled;
224
+ audioFileInput.disabled = !enabled;
225
+ if (enabled) {
226
+ audioDropZone.classList.remove('disabled');
227
+ checkInputs(); // Re-check if submit should be enabled
228
+ } else {
229
+ audioDropZone.classList.add('disabled');
230
+ }
231
+ }
232
+
233
  function resetUI() {
234
+ setFormEnabled(true);
235
  statusContainer.style.display = 'none';
236
  resultsSection.style.display = 'none';
237
  chunkInfoSection.style.display = 'none';
 
249
  localStorage.setItem('geminiApiKey', apiKeyInput.value);
250
  }
251
 
 
252
  loadApiKey();
253
  apiKeyInput.addEventListener('input', () => { saveApiKey(); checkInputs(); });
254
 
 
262
  modelCustomInput.style.display = (modelSelect.value === 'custom') ? 'block' : 'none';
263
  });
264
 
 
265
  ['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
266
  audioDropZone.addEventListener(eventName, e => { e.preventDefault(); e.stopPropagation(); });
267
  });
268
+ audioDropZone.addEventListener('dragover', () => { if (!audioFileInput.disabled) audioDropZone.classList.add('drag-over') });
269
  audioDropZone.addEventListener('dragleave', () => audioDropZone.classList.remove('drag-over'));
270
  audioDropZone.addEventListener('drop', e => {
271
+ if (audioFileInput.disabled) return;
272
  audioDropZone.classList.remove('drag-over');
273
  const droppedFile = e.dataTransfer.files[0];
274
  if (droppedFile && droppedFile.type.startsWith('audio/')) {
 
282
  checkInputs();
283
  });
284
 
 
285
  downloadTxtButton.addEventListener('click', async () => {
286
+ if (!srtContent) { alert('אין תוכן תמלול להמרה.'); return; }
 
 
 
287
  try {
288
  const response = await fetch('/convert-to-text', {
289
  method: 'POST',
 
300
  a.download = `${originalFileName}_transcript.txt`;
301
  document.body.appendChild(a); a.click(); document.body.removeChild(a);
302
  URL.revokeObjectURL(url);
303
+ } catch (error) { alert(`אירעה שגיאה בהמרת הקובץ: ${error.message}`); }
 
 
304
  });
305
 
306
  viewSrtBtn.addEventListener('click', () => {
307
  if (viewSrtBtn.classList.contains('active')) return;
308
  viewSrtBtn.classList.add('active'); viewTxtBtn.classList.remove('active');
309
  resultsOutput.value = srtContent;
 
310
  });
311
 
312
  viewTxtBtn.addEventListener('click', async () => {
313
  if (viewTxtBtn.classList.contains('active')) return;
314
  viewTxtBtn.classList.add('active'); viewSrtBtn.classList.remove('active');
 
 
315
  if (textContent !== null) { resultsOutput.value = textContent; return; }
316
  if (!srtContent) { resultsOutput.value = ''; return; }
 
317
  resultsOutput.value = 'ממיר לתצוגת טקסט...';
318
  try {
319
  const response = await fetch('/convert-to-text', {
320
+ method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ srt_data: srtContent })
 
 
321
  });
322
  if (!response.ok) throw new Error((await response.json()).detail || 'שגיאה בהמרת הקובץ');
323
  const data = await response.json();
324
  textContent = data.text;
325
  resultsOutput.value = textContent;
326
+ } catch (error) { resultsOutput.value = `אירעה שגיאה בהמרת התצוגה: ${error.message}`; }
 
 
327
  });
328
 
 
329
  form.addEventListener('submit', async (e) => {
330
  e.preventDefault();
331
  if (submitButton.disabled) return;
332
  resetUI();
333
+ setFormEnabled(false);
 
 
 
 
 
334
  updateStatus('מתחיל את התהליך...', 0);
335
  let modelName = modelSelect.value === 'custom' ? modelCustomInput.value.trim() : modelSelect.value;
336
  if (modelSelect.value === 'custom' && !modelName) {
337
  updateStatus('יש להזין שם מודל מותאם אישית', 100, true);
338
+ setFormEnabled(true);
339
  return;
340
  }
341
  const formData = new FormData();
 
347
  try {
348
  const response = await fetch('/transcribe-stream', { method: 'POST', body: formData });
349
  if (!response.ok) throw new Error((await response.json()).detail || `שגיאת שרת: ${response.status}`);
 
350
  const reader = response.body.getReader();
351
  const decoder = new TextDecoder();
352
  let buffer = '';
 
372
  srtContent = event.data;
373
  textContent = null;
374
  resultsOutput.value = srtContent;
 
 
375
  viewSrtBtn.classList.add('active');
376
  viewTxtBtn.classList.remove('active');
377
 
 
388
  }
389
  }
390
  }
391
+ setFormEnabled(true);
 
 
392
  } catch (error) {
393
  console.error('Transcription error:', error);
394
  updateStatus(`אירעה שגיאה: ${error.message}`, 100, true);
395
+ setFormEnabled(true);
 
 
396
  }
397
  });
398
  });
 
400
  <footer>
401
  <p>
402
  <a href="https://github.com/NHLOCAL/" target="_blank" class="github-link">
403
+ <i class="fa-brands fa-github"></i>
 
 
404
  </a>
405
  נוצר על ידי <a href="https://nhlocal.github.io" target="_blank">Nh Local</a>
406
  </p>