cchaimin commited on
Commit
df8b0dc
·
verified ·
1 Parent(s): 0433e01

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +15 -17
src/streamlit_app.py CHANGED
@@ -2,15 +2,14 @@ import streamlit as st
2
  import pandas as pd
3
  from pathlib import Path
4
 
5
- # Page config
6
  st.set_page_config(page_title="Customer Experience Analyzer", layout="wide")
7
 
8
- # Title
9
  st.title("Customer Experience Analyzer")
10
  st.write("Analyze customer sentiment from restaurant reviews.")
11
 
12
- # Load data (IMPORTANT: correct path for Hugging Face)
13
- df = pd.read_csv("reviews.csv")
 
14
 
15
  # KPIs
16
  total_reviews = len(df)
@@ -22,11 +21,11 @@ col1.metric("Total Reviews", total_reviews)
22
  col2.metric("Positive %", f"{positive_rate:.1f}%")
23
  col3.metric("Negative %", f"{negative_rate:.1f}%")
24
 
25
- # Sentiment chart
26
  st.subheader("Sentiment Breakdown")
27
  st.bar_chart(df["sentiment"].value_counts())
28
 
29
- # Sidebar filters
30
  st.sidebar.header("Filters")
31
  selected_sentiment = st.sidebar.multiselect(
32
  "Select sentiment",
@@ -36,32 +35,31 @@ selected_sentiment = st.sidebar.multiselect(
36
 
37
  filtered_df = df[df["sentiment"].isin(selected_sentiment)]
38
 
39
- # Show reviews
40
  st.subheader("Filtered Reviews")
41
  st.dataframe(filtered_df[["review_text", "sentiment"]])
42
 
43
- # Insights
44
  st.subheader("Key Insights")
45
-
46
  negative_df = filtered_df[filtered_df["sentiment"] == "negative"]
47
 
48
  if len(negative_df) > 0:
49
- top_issue = negative_df["review_text"].iloc[0]
50
  st.write("Example negative review:")
51
- st.warning(top_issue)
52
- st.info("Recommendation: Investigate common complaints and improve service quality.")
53
  else:
54
- st.write("No major negative issues found.")
55
 
56
- # Assistant
57
  st.subheader("Ask the Assistant")
58
-
59
  question = st.text_input("Ask a question about the reviews")
60
 
61
  if question:
62
- if "positive" in question.lower():
 
63
  st.write("Positive reviews indicate customer satisfaction.")
64
- elif "negative" in question.lower():
65
  st.write("Negative reviews indicate dissatisfaction and areas for improvement.")
66
  else:
67
  st.write("This dataset contains restaurant reviews labeled as positive or negative.")
 
2
  import pandas as pd
3
  from pathlib import Path
4
 
 
5
  st.set_page_config(page_title="Customer Experience Analyzer", layout="wide")
6
 
 
7
  st.title("Customer Experience Analyzer")
8
  st.write("Analyze customer sentiment from restaurant reviews.")
9
 
10
+ # Load the CSV from the same folder as this file
11
+ DATA_PATH = Path(__file__).parent / "reviews.csv"
12
+ df = pd.read_csv(DATA_PATH)
13
 
14
  # KPIs
15
  total_reviews = len(df)
 
21
  col2.metric("Positive %", f"{positive_rate:.1f}%")
22
  col3.metric("Negative %", f"{negative_rate:.1f}%")
23
 
24
+ # Chart
25
  st.subheader("Sentiment Breakdown")
26
  st.bar_chart(df["sentiment"].value_counts())
27
 
28
+ # Sidebar filter
29
  st.sidebar.header("Filters")
30
  selected_sentiment = st.sidebar.multiselect(
31
  "Select sentiment",
 
35
 
36
  filtered_df = df[df["sentiment"].isin(selected_sentiment)]
37
 
38
+ # Reviews
39
  st.subheader("Filtered Reviews")
40
  st.dataframe(filtered_df[["review_text", "sentiment"]])
41
 
42
+ # Insight
43
  st.subheader("Key Insights")
 
44
  negative_df = filtered_df[filtered_df["sentiment"] == "negative"]
45
 
46
  if len(negative_df) > 0:
47
+ example_negative = negative_df["review_text"].iloc[0]
48
  st.write("Example negative review:")
49
+ st.warning(example_negative)
50
+ st.info("Recommendation: investigate common complaints and improve service quality.")
51
  else:
52
+ st.write("No major negative issues found in the current selection.")
53
 
54
+ # Simple assistant
55
  st.subheader("Ask the Assistant")
 
56
  question = st.text_input("Ask a question about the reviews")
57
 
58
  if question:
59
+ q = question.lower()
60
+ if "positive" in q:
61
  st.write("Positive reviews indicate customer satisfaction.")
62
+ elif "negative" in q:
63
  st.write("Negative reviews indicate dissatisfaction and areas for improvement.")
64
  else:
65
  st.write("This dataset contains restaurant reviews labeled as positive or negative.")