Ariel Hsieh commited on
Commit
4b8f05e
1 Parent(s): 3247c6f

update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -8
app.py CHANGED
@@ -2,21 +2,19 @@ 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"]
@@ -27,7 +25,7 @@ elif model == "twitter-XLM-roBERTa-base":
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
 
@@ -46,7 +44,7 @@ elif model == "bertweet-sentiment-analysis":
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
 
 
2
  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 == "DistilBERT":
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"]
 
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
 
 
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