Ariel Hsieh commited on
Commit
e4f9c2a
1 Parent(s): 1bc7870
Files changed (1) hide show
  1. app.py +43 -38
app.py CHANGED
@@ -3,48 +3,53 @@ from transformers import pipeline
3
  from pysentimiento import create_analyzer
4
 
5
  #title
6
- st.title("Sentiment Analysis - Classify Sentiment of text")
7
 
8
  model = st.selectbox("Which pretrained model would you like to use?",("roberta-large-mnli","twitter-XLM-roBERTa-base","bertweet-sentiment-analysis"))
9
 
10
- data = []
11
- text = st.text_input("Enter text here:","Artificial Intelligence is useful")
12
- data.append(text)
13
- if model == "roberta-large-mnli":
14
- #1
15
- if st.button("Run Sentiment Analysis of Text"):
16
- model_path = "roberta-large-mnli"
17
- sentiment_pipeline = pipeline(model=model_path)
18
- result = sentiment_pipeline(data)
19
- label = result[0]["label"]
20
- score = result[0]["score"]
21
- st.write("The classification of the given text is " + label + " with a score of " + str(score))
22
- elif model == "twitter-XLM-roBERTa-base":
23
- #2
24
- if st.button("Run Sentiment Analysis of Text"):
25
- model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
26
- sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
27
- result = sentiment_task(text)
28
- label = result[0]["label"].capitalize()
29
- score = result[0]["score"]
30
- st.write("The classification of the given text is " + label + " with a score of " + str(score))
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
- if result.output == "POS":
38
- label = "POSITIVE"
39
- elif result.output == "NEU":
40
- label = "NEUTRAL"
41
- else:
42
- label = "NEGATIVE"
 
 
 
 
 
43
 
44
- neg = result.probas["NEG"]
45
- pos = result.probas["POS"]
46
- neu = result.probas["NEU"]
47
- st.write("The classification of the given text is " + label + " with the scores broken down as: Positive - " + str(pos) + ", Neutral - " + str(neu) + ", Negative - " + str(neg))
48
 
49
 
50
 
 
3
  from pysentimiento import create_analyzer
4
 
5
  #title
6
+ st.title("Toxic Tweets")
7
 
8
  model = st.selectbox("Which pretrained model would you like to use?",("roberta-large-mnli","twitter-XLM-roBERTa-base","bertweet-sentiment-analysis"))
9
 
10
+ d = {'col1':[1,2],'col2':[3,4]}
11
+ data = pd.DataFrame(data=d)
12
+ st.table(data)
13
+
14
+
15
+ # data = []
16
+ # text = st.text_input("Enter text here:","Artificial Intelligence is useful")
17
+ # data.append(text)
18
+ # if model == "roberta-large-mnli":
19
+ # #1
20
+ # if st.button("Run Sentiment Analysis of Text"):
21
+ # model_path = "roberta-large-mnli"
22
+ # sentiment_pipeline = pipeline(model=model_path)
23
+ # result = sentiment_pipeline(data)
24
+ # label = result[0]["label"]
25
+ # score = result[0]["score"]
26
+ # st.write("The classification of the given text is " + label + " with a score of " + str(score))
27
+ # elif model == "twitter-XLM-roBERTa-base":
28
+ # #2
29
+ # if st.button("Run Sentiment Analysis of Text"):
30
+ # model_path = "cardiffnlp/twitter-xlm-roberta-base-sentiment"
31
+ # sentiment_task = pipeline("sentiment-analysis", model=model_path, tokenizer=model_path)
32
+ # result = sentiment_task(text)
33
+ # label = result[0]["label"].capitalize()
34
+ # score = result[0]["score"]
35
+ # st.write("The classification of the given text is " + label + " with a score of " + str(score))
36
+
37
+ # elif model == "bertweet-sentiment-analysis":
38
+ # #3
39
+ # if st.button("Run Sentiment Analysis of Text"):
40
+ # analyzer = create_analyzer(task="sentiment", lang="en")
41
+ # result = analyzer.predict(text)
42
+ # if result.output == "POS":
43
+ # label = "POSITIVE"
44
+ # elif result.output == "NEU":
45
+ # label = "NEUTRAL"
46
+ # else:
47
+ # label = "NEGATIVE"
48
 
49
+ # neg = result.probas["NEG"]
50
+ # pos = result.probas["POS"]
51
+ # neu = result.probas["NEU"]
52
+ # st.write("The classification of the given text is " + label + " with the scores broken down as: Positive - " + str(pos) + ", Neutral - " + str(neu) + ", Negative - " + str(neg))
53
 
54
 
55