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

Update sentiment-analyser.py

Browse files
Files changed (1) hide show
  1. sentiment-analyser.py +12 -9
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", "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)
@@ -17,16 +17,19 @@ def classification(user_input, type):
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
 
25
  if submit:
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})')
 
 
 
 
 
 
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"]
7
 
8
  form = st.form(key='sentiment-form')
9
  model_type = form.selectbox(label="Select a model", options=model_options)
 
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="siebert/sentiment-roberta-large-english"
21
+ classifier = pipeline("sentiment-analysis", model=path)
22
+ result = classifier(user_input)
23
  return result
24
 
25
  if submit:
26
  resultf = classification(user_input, model_type)
27
+ if model_type=="sentiment-roberta-large-english":
28
+ st.write(resultf[0][0] + ": " + resultf[0][1])
 
 
29
  else:
30
+ label = resultf['label'][0]
31
+ score = resultf['score'][0]
32
+ if (label == 'POSITIVE') or (label =='Positive') or (label =='positive'):
33
+ st.success(f'{label} sentiment (score: {score})')
34
+ else:
35
+ st.error(f'{label} sentiment (score: {score})')