yashkens commited on
Commit
d801d73
1 Parent(s): f15e796

add emotion classification

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +3 -2
  3. emotions.py +16 -0
README.md CHANGED
@@ -7,7 +7,7 @@ sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: app.py
9
  pinned: false
10
- models: cardiffnlp/twitter-roberta-base-emoji
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
7
  sdk_version: 1.10.0
8
  app_file: app.py
9
  pinned: false
10
+ models: mrm8488/t5-base-finetuned-emotion
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
- from emoji import get_emoji
 
3
 
4
  st.title("I don't even know what this is yet")
5
 
@@ -7,6 +8,6 @@ name = st.text_input('Who are you?', 'Zeliboba')
7
  text = st.text_area('Submit your stories', '''Random symbols''')
8
 
9
  st.write('Here is your first text:', text)
10
- st.write(get_emoji(text))
11
 
12
 
 
1
  import streamlit as st
2
+ # from emoji import get_emoji
3
+ from emotions import get_emotion
4
 
5
  st.title("I don't even know what this is yet")
6
 
 
8
  text = st.text_area('Submit your stories', '''Random symbols''')
9
 
10
  st.write('Here is your first text:', text)
11
+ st.write(get_emotion(text))
12
 
13
 
emotions.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelWithLMHead
2
+
3
+ tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-emotion")
4
+
5
+ model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-emotion")
6
+
7
+
8
+ def get_emotion(text):
9
+ input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
10
+
11
+ output = model.generate(input_ids=input_ids,
12
+ max_length=2)
13
+
14
+ dec = [tokenizer.decode(ids) for ids in output]
15
+ label = dec[0]
16
+ return label