File size: 1,215 Bytes
8ccbec1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline

# Load the tokenizer and model
tokenizer = AutoTokenizer.from_pretrained("OatNapat/finetuned_yelp")
model = AutoModelForSequenceClassification.from_pretrained("OatNapat/finetuned_yelp")

# Create a sentiment analysis pipeline with the explicit tokenizer
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)

st.title("Sentiment Analysis App")
user_input = st.text_input("ป้อนประโยคเพื่อวิเคราะห์ความรู้สึก:")
if user_input:
    result = nlp(user_input)
    sentiment_label = result[0]["label"]
    sentiment_score = result[0]["score"]

    # Define explanations for sentiment labels
    sentiment_explanations = {
        "LABEL_0": "Very negative",
        "LABEL_1": "Negative",
        "LABEL_2": "Neutral",
        "LABEL_3": "Positive",
        "LABEL_4": "Very positive"
    }

    # Get the explanation for the sentiment label
    sentiment_explanation = sentiment_explanations.get(sentiment_label, "Unknown")

    st.write(f"Sentiment: {sentiment_explanation}")
    st.write(f"Confidence: {sentiment_score:.4f}")