Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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-
|
5 |
+
uncased-emotion', return_all_scores=True)
|
6 |
+
# Streamlit application title
|
7 |
+
st.title("Text Classification for you")
|
8 |
+
st.write("Classification for 6 emotions: sadness, joy, love, anger, fear,
|
9 |
+
surprise")
|
10 |
+
# Text input for user to enter the text to classify
|
11 |
+
text = st.text_area("Enter the text to classify", "")
|
12 |
+
# Perform text classification when the user clicks the "Classify" button
|
13 |
+
if st.button("Classify"):
|
14 |
+
# Perform text classification on the input text
|
15 |
+
results = classifier(text)[0]
|
16 |
+
# Display the classification result
|
17 |
+
max_score = float('-inf')
|
18 |
+
max_label = ''
|
19 |
+
for result in results:
|
20 |
+
if result['score'] > max_score:
|
21 |
+
max_score = result['score']
|
22 |
+
max_label = result['label']
|
23 |
+
st.write("Text:", text)
|
24 |
+
st.write("Label:", max_label)
|
25 |
+
st.write("Score:", max_score)
|