|
import streamlit as st |
|
from transformers import AutoTokenizer, AutoModelForSequenceClassification,tokenzir |
|
from scipy.special import softmax |
|
|
|
|
|
|
|
model_dir = "./" |
|
tokenizer = AutoTokenizer.from_pretrained(model_dir) |
|
model = AutoModelForSequenceClassification.from_pretrained(model_dir) |
|
|
|
|
|
st.title('Sentiment Analysis with Fine Tuned Model') |
|
st.write('Enter some text ') |
|
|
|
|
|
|
|
text_input = st.text_input('Enter text here') |
|
|
|
if st.button('Submit'): |
|
|
|
|
|
inputs = tokenizer(text_input, return_tensors="pt") |
|
|
|
|
|
output = model(**inputs) |
|
|
|
scores = output[0][0].detach().numpy() |
|
scores = softmax(scores) |
|
scores_dict = { |
|
'Negative': scores[0], |
|
'Neutral': scores[1], |
|
'Positive': scores[2] |
|
} |
|
max_key = max(scores_dict, key=scores_dict.get) |
|
|
|
|
|
sentiment = str(scores_dict[max_key]) |
|
|
|
|
|
st.write(f'Sentiment is {data["sentiment"]}') |
|
st.write(f'Score is {max_key}') |
|
|