theresatvan commited on
Commit
eb311d6
1 Parent(s): 7c49160

Add sentiment analyzer for user input text

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -1,4 +1,26 @@
1
  import streamlit as st
 
2
 
3
- x = st.slider('Select a value')
4
- st.write(x, 'squared is', x * x)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
 
4
+ st.title("Text Sentiment Analyzer")
5
+
6
+ # Create submission form
7
+ form = st.form("sentiment-form")
8
+ input = form.text_area('Enter your text here.')
9
+ submit = form.form_submit_button("Submit")
10
+
11
+ if submit:
12
+ # Use pre-trained sentiment analysis model
13
+ classifier = pipeline(task="sentiment-analysis")
14
+
15
+ # Extract prediction from the results
16
+ pred = classifier(input)[0]
17
+ label= pred['label']
18
+ score = pred['score']
19
+
20
+ if label == "POSITIVE":
21
+ # Green output text box
22
+ st.success("{} sentiment (score: {})".format(label, score))
23
+
24
+ else:
25
+ # Red output text box
26
+ st.error("{} sentiment (score: {})".format(label, score))