Spaces:
Sleeping
Sleeping
update
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
import numpy as np
|
|
|
5 |
|
6 |
|
7 |
# Define the function for sentiment analysis
|
@@ -30,13 +31,13 @@ image = st.image("images.png", width=200)
|
|
30 |
# Get user input
|
31 |
text = st.text_input("Type here:")
|
32 |
button = st.button('Analyze')
|
33 |
-
d = {
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
}
|
40 |
# Define the CSS style for the app
|
41 |
st.markdown(
|
42 |
"""
|
@@ -79,9 +80,14 @@ def get_model():
|
|
79 |
tokenizer, model = get_model()
|
80 |
|
81 |
if text and button:
|
82 |
-
text_sample = tokenizer(
|
83 |
-
print(text_sample)
|
84 |
-
output = model(text_sample)
|
|
|
|
|
|
|
|
|
|
|
85 |
# st.write("Logits: ",output.logits)
|
86 |
# y_pred = np.argmax(output.logits.detach().numpy(),axis =1)
|
87 |
-
|
|
|
2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
3 |
import torch
|
4 |
import numpy as np
|
5 |
+
from scipy.special import softmax
|
6 |
|
7 |
|
8 |
# Define the function for sentiment analysis
|
|
|
31 |
# Get user input
|
32 |
text = st.text_input("Type here:")
|
33 |
button = st.button('Analyze')
|
34 |
+
# d = {
|
35 |
|
36 |
+
# 0:'Negative',
|
37 |
+
# 1:'Neutral',
|
38 |
+
# 2: 'Positive'
|
39 |
|
40 |
+
# }
|
41 |
# Define the CSS style for the app
|
42 |
st.markdown(
|
43 |
"""
|
|
|
80 |
tokenizer, model = get_model()
|
81 |
|
82 |
if text and button:
|
83 |
+
text_sample = tokenizer(text, padding = 'max_length',return_tensors = 'pt')
|
84 |
+
# print(text_sample)
|
85 |
+
output = model(**text_sample)
|
86 |
+
scores_ = output[0][0].detach().numpy()
|
87 |
+
scores_ = softmax(scores_)
|
88 |
+
|
89 |
+
labels = ['Negative','Neutral','Positive']
|
90 |
+
scores = {l:float(s) for (l,s) in zip(labels,scores_)}
|
91 |
# st.write("Logits: ",output.logits)
|
92 |
# y_pred = np.argmax(output.logits.detach().numpy(),axis =1)
|
93 |
+
st.write("Prediction :",labels)
|