Update app.py
Browse files
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 |
-
|
| 26 |
"""
|
| 27 |
if classifier is None:
|
| 28 |
-
|
|
|
|
| 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 |
-
#
|
| 38 |
-
|
| 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 |
-
|
|
|
|
| 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(
|