Athspi commited on
Commit
ba527a9
·
verified ·
1 Parent(s): 9807843

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +69 -38
templates/index.html CHANGED
@@ -300,18 +300,12 @@
300
  </header>
301
 
302
  <div class="content">
303
- {% with messages = get_flashed_messages(with_categories=true) %}
304
- {% if messages %}
305
- {% for category, message in messages %}
306
- <div class="alert alert-{{ category }}">
307
- <i class="fas {% if category == 'success' %}fa-check-circle{% else %}fa-exclamation-circle{% endif %}"></i>
308
- {{ message }}
309
- </div>
310
- {% endfor %}
311
- {% endif %}
312
- {% endwith %}
313
 
314
- <form id="dubbing-form" action="/process" method="POST" enctype="multipart/form-data">
315
  <div class="upload-area" id="upload-area">
316
  <div class="upload-icon">
317
  <i class="fas fa-cloud-upload-alt"></i>
@@ -329,12 +323,14 @@
329
  Voice Style
330
  </div>
331
  <div class="radio-group">
332
- {% for voice, value in voices.items() %}
333
- <label class="radio-option">
334
- <input type="radio" name="voice" value="{{ value }}" {% if loop.first %}checked{% endif %}>
335
- {{ voice }}
336
- </label>
337
- {% endfor %}
 
 
338
  </div>
339
  </div>
340
 
@@ -345,7 +341,7 @@
345
  </div>
346
  <div class="checkbox-group">
347
  <label class="checkbox-option">
348
- <input type="checkbox" name="tone">
349
  Cheerful Tone
350
  </label>
351
  </div>
@@ -363,14 +359,12 @@
363
  <p class="loading-text">Processing your video. Please wait...</p>
364
  </div>
365
 
366
- {% if result_video %}
367
- <div class="result-section" id="result-section" style="display: block;">
368
  <div class="result-title">
369
  <i class="fas fa-video"></i>
370
  Your Dubbed Video
371
  </div>
372
- <video controls class="result-video">
373
- <source src="{{ result_video }}" type="video/mp4">
374
  Your browser does not support the video tag.
375
  </video>
376
 
@@ -378,9 +372,8 @@
378
  <i class="fas fa-scroll"></i>
379
  Generated Script
380
  </div>
381
- <div class="script-box">{{ script }}</div>
382
  </div>
383
- {% endif %}
384
  </div>
385
  </div>
386
 
@@ -391,6 +384,10 @@
391
  const fileInput = document.getElementById('video');
392
  const fileInfo = document.getElementById('file-info');
393
  const resultSection = document.getElementById('result-section');
 
 
 
 
394
 
395
  // Handle file selection
396
  fileInput.addEventListener('change', function() {
@@ -398,11 +395,7 @@
398
  fileInfo.textContent = this.files[0].name;
399
  uploadArea.style.borderColor = '#4361ee';
400
  uploadArea.style.backgroundColor = 'rgba(67, 97, 238, 0.05)';
401
-
402
- // Hide any previous results
403
- if (resultSection) {
404
- resultSection.style.display = 'none';
405
- }
406
  }
407
  });
408
 
@@ -426,24 +419,62 @@
426
  if (e.dataTransfer.files.length) {
427
  fileInput.files = e.dataTransfer.files;
428
  fileInfo.textContent = e.dataTransfer.files[0].name;
429
-
430
- // Hide any previous results
431
- if (resultSection) {
432
- resultSection.style.display = 'none';
433
- }
434
  }
435
  });
436
 
437
  // Form submission
438
- form.addEventListener('submit', function(e) {
 
 
439
  if (!fileInput.files.length) {
440
- e.preventDefault();
441
- alert('Please select a video file first.');
442
- } else {
 
 
443
  form.style.display = 'none';
444
  loader.style.display = 'block';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  }
446
  });
 
 
 
 
 
 
 
 
 
447
  </script>
448
  </body>
449
  </html>
 
300
  </header>
301
 
302
  <div class="content">
303
+ <div id="alert" class="alert" style="display: none;">
304
+ <i class="fas fa-info-circle"></i>
305
+ <span id="alert-message"></span>
306
+ </div>
 
 
 
 
 
 
307
 
308
+ <form id="dubbing-form">
309
  <div class="upload-area" id="upload-area">
310
  <div class="upload-icon">
311
  <i class="fas fa-cloud-upload-alt"></i>
 
323
  Voice Style
324
  </div>
325
  <div class="radio-group">
326
+ <label class="radio-option">
327
+ <input type="radio" name="voice" value="male" checked>
328
+ Male Voice
329
+ </label>
330
+ <label class="radio-option">
331
+ <input type="radio" name="voice" value="female">
332
+ Female Voice
333
+ </label>
334
  </div>
335
  </div>
336
 
 
341
  </div>
342
  <div class="checkbox-group">
343
  <label class="checkbox-option">
344
+ <input type="checkbox" name="cheerful">
345
  Cheerful Tone
346
  </label>
347
  </div>
 
359
  <p class="loading-text">Processing your video. Please wait...</p>
360
  </div>
361
 
362
+ <div class="result-section" id="result-section">
 
363
  <div class="result-title">
364
  <i class="fas fa-video"></i>
365
  Your Dubbed Video
366
  </div>
367
+ <video controls class="result-video" id="result-video">
 
368
  Your browser does not support the video tag.
369
  </video>
370
 
 
372
  <i class="fas fa-scroll"></i>
373
  Generated Script
374
  </div>
375
+ <div class="script-box" id="script-box"></div>
376
  </div>
 
377
  </div>
378
  </div>
379
 
 
384
  const fileInput = document.getElementById('video');
385
  const fileInfo = document.getElementById('file-info');
386
  const resultSection = document.getElementById('result-section');
387
+ const resultVideo = document.getElementById('result-video');
388
+ const scriptBox = document.getElementById('script-box');
389
+ const alertBox = document.getElementById('alert');
390
+ const alertMessage = document.getElementById('alert-message');
391
 
392
  // Handle file selection
393
  fileInput.addEventListener('change', function() {
 
395
  fileInfo.textContent = this.files[0].name;
396
  uploadArea.style.borderColor = '#4361ee';
397
  uploadArea.style.backgroundColor = 'rgba(67, 97, 238, 0.05)';
398
+ resultSection.style.display = 'none';
 
 
 
 
399
  }
400
  });
401
 
 
419
  if (e.dataTransfer.files.length) {
420
  fileInput.files = e.dataTransfer.files;
421
  fileInfo.textContent = e.dataTransfer.files[0].name;
422
+ resultSection.style.display = 'none';
 
 
 
 
423
  }
424
  });
425
 
426
  // Form submission
427
+ form.addEventListener('submit', async (e) => {
428
+ e.preventDefault();
429
+
430
  if (!fileInput.files.length) {
431
+ showAlert('Please select a video file first.', 'error');
432
+ return;
433
+ }
434
+
435
+ try {
436
  form.style.display = 'none';
437
  loader.style.display = 'block';
438
+ alertBox.style.display = 'none';
439
+
440
+ const formData = new FormData();
441
+ formData.append('file', fileInput.files[0]);
442
+ formData.append('voice', document.querySelector('input[name="voice"]:checked').value);
443
+ formData.append('cheerful', document.querySelector('input[name="cheerful"]').checked);
444
+
445
+ const response = await fetch('/process', {
446
+ method: 'POST',
447
+ body: formData
448
+ });
449
+
450
+ if (!response.ok) {
451
+ const error = await response.json();
452
+ throw new Error(error.detail || 'Processing failed');
453
+ }
454
+
455
+ const data = await response.json();
456
+
457
+ resultVideo.src = data.video_url;
458
+ scriptBox.textContent = data.script;
459
+ resultSection.style.display = 'block';
460
+
461
+ } catch (error) {
462
+ showAlert(error.message, 'error');
463
+ console.error('Processing error:', error);
464
+ } finally {
465
+ form.style.display = 'block';
466
+ loader.style.display = 'none';
467
  }
468
  });
469
+
470
+ function showAlert(message, type) {
471
+ alertMessage.textContent = message;
472
+ alertBox.className = `alert alert-${type}`;
473
+ alertBox.style.display = 'flex';
474
+
475
+ // Scroll to alert
476
+ alertBox.scrollIntoView({ behavior: 'smooth' });
477
+ }
478
  </script>
479
  </body>
480
  </html>