Daulet9900 commited on
Commit
48ec688
1 Parent(s): e2392af

Add all emotions and their persentage of 1

Browse files
Files changed (2) hide show
  1. app.py +13 -7
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
3
 
4
  print ("Load model...")
5
 
@@ -9,8 +10,8 @@ emotion_classifier = pipeline("text-classification", model=model_name)
9
 
10
  # Title and Description
11
  st.title("Emotion Classifier")
12
- st.write("""write down how your day went or what your mood is.
13
- On this space used model "bhadresh-savani/distilbert-base-uncased-emotion"
14
  """)
15
 
16
  # Input text box
@@ -21,8 +22,13 @@ if st.button("Classify Emotion"):
21
  st.write("Please enter some text to classify.")
22
  else:
23
  # Get classification results
24
- results = emotion_classifier(input_text)
25
- st.subheader("Predicted Emotions:")
26
- for result in results:
27
- st.write(f"**{result['label']}**: {result['score']:.4f}")
28
- st.write(f"**{result['label']}**: {result['score']:.4f}")
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ import numpy as np
4
 
5
  print ("Load model...")
6
 
 
10
 
11
  # Title and Description
12
  st.title("Emotion Classifier")
13
+ st.write("""write down how your day went or what your mood is.""")
14
+ st.write("""On this space used model "bhadresh-savani/distilbert-base-uncased-emotion".
15
  """)
16
 
17
  # Input text box
 
22
  st.write("Please enter some text to classify.")
23
  else:
24
  # Get classification results
25
+ results = emotion_classifier(input_text, top_k=None)
26
+
27
+ # Extract scores and normalize to sum to 1
28
+ scores = np.array([result["score"] for result in results])
29
+ normalized_scores = scores / scores.sum()
30
+
31
+ # Display normalized results
32
+ st.subheader("Emotions:")
33
+ for i, result in enumerate(results):
34
+ st.write(f"**{result['label']}**: {normalized_scores[i]:.4f}")
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  streamlit==1.41.1
2
  transformers
3
- torch
 
 
1
  streamlit==1.41.1
2
  transformers
3
+ torch
4
+ numpy