Spaces:
Sleeping
Sleeping
Download src/utils/api.js from Aya07/emotion-ui: direct link, hf CLI and curl.
- Browser
- Download file 879 Bytes
-
https://huggingface.co/spaces/Aya07/emotion-ui/resolve/main/src/utils/api.js
- Command line
-
hf download hf://spaces/Aya07/emotion-ui/src/utils/api.js
-
curl -L -o api.js https://huggingface.co/spaces/Aya07/emotion-ui/resolve/main/src/utils/api.js
879 Bytes
| const API_URL = "https://aya07-emotion-det.hf.space/predict"; | |
| export const predictEmotion = async (file) => { | |
| const formData = new FormData(); | |
| // 🔥 FIX : S'assurer que le fichier a un nom valide | |
| let fileToSend = file; | |
| if (file instanceof Blob && !file.name) { | |
| // Créer un File object avec un nom valide | |
| fileToSend = new File([file], `recording_${Date.now()}.wav`, { type: 'audio/wav' }); | |
| console.log('Fixed file for API:', fileToSend.name, fileToSend.type); | |
| } | |
| formData.append("audio_file", fileToSend); | |
| const res = await fetch(API_URL, { | |
| method: "POST", | |
| body: formData, | |
| }); | |
| const data = await res.json(); | |
| if (!res.ok) { | |
| console.error('API Error:', data); | |
| throw new Error(data.detail || `Server error: ${res.status}`); | |
| } | |
| if (!data.success) throw new Error(data.detail || "Prediction failed"); | |
| return data; | |
| }; |