Ryan Kim commited on
Commit
cffde68
1 Parent(s): 0453b0a

pushing code for sentiment analysis

Browse files
Files changed (1) hide show
  1. src/main.py +27 -12
src/main.py CHANGED
@@ -7,23 +7,38 @@ st.title("CSGY-6613 Sentiment Analysis")
7
  st.markdown("## Ryan Kim (rk2546)")
8
  st.markdown("")
9
 
10
- if "model" not in st.session_state:
11
- st.session_state.model = "Test"
12
-
13
- text_input = st.text_input(
14
- "Enter some text 👇",
15
- placeholder="I like burgers...",
16
- )
17
-
18
- if text_input:
19
- st.write("You entered: ", text_input)
20
-
21
- """
22
  @st.cache
23
  def load_model():
24
  classifier = pipeline(task="sentiment-analysis")
25
  return classifier
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  classifier = load_model()
28
 
29
  user_input = input("Please enter a text to perform sentiment analysis upon:\n")
 
7
  st.markdown("## Ryan Kim (rk2546)")
8
  st.markdown("")
9
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  @st.cache
11
  def load_model():
12
  classifier = pipeline(task="sentiment-analysis")
13
  return classifier
14
 
15
+ classifier = load_model()
16
+ placeholder="@AmericanAir just landed - 3hours Late Flight - and now we need to wait TWENTY MORE MINUTES for a gate! I have patience but none for incompetence."
17
+
18
+ #if "model" not in st.session_state:
19
+ # st.session_state.model = "Test"
20
+
21
+ form = st.form(key='sentiment-analysis-form')
22
+ text_input = st.text_area("Enter some text for sentiment analysis!", placeholder=placeholder)
23
+ submit = form.form_submit_button('Submit')
24
+
25
+ if submit:
26
+ if text_input is None or len(text_input.strip()) == 0:
27
+ to_eval = placeholder
28
+ else:
29
+ to_eval = text_input.strip()
30
+ st.write("You entered: ", to_eval)
31
+ result = classifier(to_eval)
32
+ label = result[0]['label']
33
+ score = result[0]['score']
34
+
35
+ if label == 'POSITIVE':
36
+ st.success("{} ==> {})".format(label,score))
37
+ else:
38
+ st.error("{} ==> {})".format(label,score))
39
+
40
+ """
41
+
42
  classifier = load_model()
43
 
44
  user_input = input("Please enter a text to perform sentiment analysis upon:\n")