sileod commited on
Commit
07aa724
·
verified ·
1 Parent(s): 3acbaf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -9
app.py CHANGED
@@ -22,10 +22,11 @@ def classify_text(text, candidate_labels):
22
  candidate_labels (str): Comma-separated string of possible labels
23
 
24
  Returns:
25
- dict: Dictionary containing labels and their corresponding scores
26
  """
27
  if classifier is None:
28
- return {"Error": "Model failed to load"}
 
29
 
30
  try:
31
  # Convert comma-separated string to list
@@ -34,15 +35,12 @@ def classify_text(text, candidate_labels):
34
  # Perform classification
35
  result = classifier(text, labels)
36
 
37
- # Create formatted output
38
- output = {}
39
- for label, score in zip(result["labels"], result["scores"]):
40
- output[label] = f"{score:.4f}"
41
-
42
- return output
43
 
44
  except Exception as e:
45
- return {"Error": str(e)}
 
46
 
47
  # Create Gradio interface
48
  iface = gr.Interface(
 
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
  # 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(