sileod commited on
Commit
60bd985
·
verified ·
1 Parent(s): 07aa724

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -22,11 +22,11 @@ def classify_text(text, candidate_labels):
22
  candidate_labels (str): Comma-separated string of possible labels
23
 
24
  Returns:
25
- list: List of (label, score) tuples
26
  """
27
  if classifier is None:
28
- # Return a default response when model fails to load
29
- return [("error", 1.0)]
30
 
31
  try:
32
  # Convert comma-separated string to list
@@ -35,12 +35,12 @@ def classify_text(text, candidate_labels):
35
  # Perform classification
36
  result = classifier(text, labels)
37
 
38
- # Convert results to list of (label, score) tuples
39
- return list(zip(result["labels"], result["scores"]))
40
 
41
  except Exception as e:
42
  print(f"Classification error: {e}")
43
- return [("error", 1.0)]
44
 
45
  # Create Gradio interface
46
  iface = gr.Interface(
 
22
  candidate_labels (str): Comma-separated string of possible labels
23
 
24
  Returns:
25
+ dict: Dictionary with labels as keys and confidence scores as values
26
  """
27
  if classifier is None:
28
+ # Return default response when model fails to load
29
+ return {"error": 1.0}
30
 
31
  try:
32
  # Convert comma-separated string to list
 
35
  # Perform classification
36
  result = classifier(text, labels)
37
 
38
+ # Convert to dictionary format that Gradio Label expects
39
+ return {label: float(score) for label, score in zip(result["labels"], result["scores"])}
40
 
41
  except Exception as e:
42
  print(f"Classification error: {e}")
43
+ return {"error": 1.0}
44
 
45
  # Create Gradio interface
46
  iface = gr.Interface(