sm2899 commited on
Commit
2f411bc
1 Parent(s): 1a488b8

Update sentiment-analyser.py

Browse files
Files changed (1) hide show
  1. sentiment-analyser.py +5 -2
sentiment-analyser.py CHANGED
@@ -3,7 +3,7 @@ from transformers import pipeline, AutoTokenizer
3
 
4
  st.title('Sentiment Analyser App')
5
  st.write('Welcome to my sentiment analysis app!')
6
- model_options=["sentiment-analysis", "twitter-xlm-roberta-base-sentiment"]
7
 
8
  form = st.form(key='sentiment-form')
9
  model_type = form.selectbox(label="Select a model", options=model_options)
@@ -16,6 +16,9 @@ def classification(user_input, type):
16
  elif type=="twitter-xlm-roberta-base-sentiment":
17
  path="cardiffnlp/twitter-xlm-roberta-base-sentiment"
18
  classifier = pipeline("sentiment-analysis", model=path, tokenizer=path)
 
 
 
19
  result = classifier(user_input)[0]
20
  return result
21
 
@@ -23,7 +26,7 @@ if submit:
23
  resultf = classification(user_input, model_type)
24
  label = resultf['label']
25
  score = resultf['score']
26
- if (label == 'POSITIVE') or (label =='Positive'):
27
  st.success(f'{label} sentiment (score: {score})')
28
  else:
29
  st.error(f'{label} sentiment (score: {score})')
 
3
 
4
  st.title('Sentiment Analyser App')
5
  st.write('Welcome to my sentiment analysis app!')
6
+ model_options=["sentiment-analysis", "twitter-xlm-roberta-base-sentiment", "sentiment-roberta-large-english-3-classes"]
7
 
8
  form = st.form(key='sentiment-form')
9
  model_type = form.selectbox(label="Select a model", options=model_options)
 
16
  elif type=="twitter-xlm-roberta-base-sentiment":
17
  path="cardiffnlp/twitter-xlm-roberta-base-sentiment"
18
  classifier = pipeline("sentiment-analysis", model=path, tokenizer=path)
19
+ elif type=="sentiment-roberta-large-english-3-classes":
20
+ path="j-hartmann/sentiment-roberta-large-english-3-classes"
21
+ classifier = pipeline("text-classification", model=path, return_all_scores=True)
22
  result = classifier(user_input)[0]
23
  return result
24
 
 
26
  resultf = classification(user_input, model_type)
27
  label = resultf['label']
28
  score = resultf['score']
29
+ if (label == 'POSITIVE') or (label =='Positive') or (label =='positive'):
30
  st.success(f'{label} sentiment (score: {score})')
31
  else:
32
  st.error(f'{label} sentiment (score: {score})')