Spaces:
Runtime error
Runtime error
Ariel Hsieh
commited on
Commit
•
6c5dac1
1
Parent(s):
09de9ab
update app.py
Browse files
app.py
CHANGED
@@ -21,20 +21,32 @@ if model == "DistilBERT":
|
|
21 |
label = result[0]["label"]
|
22 |
score = result[0]["score"]
|
23 |
st.write("The classification of the given text is " + label + " with a score of " + str(score))
|
24 |
-
elif model == "
|
25 |
#2
|
26 |
if st.button("Run Sentiment Analysis of Text"):
|
27 |
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
28 |
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
29 |
result = sentiment_task(text)
|
30 |
-
|
|
|
|
|
31 |
|
32 |
elif model == "bertweet-sentiment-analysis":
|
33 |
#3
|
34 |
if st.button("Run Sentiment Analysis of Text"):
|
35 |
analyzer = create_analyzer(task="sentiment", lang="en")
|
36 |
result = analyzer.predict(text)
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
|
40 |
|
|
|
21 |
label = result[0]["label"]
|
22 |
score = result[0]["score"]
|
23 |
st.write("The classification of the given text is " + label + " with a score of " + str(score))
|
24 |
+
elif model == "twitter-XLM-roBERTa-base":
|
25 |
#2
|
26 |
if st.button("Run Sentiment Analysis of Text"):
|
27 |
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
28 |
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
29 |
result = sentiment_task(text)
|
30 |
+
label = result[0]["label"]
|
31 |
+
score = result[0]["score"]
|
32 |
+
st.write("The classification of the given text is " + label + " with a score of " + str(score))
|
33 |
|
34 |
elif model == "bertweet-sentiment-analysis":
|
35 |
#3
|
36 |
if st.button("Run Sentiment Analysis of Text"):
|
37 |
analyzer = create_analyzer(task="sentiment", lang="en")
|
38 |
result = analyzer.predict(text)
|
39 |
+
if result.output == "POS":
|
40 |
+
label = "POSITIVE"
|
41 |
+
elif result.output == "NEU":
|
42 |
+
label = "NEUTRAL"
|
43 |
+
else:
|
44 |
+
label = "NEGATIVE"
|
45 |
+
|
46 |
+
neg = result.probas["NEG"]
|
47 |
+
pos = result.probas["POS"]
|
48 |
+
neu = result.probas["NEU"]
|
49 |
+
st.write("The classification of the given text is " + label + " with the percentages broken down as: Positive - " + str(pos) + ", Neutral - " + str(neu) + ", Negative - " + str(neg))
|
50 |
|
51 |
|
52 |
|