Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,36 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# Load classification model from Hugging Face
|
5 |
+
model_name = "ale-dp/distilbert-base-uncased-finetuned-emotion"
|
6 |
+
text_classifier = pipeline('text-classification', model=model_name)
|
7 |
+
|
8 |
+
# Define class labels
|
9 |
+
class_labels = ["Sadness", "Joy", "Love", "Anger", "Fear", "Surprise"]
|
10 |
+
|
11 |
+
def main():
|
12 |
+
st.title("Ordinal Emotion Classifier")
|
13 |
+
user_input = st.text_area("Enter text:")
|
14 |
+
|
15 |
+
if st.button("Classify"):
|
16 |
+
if user_input:
|
17 |
+
results = classify_text(user_input)
|
18 |
+
display_results(results)
|
19 |
+
else:
|
20 |
+
st.warning("Please enter some text to classify.")
|
21 |
+
|
22 |
+
def classify_text(text):
|
23 |
+
results = text_classifier(text)
|
24 |
+
return results
|
25 |
+
|
26 |
+
def display_results(results):
|
27 |
+
st.subheader("Prediction:")
|
28 |
+
|
29 |
+
for result in results:
|
30 |
+
label = result['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()
|