Spaces:
Sleeping
Sleeping
Download app.py from fitsblb/YelpSentimentAnalyzer: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/fitsblb/YelpSentimentAnalyzer/resolve/main/app.py
- Command line
-
hf download hf://spaces/fitsblb/YelpSentimentAnalyzer/app.py
-
curl -L -o app.py https://huggingface.co/spaces/fitsblb/YelpSentimentAnalyzer/resolve/main/app.py
1.1 kB
| 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}") | |