File size: 1,943 Bytes
8c3d7c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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.")