faizack's picture
added app
eebd499 verified
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification,tokenzir
from scipy.special import softmax
# Load the fine-tuned model and tokenizer
model_dir = "./"
tokenizer = AutoTokenizer.from_pretrained(model_dir)
model = AutoModelForSequenceClassification.from_pretrained(model_dir)
# Create a Streamlit app
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'):
# Tokenize the text
inputs = tokenizer(text_input, return_tensors="pt")
# Perform prediction
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)
# Get the maximum value
sentiment = str(scores_dict[max_key])
# Display the results
st.write(f'Sentiment is {data["sentiment"]}')
st.write(f'Score is {max_key}')