File size: 5,450 Bytes
9940e7a
4e9ccb5
 
 
 
 
 
 
 
 
 
633f188
4e9ccb5
633f188
4e9ccb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
633f188
4e9ccb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9940e7a
4e9ccb5
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import streamlit as st
import pandas as pd
import plotly.express as px
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import os

# ---------- CONFIG ----------
st.set_page_config(page_title="CheckPD Sentiment Dashboard", layout="wide")
st.title("ภาพรวมความรู้สึกของผู้ใช้ CheckPD (Real-time)")

# ---------- LOAD DATA ----------
@st.cache_data
def load_data():
    file_path = "src/Senti_real/Sentiment/checkpd_sentiment.csv"  # ✅ แก้ path ตรงนี้
    df = pd.read_csv(file_path)
    return df

if st.button("รีเฟรชข้อมูล"):
    st.cache_data.clear()
    st.rerun()

# โหลดข้อมูลและตัวกรองจังหวัด
df = load_data()
locations = df['service_location'].dropna().unique().tolist()
locations.insert(0, "ดูทั้งหมด")
selected_location = st.selectbox("เลือกจังหวัด/สถานที่บริการ", options=locations)

if selected_location == "ดูทั้งหมด":
    df_filtered = df.copy()
else:
    df_filtered = df[df['service_location'] == selected_location]

# ---------- SIDEBAR MENU ----------
menu = st.sidebar.radio("เลือกหน้าที่จะแสดง", ["Dashboard สรุป", "Bar Chart เปรียบเทียบความรู้สึก"])

# ---------- กำหนดสี ----------
sentiment_colors = {'pos': 'skyblue', 'neg': 'red'}

if menu == "Dashboard สรุป":
    st.subheader("1. สัดส่วนความรู้สึก (แยกตามประเภท)")
    text_columns = {
        'user_feeling_first_use': 'คุณรู้สึกอย่างไรเมื่อใช้งานแอปพลิเคชัน CheckPD ครั้งแรก?',
        'staff_emotion_feedback': 'บริการของเจ้าหน้าที่ทำให้คุณรู้สึกอย่างไร?',
        'improvement_suggestions': 'สิ่งใดในแอปพลิเคชันหรืองานบริการที่คุณคิดว่าควรปรับปรุง?'
    }

    for col, label in text_columns.items():
        chart_col = col + '_sentiment'
        df_chart = df_filtered[df_filtered[chart_col].isin(['pos', 'neg'])]
        st.markdown(f"#### ➤ {label}")
        fig = px.pie(df_chart, names=chart_col, title=f"สัดส่วนความรู้สึก - {label}", hole=0.4,
                     color=chart_col, color_discrete_map=sentiment_colors)
        fig.update_traces(textfont_size=20)
        st.plotly_chart(fig, use_container_width=True)

    st.subheader("2. สัดส่วนภาพรวมทุกประเภท")
    combined_counts = pd.concat([
        df_filtered['user_feeling_first_use_sentiment'],
        df_filtered['staff_emotion_feedback_sentiment'],
        df_filtered['improvement_suggestions_sentiment']
    ])
    combined_counts = combined_counts[combined_counts.isin(['pos', 'neg'])]
    combined_counts = combined_counts.value_counts().reset_index()
    combined_counts.columns = ['sentiment', 'count']
    fig_total = px.pie(combined_counts, names='sentiment', values='count',
                       title="สัดส่วนความรู้สึกโดยรวมจากทุกหมวด", hole=0.4,
                       color='sentiment', color_discrete_map=sentiment_colors)
    fig_total.update_traces(textfont_size=20)
    st.plotly_chart(fig_total, use_container_width=True)

    st.subheader("3. ข้อความที่ให้ความคิดเห็น (ตามตัวกรอง)")
    cols_to_show = [
        'service_location',
        'user_feeling_first_use',
        'staff_emotion_feedback',
        'improvement_suggestions'
    ]
    st.dataframe(df_filtered[cols_to_show], use_container_width=True)

elif menu == "Bar Chart เปรียบเทียบความรู้สึก":
    st.subheader("เปรียบเทียบความรู้สึกในแต่ละหมวดด้วย Bar Chart")
    text_columns = {
        'user_feeling_first_use_sentiment': 'รู้สึกเมื่อใช้งานครั้งแรก',
        'staff_emotion_feedback_sentiment': 'รู้สึกต่อเจ้าหน้าที่',
        'improvement_suggestions_sentiment': 'ข้อเสนอแนะต่อแอป/บริการ'
    }

    for col, label in text_columns.items():
        st.markdown(f"#### ➤ {label}")
        df_chart = df_filtered[df_filtered[col].isin(['pos', 'neg'])]
        counts = df_chart[col].value_counts().reset_index()
        counts.columns = ['sentiment', 'count']
        fig = px.bar(counts, x='sentiment', y='count',
                     labels={'sentiment': 'ความรู้สึก', 'count': 'จำนวน'},
                     title=f"Bar Chart - {label}",
                     color='sentiment', color_discrete_map=sentiment_colors)
        fig.update_layout(font=dict(size=18))
        st.plotly_chart(fig, use_container_width=True)

# ---------- SIDEBAR INFO ----------
st.sidebar.title("Model & Pipeline")
st.sidebar.info("กำลังใช้โมเดล: phoner45/wangchan-sentiment-thai-text-model")