Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from EnYa32/AppReviewsSentimentAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/EnYa32/AppReviewsSentimentAnalysis/resolve/main/src/streamlit_app.py
- Command line
-
hf download hf://spaces/EnYa32/AppReviewsSentimentAnalysis/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/EnYa32/AppReviewsSentimentAnalysis/resolve/main/src/streamlit_app.py
2.26 kB
| import streamlit as st | |
| import pandas as pd | |
| from textblob import TextBlob | |
| from wordcloud import WordCloud | |
| st.set_page_config(page_title="App Reviews Sentiment", layout="centered") | |
| st.title("Sentiment Analysis of App Reviews (TextBlob)") | |
| st.write("Enter a review text and get sentiment (pos/neg/neu) + polarity score.") | |
| # ---------- User input ---------- | |
| user_text = st.text_area("Review text", height=120, placeholder="Type a review here...") | |
| if st.button("Analyze"): | |
| if user_text.strip() == "": | |
| st.warning("Please enter some text.") | |
| else: | |
| blob = TextBlob(user_text) | |
| polarity = blob.sentiment.polarity | |
| subjectivity = blob.sentiment.subjectivity | |
| if polarity > 0: | |
| label = "pos" | |
| elif polarity < 0: | |
| label = "neg" | |
| else: | |
| label = "neu" | |
| st.subheader("Result") | |
| st.write(f"**Sentiment:** {label}") | |
| st.write(f"**Polarity:** {polarity:.3f}") | |
| st.write(f"**Subjectivity:** {subjectivity:.3f}") | |
| st.divider() | |
| # ---------- Optional: Dataset + Wordclouds ---------- | |
| st.subheader("Optional: WordClouds from Dataset") | |
| uploaded = st.file_uploader("Upload your CSV (must contain columns: Review, Rating)", type=["csv"]) | |
| if uploaded is not None: | |
| df = pd.read_csv(uploaded) | |
| # Basic checks | |
| if "Review" not in df.columns: | |
| st.error("CSV must contain a 'Review' column.") | |
| else: | |
| # Compute polarity + sentiment | |
| df["polarity"] = df["Review"].astype(str).apply(lambda x: TextBlob(x).sentiment.polarity) | |
| df["sentiment"] = df["polarity"].apply(lambda x: "pos" if x > 0 else "neg" if x < 0 else "neu") | |
| st.write("Sentiment counts:") | |
| st.dataframe(df["sentiment"].value_counts().rename_axis("sentiment").to_frame("count")) | |
| choice = st.selectbox("Choose sentiment for WordCloud", ["neg", "neu", "pos"]) | |
| text = " ".join(df[df["sentiment"] == choice]["Review"].astype(str)) | |
| if text.strip() == "": | |
| st.warning("No text available for this sentiment group.") | |
| else: | |
| wc_img = WordCloud(background_color="white", width=800, height=400).generate(text).to_image() | |
| st.image(wc_img, caption=f"WordCloud: {choice}", use_container_width=True) |