File size: 1,073 Bytes
eebd499
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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}')