File size: 5,229 Bytes
8e315dc
c4587cb
8e315dc
c4587cb
e3e8ff9
c4587cb
 
 
8e315dc
7877a46
c4587cb
7877a46
9b3b3ee
 
 
 
 
 
 
ede3059
9b3b3ee
 
c4587cb
 
 
 
 
 
 
 
 
8e315dc
34a373d
 
 
 
 
 
 
 
 
ede3059
b30668d
ede3059
 
 
c718b76
 
 
 
 
 
 
 
 
 
 
 
b3cc614
 
 
 
 
c718b76
 
ede3059
 
 
 
c718b76
 
b3cc614
 
c718b76
fc86e36
c718b76
ede3059
 
fc86e36
 
 
f5c3915
fc86e36
c718b76
ede3059
 
fc86e36
 
 
c718b76
 
 
 
9b9214f
ede3059
fc86e36
c718b76
9b9214f
 
c718b76
fc86e36
c718b76
ede3059
 
fc86e36
c718b76
 
 
 
ede3059
c718b76
ede3059
c718b76
ede3059
 
c718b76
 
fc86e36
c718b76
ede3059
b30668d
c718b76
fc86e36
ede3059
b30668d
b3cc614
 
 
b30668d
 
8e315dc
b30668d
9e67cb5
8e315dc
 
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import streamlit as st
from groq import Groq

# Groq API Key (replace with your actual API key)
groq_api_key = "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"

# Initialize Groq client
client = Groq(api_key=groq_api_key)

# Function to fetch personalized advice using Groq API
def get_personalized_advice(user_data):
    """Fetch personalized advice using the Groq API based on user data."""
    query = f"""
    Based on the following user's responses:
    - Anxiety level: {user_data['anxiety_level']}
    - Self-esteem: {user_data['self_esteem']}
    - Mental health history: {user_data['mental_health_history']}
    - Stress level: {user_data['stress_level']}

    Please provide professional, personalized mental health advice tailored to these responses.
    """

    try:
        response = client.chat.completions.create(
            messages=[{"role": "user", "content": query}],
            model="llama-3.3-70b-versatile",
        )
        return response.choices[0].message.content
    except Exception as e:
        st.error(f"Error fetching advice from Groq: {str(e)}")
        return None

def stress_level_to_string(stress_level):
    """Convert numerical stress level (0, 1, 2) to a string representation."""
    if stress_level == 0:
        return "Low"
    elif stress_level == 1:
        return "Moderate"
    else:
        return "High"

# Chatbot interface for professional user experience
def chatbot_interface():
    st.title("πŸŽ“ Professional Student Well-being Chatbot")
    st.write("Welcome to the Student Well-being Chatbot. I’m here to assist you in improving your mental well-being based on your responses. Please answer the following questions.")

    # Initialize session state
    if 'step' not in st.session_state:
        st.session_state.step = 0
        st.session_state.user_data = {}

    def next_step():
        st.session_state.step += 1

    def show_input_error(message="Please provide a valid input."):
        st.error(message)
        return False

    def clear_data():
        """Clear session data and reset to initial step."""
        st.session_state.step = 0
        st.session_state.user_data = {}

    # Step 0: Welcome message and initial question
    if st.session_state.step == 0:
        st.write("Bot: Thank you for choosing to take this well-being assessment. We will gather some insights to provide personalized advice.")
        st.write("Bot: Please answer the following questions as accurately as possible.")
        next_step_button = st.button("Start Assessment")
        clear_button = st.button("Clear All")
        if next_step_button:
            next_step()
        if clear_button:
            clear_data()

    # Step 1: Ask for anxiety level
    elif st.session_state.step == 1:
        st.write("Bot: On a scale from 1 to 10, how would you rate your current anxiety level?")
        anxiety_level = st.slider("Anxiety Level", 1, 10, 5)
        if anxiety_level:
            st.session_state.user_data['anxiety_level'] = anxiety_level
            next_step()

    # Step 2: Ask for self-esteem
    elif st.session_state.step == 2:
        st.write("Bot: On a scale from 1 to 10, how would you rate your current self-esteem?")
        self_esteem = st.slider("Self-esteem Level", 1, 10, 5)
        if self_esteem:
            st.session_state.user_data['self_esteem'] = self_esteem
            next_step()

    # Step 3: Ask for mental health history
    elif st.session_state.step == 3:
        st.write("Bot: How would you describe your mental health history?")
        mental_health_history = st.selectbox(
            "Please select the option that best represents your mental health history:",
            ["None", "Minor Issues", "Moderate Issues", "Severe Issues"]
        )
        st.session_state.user_data['mental_health_history'] = mental_health_history
        next_step()

    # Step 4: Ask for stress level
    elif st.session_state.step == 4:
        st.write("Bot: On a scale from 0 to 2, how would you rate your current stress level?")
        stress_level = st.radio("Stress Level (0 = Low, 1 = Moderate, 2 = High)", [0, 1, 2])
        st.session_state.user_data['stress_level'] = stress_level
        next_step()

    # Step 5: Show advice based on user input
    elif st.session_state.step == 5:
        st.write("Bot: Thank you for providing the information.")
        user_data = st.session_state.user_data
        st.write(f"Bot: Based on your inputs, here is a summary of your responses: {user_data}")

        # Show professional, personalized advice
        st.subheader("πŸ”” Professional Well-being Advice:")
        advice = get_personalized_advice(user_data)
        if advice:
            st.write(f"Bot: {advice}")
        else:
            st.write("Bot: Unfortunately, I couldn't retrieve specific advice at this moment, but feel free to try again later.")

        # Option to restart the chat
        restart_button = st.button("Start Over")
        clear_button = st.button("Clear All")
        if restart_button:
            clear_data()
        if clear_button:
            clear_data()

# Main function to run the chatbot
def main():
    chatbot_interface()

if __name__ == "__main__":
    main()