MinAA commited on
Commit
05f7dda
·
1 Parent(s): 99831c1
Files changed (1) hide show
  1. app.py +6 -36
app.py CHANGED
@@ -298,28 +298,12 @@ def audio_classifier(audio, model_name):
298
  def audio_zero_shot_classifier(audio, candidate_labels, model_name):
299
  """Zero-shot классификация аудио"""
300
  try:
301
- labels = [label.strip() for label in candidate_labels.split(",")]
302
  classifier = get_pipeline("zero-shot-audio-classification", model_name)
 
303
  result = classifier(audio, candidate_labels=labels)
304
-
305
- # Обрабатываем результат
306
- if isinstance(result, list):
307
- result = result[0] if result else {}
308
-
309
  output = "Результаты классификации:\n"
310
- if isinstance(result, dict) and 'scores' in result:
311
- for label, score in zip(result.get('labels', labels), result['scores']):
312
- output += f"{label}: {score:.4f}\n"
313
- elif isinstance(result, list):
314
- for item in result:
315
- if isinstance(item, dict):
316
- label = item.get('label', '')
317
- score = item.get('score', 0.0)
318
- output += f"{label}: {score:.4f}\n"
319
- else:
320
- # Если формат неожиданный, пытаемся извлечь информацию
321
- output += str(result)
322
-
323
  return output
324
  except Exception as e:
325
  return f"Ошибка: {str(e)}"
@@ -712,26 +696,12 @@ def visual_qa(image, question, model_name):
712
  def image_zero_shot_classification(image, candidate_labels, model_name):
713
  """Zero-shot классификация изображений"""
714
  try:
715
- labels = [label.strip() for label in candidate_labels.split(",")]
716
  classifier = get_pipeline("zero-shot-image-classification", model_name)
 
717
  result = classifier(image, candidate_labels=labels)
718
-
719
- # Обрабатываем результат
720
- if isinstance(result, list):
721
- # Сортируем по score если нужно
722
- result = sorted(result, key=lambda x: x.get('score', 0), reverse=True)
723
- else:
724
- result = [result] if result else []
725
-
726
  output = "Результаты классификации:\n"
727
- for item in result:
728
- if isinstance(item, dict):
729
- label = item.get('label', '')
730
- score = item.get('score', 0.0)
731
- output += f"{label}: {score:.4f}\n"
732
- else:
733
- output += f"{item}\n"
734
-
735
  return output
736
  except Exception as e:
737
  return f"Ошибка: {str(e)}"
 
298
  def audio_zero_shot_classifier(audio, candidate_labels, model_name):
299
  """Zero-shot классификация аудио"""
300
  try:
 
301
  classifier = get_pipeline("zero-shot-audio-classification", model_name)
302
+ labels = [label.strip() for label in candidate_labels.split(",")]
303
  result = classifier(audio, candidate_labels=labels)
 
 
 
 
 
304
  output = "Результаты классификации:\n"
305
+ for label, score in zip(result['labels'], result['scores']):
306
+ output += f"{label}: {score:.4f}\n"
 
 
 
 
 
 
 
 
 
 
 
307
  return output
308
  except Exception as e:
309
  return f"Ошибка: {str(e)}"
 
696
  def image_zero_shot_classification(image, candidate_labels, model_name):
697
  """Zero-shot классификация изображений"""
698
  try:
 
699
  classifier = get_pipeline("zero-shot-image-classification", model_name)
700
+ labels = [label.strip() for label in candidate_labels.split(",")]
701
  result = classifier(image, candidate_labels=labels)
 
 
 
 
 
 
 
 
702
  output = "Результаты классификации:\n"
703
+ for label, score in zip(result['labels'], result['scores']):
704
+ output += f"{label}: {score:.4f}\n"
 
 
 
 
 
 
705
  return output
706
  except Exception as e:
707
  return f"Ошибка: {str(e)}"