smjain commited on
Commit
599ec4b
1 Parent(s): 137aa2f

Upload ui.html

Browse files
Files changed (1) hide show
  1. templates/ui.html +32 -16
templates/ui.html CHANGED
@@ -28,6 +28,10 @@
28
  <input type="submit" value="Convert Voice">
29
  </form>
30
 
 
 
 
 
31
  <!-- Processed Audio Playback -->
32
  <h3>Processed Audio:</h3>
33
  <audio id="processedAudio" controls>
@@ -45,34 +49,46 @@ $(document).ready(function() {
45
  url: '/convert_voice',
46
  type: 'POST',
47
  data: formData,
48
- timeout: 180000
49
  success: function(data) {
50
  if (data.audio_id) {
51
- // Update the source of the processed audio element
 
52
  $('#processedAudio source').attr('src', '/get_processed_audio/' + data.audio_id);
53
  $('#processedAudio')[0].load();
54
- $('#processedAudio')[0].play();
55
  } else if (data.error) {
56
- // Display error message from the server
57
  alert(data.error);
58
  }
59
  },
60
- error: function(xhr, status, error) {
61
- // Handle different types of error status codes
62
- if(xhr.status === 429) {
63
- alert("Too many requests, please try again later.");
64
- } else if(xhr.status === 400) {
65
- alert("Bad request. Please check the input and try again.");
66
- } else {
67
- // Generic error message for other statuses
68
- alert("An error occurred: " + xhr.status + " " + error);
69
- }
70
- },
71
  cache: false,
72
  contentType: false,
73
- processData: false
 
 
 
 
74
  });
75
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  });
77
  </script>
78
 
 
28
  <input type="submit" value="Convert Voice">
29
  </form>
30
 
31
+ <!-- Status Display -->
32
+ <h3>Processing Status:</h3>
33
+ <div id="statusDisplay">Waiting for submission...</div>
34
+
35
  <!-- Processed Audio Playback -->
36
  <h3>Processed Audio:</h3>
37
  <audio id="processedAudio" controls>
 
49
  url: '/convert_voice',
50
  type: 'POST',
51
  data: formData,
52
+ timeout: 180000,
53
  success: function(data) {
54
  if (data.audio_id) {
55
+ // Start polling for status
56
+ updateTaskStatus(data.audio_id);
57
  $('#processedAudio source').attr('src', '/get_processed_audio/' + data.audio_id);
58
  $('#processedAudio')[0].load();
 
59
  } else if (data.error) {
 
60
  alert(data.error);
61
  }
62
  },
 
 
 
 
 
 
 
 
 
 
 
63
  cache: false,
64
  contentType: false,
65
+ processData: false,
66
+ error: function(xhr) {
67
+ // Handle errors
68
+ alert("Error: " + xhr.responseText);
69
+ }
70
  });
71
  });
72
+
73
+ function updateTaskStatus(audioId) {
74
+ $.ajax({
75
+ url: `/status/${audioId}`,
76
+ type: 'GET',
77
+ success: function(data) {
78
+ $('#statusDisplay').text(`${data.status} - ${data.percentage}% complete`);
79
+ if (data.status !== "Completed" && data.status !== "Failed") {
80
+ setTimeout(() => updateTaskStatus(audioId), 1000); // Poll every second
81
+ } else {
82
+ if (data.status === "Completed") {
83
+ $('#processedAudio')[0].play();
84
+ }
85
+ }
86
+ },
87
+ error: function(xhr) {
88
+ $('#statusDisplay').text("Failed to get status.");
89
+ }
90
+ });
91
+ }
92
  });
93
  </script>
94