Spaces:
Sleeping

File size: 879 Bytes
ee09ce0
20d0e47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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;
};