Spaces:
Sleeping
Sleeping
Download app.py from faiqyy/sentiment_analysis: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/faiqyy/sentiment_analysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/faiqyy/sentiment_analysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/faiqyy/sentiment_analysis/resolve/main/app.py
1.17 kB
| import streamlit as st | |
| from textblob import TextBlob | |
| # Streamlit UI | |
| st.set_page_config(page_title="Text Sentiment Analyzer", layout="centered") | |
| st.title("π§ Sentiment Analyzer with Polarity & Subjectivity") | |
| st.write("Enter your text to see sentiment label, polarity, and subjectivity.") | |
| # Input | |
| user_input = st.text_area("Enter your text here:", height=150) | |
| # Analysis Function | |
| def analyze_text(text): | |
| blob = TextBlob(text) | |
| polarity = blob.sentiment.polarity # -1 to +1 | |
| subjectivity = blob.sentiment.subjectivity # 0 to 1 | |
| if polarity > 0: | |
| sentiment = "Positive π" | |
| elif polarity < 0: | |
| sentiment = "Negative π" | |
| else: | |
| sentiment = "Neutral π" | |
| return sentiment, polarity, subjectivity | |
| # Output | |
| if st.button("Analyze Sentiment"): | |
| if user_input.strip(): | |
| sentiment, polarity, subjectivity = analyze_text(user_input) | |
| st.success(f"Sentiment: **{sentiment}**") | |
| st.info(f"Polarity: `{polarity:.2f}` (β1 = Negative, +1 = Positive)") | |
| st.info(f"Subjectivity: `{subjectivity:.2f}` (0 = Objective, 1 = Subjective)") | |
| else: | |
| st.warning("Please enter some text.") | |