Spaces:
Running
Running
JustHuggingFaces
commited on
Commit
•
44ee5e5
1
Parent(s):
f93250f
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
# Load the text classification model pipeline
|
4 |
+
classifier = pipeline("text-classification", model='isom5240sp24/bert-base-uncased-emotion', return_all_scores=True)
|
5 |
+
# Streamlit application title
|
6 |
+
st.title("Text Classification")
|
7 |
+
st.write("Classification for 6 emotions: sadness, joy, love, anger, fear, surprise")
|
8 |
+
# Text input for user to enter the text to classify
|
9 |
+
text = st.text_area("Enter the text to classify", "")
|
10 |
+
# Perform text classification when the user clicks the "Classify" button
|
11 |
+
if st.button("Classify"):
|
12 |
+
# Perform text classification on the input text
|
13 |
+
results = classifier(text)[0]
|
14 |
+
# Display the classification result
|
15 |
+
max_score = float('-inf')
|
16 |
+
max_label = ''
|
17 |
+
for result in results:
|
18 |
+
if result['score'] > max_score:
|
19 |
+
max_score = result['score']
|
20 |
+
max_label = result['label']
|
21 |
+
st.write("Text:", text)
|
22 |
+
st.write("Label:", max_label)
|
23 |
+
st.write("Score:", max_score
|