Update app.py
Browse files
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 |
-
|
| 26 |
"""
|
| 27 |
if classifier is None:
|
| 28 |
-
# Return
|
| 29 |
-
return
|
| 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
|
| 39 |
-
return
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
print(f"Classification error: {e}")
|
| 43 |
-
return
|
| 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(
|