Update app.py
Browse files
app.py
CHANGED
|
@@ -11,17 +11,16 @@ def zeroShotClassification(text_input, candidate_labels):
|
|
| 11 |
# Get predictions
|
| 12 |
prediction = classifier(text_input, labels)
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
results = {label:
|
| 16 |
-
for label, score in zip(prediction['labels'], prediction['scores'])}
|
| 17 |
|
| 18 |
-
# Create
|
| 19 |
markdown_output = "### Results Breakdown:\n\n"
|
| 20 |
-
for label, score in sorted(results.items(), key=lambda x:
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
blocks = "█" * int(
|
| 24 |
-
markdown_output += f"**{label}**: {blocks} {
|
| 25 |
|
| 26 |
return results, markdown_output
|
| 27 |
|
|
@@ -66,7 +65,7 @@ demo = gr.Interface(
|
|
| 66 |
["The team scored in the final minute to win the championship", "sports, victory, competition, excitement"],
|
| 67 |
["The painting uses vibrant colors to express deep emotions", "art, emotion, creativity, analysis"]
|
| 68 |
],
|
| 69 |
-
cache_examples=False,
|
| 70 |
css="""
|
| 71 |
footer {display:none !important}
|
| 72 |
.output-markdown{display:none !important}
|
|
@@ -113,8 +112,7 @@ demo = gr.Interface(
|
|
| 113 |
font-family: 'Inter', sans-serif !important;
|
| 114 |
color: #11142D !important;
|
| 115 |
}
|
| 116 |
-
"""
|
| 117 |
-
theme=gr.themes.Soft()
|
| 118 |
)
|
| 119 |
|
| 120 |
# Launch the app
|
|
|
|
| 11 |
# Get predictions
|
| 12 |
prediction = classifier(text_input, labels)
|
| 13 |
|
| 14 |
+
# For Label component: Return raw scores (not percentage strings)
|
| 15 |
+
results = {label: score for label, score in zip(prediction['labels'], prediction['scores'])}
|
|
|
|
| 16 |
|
| 17 |
+
# For Markdown: Create detailed view with percentage formatting
|
| 18 |
markdown_output = "### Results Breakdown:\n\n"
|
| 19 |
+
for label, score in sorted(results.items(), key=lambda x: x[1], reverse=True):
|
| 20 |
+
# Convert to percentage for display
|
| 21 |
+
percentage = score * 100
|
| 22 |
+
blocks = "█" * int(percentage/5) + "░" * (20 - int(percentage/5))
|
| 23 |
+
markdown_output += f"**{label}**: {blocks} {percentage:.2f}%\n\n"
|
| 24 |
|
| 25 |
return results, markdown_output
|
| 26 |
|
|
|
|
| 65 |
["The team scored in the final minute to win the championship", "sports, victory, competition, excitement"],
|
| 66 |
["The painting uses vibrant colors to express deep emotions", "art, emotion, creativity, analysis"]
|
| 67 |
],
|
| 68 |
+
cache_examples=False,
|
| 69 |
css="""
|
| 70 |
footer {display:none !important}
|
| 71 |
.output-markdown{display:none !important}
|
|
|
|
| 112 |
font-family: 'Inter', sans-serif !important;
|
| 113 |
color: #11142D !important;
|
| 114 |
}
|
| 115 |
+
"""
|
|
|
|
| 116 |
)
|
| 117 |
|
| 118 |
# Launch the app
|