Obiang commited on
Commit
2e77301
·
1 Parent(s): fc2c77a

Fix API file path handling for predict_json endpoint

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -209,8 +209,19 @@ def predict_tone_json(audio_file):
209
  }
210
 
211
  try:
 
 
 
 
 
 
 
 
 
 
 
212
  # Get predictions
213
- tone_indices, tone_names, f0_extracted, f0_predicted = tone_recognizer.classify_file(audio_file)
214
 
215
  # Convert F0 tensors to lists for JSON serialization
216
  if hasattr(f0_extracted, 'cpu'):
 
209
  }
210
 
211
  try:
212
+ # Handle different input types from Gradio API
213
+ # audio_file can be: string path, dict with 'path' key, or other formats
214
+ if isinstance(audio_file, dict):
215
+ # FileData format from API
216
+ file_path = audio_file.get('path', audio_file.get('name', str(audio_file)))
217
+ elif isinstance(audio_file, str):
218
+ file_path = audio_file
219
+ else:
220
+ # Try to get path attribute or convert to string
221
+ file_path = getattr(audio_file, 'path', str(audio_file))
222
+
223
  # Get predictions
224
+ tone_indices, tone_names, f0_extracted, f0_predicted = tone_recognizer.classify_file(file_path)
225
 
226
  # Convert F0 tensors to lists for JSON serialization
227
  if hasattr(f0_extracted, 'cpu'):