Spaces:
Sleeping
Sleeping
Update Web/script.js
Browse files- Web/script.js +8 -18
Web/script.js
CHANGED
|
@@ -182,34 +182,24 @@ async function analyzeAudio(blob) {
|
|
| 182 |
|
| 183 |
responseBox.innerHTML = "<em>Analyzing...</em>";
|
| 184 |
|
| 185 |
-
//
|
| 186 |
-
|
|
|
|
| 187 |
const formData = new FormData();
|
| 188 |
-
|
| 189 |
-
formData.append('files', blob, "audio.wav"); // Utiliser 'files' comme nom de champ
|
| 190 |
|
| 191 |
try {
|
| 192 |
-
//
|
| 193 |
-
|
| 194 |
-
const res = await fetch("/predict/", {
|
| 195 |
method: "POST",
|
| 196 |
body: formData,
|
| 197 |
});
|
| 198 |
|
| 199 |
-
if (!res.ok) {
|
| 200 |
-
// Read the error message from the server if available
|
| 201 |
-
const errorText = await res.text();
|
| 202 |
-
throw new Error(`Server Error ${res.status}: ${errorText}`);
|
| 203 |
-
}
|
| 204 |
-
|
| 205 |
const data = await res.json();
|
| 206 |
-
responseBox.innerHTML = `<pre>${JSON.stringify(data, null, 2)}</pre>`;
|
| 207 |
|
|
|
|
| 208 |
} catch (err) {
|
|
|
|
| 209 |
console.error(err);
|
| 210 |
-
responseBox.innerHTML = `<div class="alert alert-danger">
|
| 211 |
-
<strong>Analysis failed.</strong><br/>
|
| 212 |
-
<small>${err.message}</small>
|
| 213 |
-
</div>`;
|
| 214 |
}
|
| 215 |
}
|
|
|
|
| 182 |
|
| 183 |
responseBox.innerHTML = "<em>Analyzing...</em>";
|
| 184 |
|
| 185 |
+
// Convert Blob to File
|
| 186 |
+
const file = new File([blob], blob.name || "audio.wav", { type: blob.type });
|
| 187 |
+
|
| 188 |
const formData = new FormData();
|
| 189 |
+
formData.append("file", file);
|
|
|
|
| 190 |
|
| 191 |
try {
|
| 192 |
+
// Replace the URL with your real backend endpoint
|
| 193 |
+
const res = await fetch("/predict", {
|
|
|
|
| 194 |
method: "POST",
|
| 195 |
body: formData,
|
| 196 |
});
|
| 197 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
const data = await res.json();
|
|
|
|
| 199 |
|
| 200 |
+
responseBox.innerHTML = `<pre>${JSON.stringify(data, null, 2)}</pre>`;
|
| 201 |
} catch (err) {
|
| 202 |
+
responseBox.innerHTML = `<span style="color:red;">Analysis failed.</span>`;
|
| 203 |
console.error(err);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
}
|
| 205 |
}
|