File size: 5,746 Bytes
af13f6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
104
105
106
107
108
109
110
111
112
113
114
# app.py
import streamlit as st

# --- Dữ liệu Demo (Chuẩn bị sẵn) ---
# Dữ liệu này được lấy sẵn để demo nhanh và ổn định.
DEMO_DATA = {
    "Ví dụ 1: Dấu hiệu trầm cảm rõ ràng": {
        "post": "Lately, I just feel so empty and numb inside. Nothing brings me joy anymore, not even the things I used to love. It's a struggle just to get out of bed.",
        "mentallama_output": {
            "answer": "Depression",
            "reasoning": "The post conveys a deep sense of emotional numbness, loss of interest (anhedonia), and lack of motivation, which are core symptoms of depression."
        },
        "mentalroberta_output": "Depression"
    },
    "Ví dụ 2: Dấu hiệu stress tinh tế": {
        "post": "Another sleepless night. My mind just won't shut off. I feel so tired but I can't rest. Work is piling up and I just don't have the energy to face it.",
        "mentallama_output": {
            "answer": "Stress",
            "reasoning": "The user mentions sleepless nights, a racing mind, and feeling overwhelmed by work. These are classic indicators of high stress levels."
        },
        "mentalroberta_output": "Stress"
    },
    "Ví dụ 3: Bài đăng tích cực, không có vấn đề": {
        "post": "Just finished a great hike with friends! The view from the top was incredible. Feeling so refreshed and happy.",
        "mentallama_output": {
            "answer": "None",
            "reasoning": "The post expresses positive emotions, mentions social activity (hiking with friends), and feelings of refreshment. There are no indicators of mental distress."
        },
        "mentalroberta_output": "None"
    },
    "Ví dụ 4: Tự tử (Nghiêm trọng)": {
        "post": "I can't take this pain anymore. I've been thinking about ending it all. It feels like the only way out.",
        "mentallama_output": {
            "answer": "Suicide",
            "reasoning": "The post contains explicit suicidal ideation ('thinking about ending it all') and expresses feelings of unbearable pain and hopelessness, indicating a high-risk situation."
        },
        "mentalroberta_output": "Suicide"
    }
}

# --- Giao diện ứng dụng Streamlit ---
st.set_page_config(layout="wide", page_title="MentaLLaMA Demo")

# Header
st.title("🔬 Demo: MentaLLaMA - Phân Tích Sức Khỏe Tâm Thần Có Thể Giải Thích")
st.markdown("""
Chào mừng đến với bản demo của **MentaLLaMA**!

Demo này minh họa sự khác biệt cốt lõi giữa:
1.  **Phương pháp truyền thống "Hộp đen"** (như MentalRoBERTa): Chỉ đưa ra dự đoán.
2.  **MentaLLaMA**: Đưa ra cả dự đoán và **lời giải thích chi tiết**.

*Lưu ý: Demo này sử dụng kết quả được tạo sẵn để đảm bảo tốc độ và sự ổn định.*
""")

# --- Phần tương tác ---
st.sidebar.header("Bảng điều khiển")
option = st.sidebar.selectbox(
    'Chọn một bài đăng mẫu để phân tích:',
    list(DEMO_DATA.keys()),
    index=0
)

# Hiển thị bài đăng được chọn
selected_example = DEMO_DATA[option]
post_text = selected_example["post"]

st.subheader("📝 Nội dung bài đăng được chọn:")
st.info(post_text)

# Nút phân tích
if st.sidebar.button('Chạy Phân Tích So Sánh', type="primary"):
    st.header("📊 Kết quả phân tích so sánh")
    
    col1, col2 = st.columns(2, gap="large")

    # Cột 1: Phương pháp truyền thống (Hộp đen)
    with col1:
        st.subheader("Mô hình 'Hộp đen' (ví dụ: MentalRoBERTa)")
        
        st.metric(label="Dự đoán", value=selected_example['mentalroberta_output'])
        
        with st.expander("Phân tích về phương pháp này", expanded=True):
            st.warning("⚠️ **Không có lời giải thích!**")
            st.write("""
            Mô hình chỉ đưa ra kết quả cuối cùng. Chúng ta không biết **tại sao** nó lại đưa ra dự đoán này. 
            - **Khó tin tưởng:** Làm sao để chắc chắn nó không mắc sai lầm?
            - **Khó xác thực:** Bác sĩ không có cơ sở để kiểm tra lại logic của AI.
            - **Rủi ro cao:** Trong lĩnh vực y tế, một quyết định không thể giải thích là rất nguy hiểm.
            """)

    # Cột 2: MentaLLaMA (Giải thích được)
    with col2:
        st.subheader("MentaLLaMA (Mô hình giải thích được)")
        
        st.metric(label="Dự đoán", value=selected_example['mentallama_output']['answer'])
        
        st.write("**Lý do giải thích (Reasoning):**")
        st.success(f"“{selected_example['mentallama_output']['reasoning']}”")
        
        with st.expander("Phân tích về phương pháp này", expanded=True):
            st.info("💡 **Cung cấp lý do chi tiết!**")
            st.write("""
            MentaLLaMA không chỉ dự đoán mà còn chỉ ra các **bằng chứng cụ thể** trong văn bản.
            - **Tăng sự tin tưởng:** Lời giải thích hợp lý giúp chúng ta tin vào kết quả.
            - **Hỗ trợ chuyên gia:** Bác sĩ có thể nhanh chóng xác thực logic và đưa ra quyết định cuối cùng.
            - **An toàn hơn:** Sự minh bạch giúp giảm thiểu rủi ro và tăng tính trách nhiệm.
            """)
else:
    st.info("Hãy chọn một ví dụ và nhấn nút 'Chạy Phân Tích So Sánh' ở thanh bên trái.")

# Footer
st.markdown("---")
st.markdown("Demo được xây dựng dựa trên bài báo: *MentaLLaMA: Interpretable Mental Health Analysis on Social Media with Large Language Models*.")