cchaimin commited on
Commit
8b61600
·
verified ·
1 Parent(s): a63f459

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +66 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,68 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  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
+ DATA_PATH = Path(__file__).resolve().parent.parent / "reviews.csv"
14
+ df = pd.read_csv(DATA_PATH)
15
+
16
+ # KPIs
17
+ total_reviews = len(df)
18
+ positive_rate = (df["sentiment"] == "positive").mean() * 100 if total_reviews > 0 else 0
19
+ negative_rate = (df["sentiment"] == "negative").mean() * 100 if total_reviews > 0 else 0
20
+
21
+ col1, col2, col3 = st.columns(3)
22
+ col1.metric("Total Reviews", total_reviews)
23
+ col2.metric("Positive %", f"{positive_rate:.1f}%")
24
+ col3.metric("Negative %", f"{negative_rate:.1f}%")
25
+
26
+ # Sentiment chart
27
+ st.subheader("Sentiment Breakdown")
28
+ st.bar_chart(df["sentiment"].value_counts())
29
+
30
+ # Sidebar filters
31
+ st.sidebar.header("Filters")
32
+ selected_sentiment = st.sidebar.multiselect(
33
+ "Select sentiment",
34
+ options=df["sentiment"].unique(),
35
+ default=df["sentiment"].unique()
36
+ )
37
+
38
+ filtered_df = df[df["sentiment"].isin(selected_sentiment)]
39
+
40
+ # Show reviews
41
+ st.subheader("Filtered Reviews")
42
+ st.dataframe(filtered_df[["review_text", "sentiment"]])
43
+
44
+ # Insights
45
+ st.subheader("Key Insights")
46
+
47
+ negative_df = filtered_df[filtered_df["sentiment"] == "negative"]
48
+
49
+ if len(negative_df) > 0:
50
+ top_issue = negative_df["review_text"].iloc[0]
51
+ st.write("Example negative review:")
52
+ st.warning(top_issue)
53
+ st.info("Recommendation: Investigate common complaints and improve service quality.")
54
+ else:
55
+ st.write("No major negative issues found.")
56
+
57
+ # Assistant
58
+ st.subheader("Ask the Assistant")
59
+
60
+ question = st.text_input("Ask a question about the reviews")
61
 
62
+ if question:
63
+ if "positive" in question.lower():
64
+ st.write("Positive reviews indicate customer satisfaction.")
65
+ elif "negative" in question.lower():
66
+ st.write("Negative reviews indicate dissatisfaction and areas for improvement.")
67
+ else:
68
+ st.write("This dataset contains restaurant reviews labeled as positive or negative.")