customer_experience_analyzer / streamlit_app.py
cchaimin's picture
Rename app.py to streamlit_app.py
a63f459 verified
import streamlit as st
import pandas as pd
st.set_page_config(page_title="Restaurant Review Analyzer", layout="wide")
st.title("Restaurant Review Analyzer")
st.write("Analyze customer sentiment from restaurant reviews.")
# Load cleaned data
df = pd.read_csv("reviews.csv")
# KPIs
total_reviews = len(df)
positive_rate = (df["sentiment"] == "positive").mean() * 100 if total_reviews > 0 else 0
negative_rate = (df["sentiment"] == "negative").mean() * 100 if total_reviews > 0 else 0
col1, col2, col3 = st.columns(3)
col1.metric("Total Reviews", total_reviews)
col2.metric("Positive %", f"{positive_rate:.1f}%")
col3.metric("Negative %", f"{negative_rate:.1f}%")
# Sentiment chart
st.subheader("Sentiment Breakdown")
st.bar_chart(df["sentiment"].value_counts())
# Filter by sentiment
st.sidebar.header("Filters")
selected_sentiment = st.sidebar.multiselect(
"Select sentiment",
options=df["sentiment"].unique(),
default=df["sentiment"].unique()
)
filtered_df = df[df["sentiment"].isin(selected_sentiment)]
# Show filtered reviews
st.subheader("Filtered Reviews")
st.dataframe(filtered_df[["review_text", "sentiment"]])
# Insights
st.subheader("Key Insight")
if len(filtered_df) > 0:
dominant_sentiment = filtered_df["sentiment"].mode().iloc[0]
st.write(f"The dominant sentiment in the selected reviews is **{dominant_sentiment}**.")
else:
st.write("No reviews match the selected filter.")
# Simple assistant box
st.subheader("Ask the Assistant")
question = st.text_input("Ask a question about the reviews")
if question:
if "positive" in question.lower():
st.write("Positive reviews reflect customer satisfaction with the restaurant experience.")
elif "negative" in question.lower():
st.write("Negative reviews suggest dissatisfaction and possible service or food quality issues.")
else:
st.write("This dataset contains restaurant reviews labeled as positive or negative.")