Update app.py
Browse files
app.py
CHANGED
|
@@ -1,17 +1,30 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
def
|
| 5 |
model = pipeline("text-classification", model = "cross-encoder/qnli-electra-base")
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def main():
|
| 10 |
user_input = st.text_area("Input Text Here")
|
| 11 |
if st.button("Sentiment"):
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
st.write("Sentiment:")
|
| 14 |
-
st.write(
|
|
|
|
|
|
|
| 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()
|