add emotion classification
Browse files- README.md +1 -1
- app.py +1 -1
- emotions.py +7 -12
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:
|
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: bhadresh-savani/distilbert-base-uncased-emotion
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -8,6 +8,6 @@ name = st.text_input('Who are you?', 'Zeliboba')
|
|
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 |
|
|
|
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)['label'])
|
12 |
|
13 |
|
emotions.py
CHANGED
@@ -1,16 +1,11 @@
|
|
1 |
-
from transformers import
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
|
7 |
|
8 |
def get_emotion(text='No text yet'):
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
max_length=2)
|
13 |
-
|
14 |
-
dec = [tokenizer.decode(ids) for ids in output]
|
15 |
-
label = dec[0]
|
16 |
-
return label
|
|
|
1 |
+
from transformers import pipeline
|
2 |
|
3 |
+
classifier = pipeline("text-classification",
|
4 |
+
model='bhadresh-savani/distilbert-base-uncased-emotion',
|
5 |
+
return_all_scores=True)
|
6 |
|
7 |
|
8 |
def get_emotion(text='No text yet'):
|
9 |
+
prediction = classifier(text)[0]
|
10 |
+
result = max(prediction, key=lambda x: x['score'])
|
11 |
+
return result
|
|
|
|
|
|
|
|
|
|