Spaces:
Runtime error
Runtime error
Ariel Hsieh
commited on
Commit
•
bd8d813
1
Parent(s):
af1454e
update app.py
Browse files
app.py
CHANGED
@@ -1,18 +1,39 @@
|
|
1 |
import streamlit as st #Web App
|
2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
#title
|
5 |
st.title("Sentiment Analysis - Classify Sentiment of text")
|
6 |
|
7 |
data = []
|
8 |
text = st.text_input("Enter text here:","Artificial Intelligence is useful")
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
|
|
|
1 |
import streamlit as st #Web App
|
2 |
from transformers import pipeline
|
3 |
+
from pysentimiento import create_analyzer
|
4 |
+
|
5 |
+
|
6 |
+
|
7 |
+
model = st.selectbox("Which pretrained model would you like to use?",("DistilBERT","twitter-XLM-roBERTa-base","bertweet-sentiment-analysis"))
|
8 |
|
9 |
#title
|
10 |
st.title("Sentiment Analysis - Classify Sentiment of text")
|
11 |
|
12 |
data = []
|
13 |
text = st.text_input("Enter text here:","Artificial Intelligence is useful")
|
14 |
+
data.append(text)
|
15 |
+
if model == "DistilBERT":
|
16 |
+
#1
|
17 |
+
if st.button("Run Sentiment Analysis of Text"):
|
18 |
+
model_path = "distilbert-base-uncased-finetuned-sst-2-english"
|
19 |
+
sentiment_pipeline = pipeline("sentiment-analysis",model=model_path, tokenizer=model_path)
|
20 |
+
result = sentiment_pipeline(data)
|
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-roBERTa-base":
|
25 |
+
#2
|
26 |
+
model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
|
27 |
+
sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
|
28 |
+
result = sentiment_task(text)
|
29 |
+
st.write(result)
|
30 |
+
|
31 |
+
elif model == "bertweet-sentiment-analysis":
|
32 |
+
#3
|
33 |
+
analyzer = create_analyzer(task="sentiment", lang="en")
|
34 |
+
result = analyzer.predict(text)
|
35 |
+
st.write(result)
|
36 |
+
|
37 |
|
38 |
|
39 |
|