sm2899 commited on
Commit
2d6a0fb
1 Parent(s): 204de1f

Update sentiment-analyser.py

Browse files
Files changed (1) hide show
  1. sentiment-analyser.py +15 -10
sentiment-analyser.py CHANGED
@@ -3,22 +3,27 @@ from transformers import pipeline
3
 
4
  st.title('Sentiment Analyser App')
5
  st.write('Welcome to my sentiment analysis app!')
 
6
 
7
  form = st.form(key='sentiment-form')
8
- user_input = form.text_area(label='Enter your text to analyse')
 
9
  submit = form.form_submit_button('Submit')
10
 
11
- classifier = pipeline("sentiment-analysis")
12
- result = classifier(user_input)[0]
13
- label = result['label']
14
- score = result['score']
 
 
 
 
15
 
16
  if submit:
17
- classifier = pipeline("sentiment-analysis")
18
- result = classifier(user_input)[0]
19
- label = result['label']
20
- score = result['score']
21
- if label == 'POSITIVE':
22
  st.success(f'{label} sentiment (score: {score})')
23
  else:
24
  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"]
7
 
8
  form = st.form(key='sentiment-form')
9
+ model_type = form.selectbox(label="Select a model", options=model_options)
10
+ user_input = form.text_area(label='Enter your text to analyse', value="Hey how are you?")
11
  submit = form.form_submit_button('Submit')
12
 
13
+ def classification(user_input, type):
14
+ if type=="sentiment-analysis":
15
+ classifier = pipeline("sentiment-analysis")
16
+ elif type==""
17
+ classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-xlm-roberta-base-sentiment")
18
+ result = classifier(user_input)[0]
19
+ return result
20
+
21
 
22
  if submit:
23
+ resultf = classification(user_input, model_type)
24
+ label = resultf['label']
25
+ score = resultf['score']
26
+ if label == 'POSITIVE' or 'Positive':
 
27
  st.success(f'{label} sentiment (score: {score})')
28
  else:
29
  st.error(f'{label} sentiment (score: {score})')