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}")