Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +40 -4
src/streamlit_app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from pathlib import Path
|
|
|
|
|
|
|
| 4 |
|
| 5 |
st.set_page_config(page_title="Customer Experience Analyzer", layout="wide")
|
| 6 |
|
|
@@ -48,6 +50,34 @@ if total_reviews > 0:
|
|
| 48 |
else:
|
| 49 |
st.warning("No reviews match the selected filters.")
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# Example reviews
|
| 52 |
st.subheader("Example Customer Reviews")
|
| 53 |
|
|
@@ -85,7 +115,7 @@ if total_reviews > 0:
|
|
| 85 |
f"""
|
| 86 |
- Out of **{total_reviews}** filtered reviews, **{positive_rate:.1f}%** are positive and **{negative_rate:.1f}%** are negative.
|
| 87 |
- This helps management quickly assess overall customer satisfaction.
|
| 88 |
-
- Searching by keyword can help identify specific issues
|
| 89 |
"""
|
| 90 |
)
|
| 91 |
else:
|
|
@@ -98,9 +128,9 @@ if total_reviews > 0:
|
|
| 98 |
if negative_rate > 60:
|
| 99 |
st.warning("Customer dissatisfaction is high. Management should urgently review repeated complaints and investigate operational issues.")
|
| 100 |
elif negative_rate > 40:
|
| 101 |
-
st.info("Customer sentiment is mixed. Management should identify
|
| 102 |
else:
|
| 103 |
-
st.success("Customer sentiment is mostly positive. Management should preserve strengths and
|
| 104 |
else:
|
| 105 |
st.write("No recommendation available.")
|
| 106 |
|
|
@@ -126,7 +156,13 @@ if question:
|
|
| 126 |
st.write("Positive reviews suggest that customers were satisfied with their restaurant experience.")
|
| 127 |
elif "negative" in q:
|
| 128 |
st.write("Negative reviews suggest that customers experienced problems that may affect satisfaction and loyalty.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
elif "improve" in q or "improvement" in q:
|
| 130 |
st.write("Management should focus on recurring negative feedback and investigate the causes behind poor customer experiences.")
|
| 131 |
else:
|
| 132 |
-
st.write("This dashboard helps management understand customer sentiment,
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from pathlib import Path
|
| 4 |
+
from collections import Counter
|
| 5 |
+
import re
|
| 6 |
|
| 7 |
st.set_page_config(page_title="Customer Experience Analyzer", layout="wide")
|
| 8 |
|
|
|
|
| 50 |
else:
|
| 51 |
st.warning("No reviews match the selected filters.")
|
| 52 |
|
| 53 |
+
# Top complaint words
|
| 54 |
+
st.subheader("Top Complaint Words")
|
| 55 |
+
|
| 56 |
+
negative_reviews = filtered_df[filtered_df["sentiment"] == "negative"]["review_text"]
|
| 57 |
+
|
| 58 |
+
if len(negative_reviews) > 0:
|
| 59 |
+
all_text = " ".join(negative_reviews.astype(str)).lower()
|
| 60 |
+
words = re.findall(r"\b[a-z]+\b", all_text)
|
| 61 |
+
|
| 62 |
+
stopwords = {
|
| 63 |
+
"the", "and", "was", "were", "is", "it", "to", "of", "for", "in",
|
| 64 |
+
"a", "an", "this", "that", "with", "on", "at", "my", "our", "we",
|
| 65 |
+
"i", "had", "but", "very", "so", "not", "be", "been", "are", "as",
|
| 66 |
+
"they", "them", "you", "he", "she", "his", "her", "their", "there",
|
| 67 |
+
"here", "have", "has", "from", "too", "all"
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
filtered_words = [word for word in words if word not in stopwords and len(word) > 2]
|
| 71 |
+
|
| 72 |
+
if filtered_words:
|
| 73 |
+
word_counts = Counter(filtered_words).most_common(10)
|
| 74 |
+
word_df = pd.DataFrame(word_counts, columns=["Word", "Count"])
|
| 75 |
+
st.bar_chart(word_df.set_index("Word"))
|
| 76 |
+
else:
|
| 77 |
+
st.info("No meaningful complaint words found.")
|
| 78 |
+
else:
|
| 79 |
+
st.info("No negative reviews available for this selection.")
|
| 80 |
+
|
| 81 |
# Example reviews
|
| 82 |
st.subheader("Example Customer Reviews")
|
| 83 |
|
|
|
|
| 115 |
f"""
|
| 116 |
- Out of **{total_reviews}** filtered reviews, **{positive_rate:.1f}%** are positive and **{negative_rate:.1f}%** are negative.
|
| 117 |
- This helps management quickly assess overall customer satisfaction.
|
| 118 |
+
- Searching by keyword can help identify specific issues in customer feedback.
|
| 119 |
"""
|
| 120 |
)
|
| 121 |
else:
|
|
|
|
| 128 |
if negative_rate > 60:
|
| 129 |
st.warning("Customer dissatisfaction is high. Management should urgently review repeated complaints and investigate operational issues.")
|
| 130 |
elif negative_rate > 40:
|
| 131 |
+
st.info("Customer sentiment is mixed. Management should identify recurring negative themes and improve consistency.")
|
| 132 |
else:
|
| 133 |
+
st.success("Customer sentiment is mostly positive. Management should preserve strengths and continue monitoring feedback.")
|
| 134 |
else:
|
| 135 |
st.write("No recommendation available.")
|
| 136 |
|
|
|
|
| 156 |
st.write("Positive reviews suggest that customers were satisfied with their restaurant experience.")
|
| 157 |
elif "negative" in q:
|
| 158 |
st.write("Negative reviews suggest that customers experienced problems that may affect satisfaction and loyalty.")
|
| 159 |
+
elif "complaint" in q or "complaints" in q:
|
| 160 |
+
if len(negative_reviews) > 0 and filtered_words:
|
| 161 |
+
top_word = word_counts[0][0]
|
| 162 |
+
st.write(f"A common complaint-related word in the selected reviews is **{top_word}**.")
|
| 163 |
+
else:
|
| 164 |
+
st.write("There are no complaint words available in the current selection.")
|
| 165 |
elif "improve" in q or "improvement" in q:
|
| 166 |
st.write("Management should focus on recurring negative feedback and investigate the causes behind poor customer experiences.")
|
| 167 |
else:
|
| 168 |
+
st.write("This dashboard helps management understand customer sentiment, complaint patterns, and possible improvement areas.")
|