Gregniuki commited on
Commit
81a4e7a
1 Parent(s): 7b6d324

Update templates/interface.html

Browse files
Files changed (1) hide show
  1. templates/interface.html +26 -14
templates/interface.html CHANGED
@@ -94,30 +94,42 @@
94
  </script>
95
 
96
  </form>
97
- <script>
98
- const selectedModelDropdown = document.getElementById("selected_model");
99
- const speakerDropdown = document.getElementById("selected_speaker_id");
100
 
101
- selectedModelDropdown.addEventListener("change", () => {
102
- const selectedModel = selectedModelDropdown.value;
 
103
 
104
- // Fetch speaker options for the selected model
105
  fetch(`/get_speaker_id_map?selected_model=${selectedModel}`)
106
  .then(response => response.json())
107
  .then(data => {
108
- const speakerIdMap = data.speaker_id_map;
109
- speakerDropdown.innerHTML = ""; // Clear existing options
 
 
110
 
111
- for (const [speakerId, speakerName] of Object.entries(speakerIdMap)) {
112
- const option = document.createElement("option");
 
113
  option.value = speakerId;
114
  option.textContent = speakerName;
115
- speakerDropdown.appendChild(option);
116
  }
117
  })
118
- .catch(error => console.error("Error fetching speaker options:", error));
119
- });
120
- </script>
 
 
 
 
 
 
 
 
121
  <!-- Move the JavaScript code outside the conditional block -->
122
 
123
  </body>
 
94
  </script>
95
 
96
  </form>
97
+ <script>
98
+ const modelSelect = document.getElementById('selected_model');
99
+ const speakerSelect = document.getElementById('selected_speaker_id');
100
 
101
+ // Function to load speaker options based on the selected model
102
+ function loadSpeakers() {
103
+ const selectedModel = modelSelect.value;
104
 
105
+ // Fetch the speaker options for the selected model from the server
106
  fetch(`/get_speaker_id_map?selected_model=${selectedModel}`)
107
  .then(response => response.json())
108
  .then(data => {
109
+ // Clear existing options
110
+ while (speakerSelect.firstChild) {
111
+ speakerSelect.removeChild(speakerSelect.firstChild);
112
+ }
113
 
114
+ // Populate the speaker options based on data received
115
+ for (const [speakerId, speakerName] of Object.entries(data.speaker_id_map)) {
116
+ const option = document.createElement('option');
117
  option.value = speakerId;
118
  option.textContent = speakerName;
119
+ speakerSelect.appendChild(option);
120
  }
121
  })
122
+ .catch(error => {
123
+ console.error('Error fetching speaker options:', error);
124
+ });
125
+ }
126
+
127
+ // Add an event listener to load speakers when the model selection changes
128
+ modelSelect.addEventListener('change', loadSpeakers);
129
+
130
+ // Initialize the speaker options based on the default selected model
131
+ loadSpeakers();
132
+ </script>
133
  <!-- Move the JavaScript code outside the conditional block -->
134
 
135
  </body>