File size: 1,095 Bytes
e9aa866
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from transformers import pipeline

# Load the sentiment pipeline
sentiment_pipeline = pipeline("sentiment-analysis", model="fitsblb/YelpReviewsAnalyzer")

def map_sentiment_label(label):
    return {
        "LABEL_0": "❌ Negative",
        "LABEL_1": "⚖️ Neutral",
        "LABEL_2": "✅ Positive"
    }.get(label, "🤷 Unknown")

st.set_page_config(page_title="Yelp Sentiment Analyzer", layout="centered")
st.title("🍽️ Yelp Sentiment Analyzer")
st.markdown("Enter a restaurant review and see the model's sentiment prediction:")

example = "The food was amazing but the wait was long."
review = st.text_area("Review", example)

if st.button("Analyze Sentiment"):
    if review.strip() == "":
        st.warning("Please enter a review.")
    else:
        with st.spinner("Analyzing..."):
            result = sentiment_pipeline(review)[0]
            label = result["label"]
            confidence = round(result["score"], 3)
            st.success(f"**Sentiment:** {map_sentiment_label(label)}\n\n**Confidence:** {confidence}")