Dineth98 commited on
Commit
9d5a490
1 Parent(s): 9f0871c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -1,17 +1,30 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
- def summarize_text(text):
5
  model = pipeline("text-classification", model = "cross-encoder/qnli-electra-base")
6
- text_input = model(text)
7
- return text_input
 
 
8
 
9
  def main():
10
  user_input = st.text_area("Input Text Here")
11
  if st.button("Sentiment"):
12
- summary = summarize_text(user_input)
 
 
 
 
 
 
 
 
 
13
  st.write("Sentiment:")
14
- st.write(summary)
 
 
15
 
16
  if __name__ == "__main__":
17
  main()
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+ def sentiment_funtion(text):
5
  model = pipeline("text-classification", model = "cross-encoder/qnli-electra-base")
6
+ output = model(text)[0]
7
+ label = output["label"]
8
+ score = output["score"]
9
+ return label , score
10
 
11
  def main():
12
  user_input = st.text_area("Input Text Here")
13
  if st.button("Sentiment"):
14
+ label , score = sentiment_funtion(user_input)
15
+ if label == "LABEL_0":
16
+ label = "Positive"
17
+ postive_score = score
18
+ negative_score = 1 - score
19
+ else:
20
+ label = "Negative"
21
+ postive_score = 1 - score
22
+ negative_score = score
23
+
24
  st.write("Sentiment:")
25
+ st.write(label)
26
+ st.write(postive_score)
27
+ st.write(negative_score)
28
 
29
  if __name__ == "__main__":
30
  main()