Spaces:
Sleeping
Sleeping
Khalaji, Ali
commited on
Commit
•
bd2f6d2
1
Parent(s):
02f37a3
Add class probs
Browse files
app.py
CHANGED
@@ -20,17 +20,21 @@ def main():
|
|
20 |
st.warning("Please enter some text to classify.")
|
21 |
|
22 |
def classify_text(text):
|
23 |
-
results = text_classifier(text)
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
def display_results(results):
|
27 |
st.subheader("Prediction:")
|
28 |
|
29 |
-
for
|
30 |
-
label
|
31 |
-
score = result['score']
|
32 |
-
score_percent = score * 100
|
33 |
-
st.write(f"{label}: {score_percent:.2f}%")
|
34 |
|
35 |
if __name__ == "__main__":
|
36 |
main()
|
|
|
20 |
st.warning("Please enter some text to classify.")
|
21 |
|
22 |
def classify_text(text):
|
23 |
+
results = text_classifier(text, return_all_scores=True)
|
24 |
+
scores_list = results[0]
|
25 |
+
total_score = sum(score['score'] for score in scores_list)
|
26 |
+
labeled_probabilities = {}
|
27 |
+
for score in scores_list:
|
28 |
+
label = score['label']
|
29 |
+
probability = (score['score'] / total_score) * 100
|
30 |
+
labeled_probabilities[label] = probability
|
31 |
+
return labeled_probabilities
|
32 |
|
33 |
def display_results(results):
|
34 |
st.subheader("Prediction:")
|
35 |
|
36 |
+
for label, probability in results.items():
|
37 |
+
st.write(f"{label.lower()}: {probability:.2f}%")
|
|
|
|
|
|
|
38 |
|
39 |
if __name__ == "__main__":
|
40 |
main()
|