Spaces:
Runtime error
Runtime error
Commit
·
0ba7189
1
Parent(s):
f1f8ba6
update code
Browse files
app.py
CHANGED
@@ -1,63 +1,30 @@
|
|
1 |
import streamlit as st
|
2 |
-
|
3 |
-
from transformers import PerceiverTokenizer, PerceiverForMaskedLM
|
4 |
import transformers
|
|
|
|
|
5 |
|
6 |
@st.cache(allow_output_mutation=True, show_spinner=False)
|
7 |
def get_pipe():
|
8 |
-
|
9 |
-
|
|
|
10 |
pipe = transformers.pipeline('text-classification', model=model, tokenizer=tokenizer,
|
11 |
return_all_scores=True, truncation=True)
|
12 |
return pipe
|
13 |
|
14 |
|
15 |
-
|
16 |
-
@st.cache
|
17 |
-
def load_labels():
|
18 |
-
return [
|
19 |
-
"admiration",
|
20 |
-
"amusement",
|
21 |
-
"anger",
|
22 |
-
"annoyance",
|
23 |
-
"approval",
|
24 |
-
"caring",
|
25 |
-
"confusion",
|
26 |
-
"curiosity",
|
27 |
-
"desire",
|
28 |
-
"disappointment",
|
29 |
-
"disapproval",
|
30 |
-
"disgust",
|
31 |
-
"embarrassment",
|
32 |
-
"excitement",
|
33 |
-
"fear",
|
34 |
-
"gratitude",
|
35 |
-
"grief",
|
36 |
-
"joy",
|
37 |
-
"love",
|
38 |
-
"nervousness",
|
39 |
-
"optimism",
|
40 |
-
"pride",
|
41 |
-
"realization",
|
42 |
-
"relief",
|
43 |
-
"remorse",
|
44 |
-
"sadness",
|
45 |
-
"surprise",
|
46 |
-
"neutral"
|
47 |
-
]
|
48 |
-
|
49 |
def sort_predictions(predictions):
|
50 |
return sorted(predictions, key=lambda x: x['score'], reverse=True)
|
51 |
|
52 |
|
53 |
-
st.set_page_config(page_title="
|
54 |
-
st.title("
|
55 |
-
st.write("Type text into the text box and then press '
|
56 |
|
57 |
-
default_text = "
|
58 |
|
59 |
text = st.text_area('Enter text here:', value=default_text)
|
60 |
-
submit = st.button('
|
61 |
|
62 |
with st.spinner("Loading model..."):
|
63 |
pipe = get_pipe()
|
@@ -74,7 +41,7 @@ if (submit and len(text.strip()) > 0) or len(text.strip()) > 0:
|
|
74 |
ax.tick_params(rotation=90)
|
75 |
ax.set_ylim(0, 1)
|
76 |
|
77 |
-
st.header('
|
78 |
st.pyplot(fig)
|
79 |
|
80 |
prediction = dict([(p['label'], p['score']) for p in prediction])
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import transformers
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
|
6 |
@st.cache(allow_output_mutation=True, show_spinner=False)
|
7 |
def get_pipe():
|
8 |
+
model_name = "joeddav/distilbert-base-uncased-go-emotions-student"
|
9 |
+
model = transformers.AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
|
11 |
pipe = transformers.pipeline('text-classification', model=model, tokenizer=tokenizer,
|
12 |
return_all_scores=True, truncation=True)
|
13 |
return pipe
|
14 |
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def sort_predictions(predictions):
|
17 |
return sorted(predictions, key=lambda x: x['score'], reverse=True)
|
18 |
|
19 |
|
20 |
+
st.set_page_config(page_title="Affect scores")
|
21 |
+
st.title("Affect scores")
|
22 |
+
st.write("Type text into the text box and then press 'Compute' to generate affect scores.")
|
23 |
|
24 |
+
default_text = "It's about a startup taking on a big yet creative challenge, with ups and downs along the way."
|
25 |
|
26 |
text = st.text_area('Enter text here:', value=default_text)
|
27 |
+
submit = st.button('Generate')
|
28 |
|
29 |
with st.spinner("Loading model..."):
|
30 |
pipe = get_pipe()
|
|
|
41 |
ax.tick_params(rotation=90)
|
42 |
ax.set_ylim(0, 1)
|
43 |
|
44 |
+
st.header('Result:')
|
45 |
st.pyplot(fig)
|
46 |
|
47 |
prediction = dict([(p['label'], p['score']) for p in prediction])
|