saherPervaiz commited on
Commit
9b9214f
Β·
verified Β·
1 Parent(s): f5c3915

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -15
app.py CHANGED
@@ -22,11 +22,16 @@ def get_personalized_advice(user_data):
22
  st.error(f"Error fetching advice from Groq: {str(e)}")
23
  return None
24
 
25
- # Function for chatbot interaction
26
  def chatbot_interface():
 
27
  st.title("πŸŽ“ Student Well-being Chatbot")
28
- st.write("Hello! I’m here to assist you with well-being advice based on your responses.")
29
-
 
 
 
 
30
  # Initialize session state
31
  if 'step' not in st.session_state:
32
  st.session_state.step = 0
@@ -41,40 +46,41 @@ def chatbot_interface():
41
 
42
  # Step 0: Welcome message and initial question
43
  if st.session_state.step == 0:
44
- st.write("Bot: Hi there! I'm here to help with your well-being. Let's start! 😊")
45
- next_step_button = st.button("Start Chat")
 
46
  if next_step_button:
47
  next_step()
48
 
49
  # Step 1: Ask for anxiety level with slider
50
  elif st.session_state.step == 1:
51
  st.write("Bot: On a scale of 1 to 10, how would you rate your anxiety level?")
52
- anxiety_level = st.slider("Your Anxiety Level:", min_value=1, max_value=10, value=5)
53
  st.session_state.user_data['anxiety_level'] = anxiety_level
54
  next_step()
55
 
56
  # Step 2: Ask for self-esteem with slider
57
  elif st.session_state.step == 2:
58
  st.write("Bot: On a scale of 1 to 10, how would you rate your self-esteem?")
59
- self_esteem = st.slider("Your Self-Esteem Level:", min_value=1, max_value=10, value=5)
60
  st.session_state.user_data['self_esteem'] = self_esteem
61
  next_step()
62
 
63
  # Step 3: Ask for mental health history
64
  elif st.session_state.step == 3:
65
  st.write("Bot: How would you describe your mental health history?")
66
- mental_health_history = st.multiselect(
67
  "Select your mental health history:",
68
- ["None", "Minor Issues", "Moderate Issues", "Severe Issues"]
 
69
  )
70
- if mental_health_history:
71
- st.session_state.user_data['mental_health_history'] = ", ".join(mental_health_history)
72
- next_step()
73
 
74
  # Step 4: Ask for stress level with slider
75
  elif st.session_state.step == 4:
76
  st.write("Bot: On a scale of 0 to 2, how would you rate your stress level?")
77
- stress_level = st.slider("Your Stress Level:", min_value=0, max_value=2, value=1)
78
  st.session_state.user_data['stress_level'] = stress_level
79
  next_step()
80
 
@@ -82,7 +88,7 @@ def chatbot_interface():
82
  elif st.session_state.step == 5:
83
  st.write("Bot: Thank you for providing the information! Here’s your personalized advice:")
84
  user_data = st.session_state.user_data
85
- st.write(f"Your data: {user_data}")
86
 
87
  # Fetch personalized advice from Groq
88
  st.subheader("πŸ”” Here's Your Personalized Well-being Advice:")
@@ -93,7 +99,8 @@ def chatbot_interface():
93
  st.write("I couldn't retrieve specific advice right now, but please check back later.")
94
 
95
  # Option to restart the chat
96
- restart_button = st.button("Start Over")
 
97
  if restart_button:
98
  st.session_state.step = 0
99
  st.session_state.user_data = {}
 
22
  st.error(f"Error fetching advice from Groq: {str(e)}")
23
  return None
24
 
25
+ # Function for chatbot interaction with professional styling
26
  def chatbot_interface():
27
+ st.set_page_config(page_title="πŸŽ“ Student Well-being Chatbot", layout="centered")
28
  st.title("πŸŽ“ Student Well-being Chatbot")
29
+ st.write("Welcome! I'm here to help you with well-being advice tailored to your current state.")
30
+
31
+ # Styling the sidebar for improved UX
32
+ st.sidebar.title("Student Well-being")
33
+ st.sidebar.write("The well-being questionnaire will guide you through assessing your mental health and providing personalized advice.")
34
+
35
  # Initialize session state
36
  if 'step' not in st.session_state:
37
  st.session_state.step = 0
 
46
 
47
  # Step 0: Welcome message and initial question
48
  if st.session_state.step == 0:
49
+ st.write("Bot: Hi there! I'm here to assist you with your well-being. Let's get started! 😊")
50
+ st.markdown("<hr>", unsafe_allow_html=True)
51
+ next_step_button = st.button("Start Chat", key="start_button", help="Click to start the well-being questionnaire.")
52
  if next_step_button:
53
  next_step()
54
 
55
  # Step 1: Ask for anxiety level with slider
56
  elif st.session_state.step == 1:
57
  st.write("Bot: On a scale of 1 to 10, how would you rate your anxiety level?")
58
+ anxiety_level = st.slider("Your Anxiety Level:", min_value=1, max_value=10, value=5, step=1, help="Rate your anxiety from 1 (low) to 10 (high).")
59
  st.session_state.user_data['anxiety_level'] = anxiety_level
60
  next_step()
61
 
62
  # Step 2: Ask for self-esteem with slider
63
  elif st.session_state.step == 2:
64
  st.write("Bot: On a scale of 1 to 10, how would you rate your self-esteem?")
65
+ self_esteem = st.slider("Your Self-Esteem Level:", min_value=1, max_value=10, value=5, step=1, help="Rate your self-esteem from 1 (low) to 10 (high).")
66
  st.session_state.user_data['self_esteem'] = self_esteem
67
  next_step()
68
 
69
  # Step 3: Ask for mental health history
70
  elif st.session_state.step == 3:
71
  st.write("Bot: How would you describe your mental health history?")
72
+ mental_health_history = st.selectbox(
73
  "Select your mental health history:",
74
+ ["None", "Minor Issues", "Moderate Issues", "Severe Issues"],
75
+ help="Choose an option that best describes your mental health background."
76
  )
77
+ st.session_state.user_data['mental_health_history'] = mental_health_history
78
+ next_step()
 
79
 
80
  # Step 4: Ask for stress level with slider
81
  elif st.session_state.step == 4:
82
  st.write("Bot: On a scale of 0 to 2, how would you rate your stress level?")
83
+ stress_level = st.slider("Your Stress Level:", min_value=0, max_value=2, value=1, step=1, help="Rate your stress from 0 (low) to 2 (high).")
84
  st.session_state.user_data['stress_level'] = stress_level
85
  next_step()
86
 
 
88
  elif st.session_state.step == 5:
89
  st.write("Bot: Thank you for providing the information! Here’s your personalized advice:")
90
  user_data = st.session_state.user_data
91
+ st.write(f"Your Data: {user_data}")
92
 
93
  # Fetch personalized advice from Groq
94
  st.subheader("πŸ”” Here's Your Personalized Well-being Advice:")
 
99
  st.write("I couldn't retrieve specific advice right now, but please check back later.")
100
 
101
  # Option to restart the chat
102
+ st.markdown("<hr>", unsafe_allow_html=True)
103
+ restart_button = st.button("Start Over", key="restart_button", help="Click to restart the questionnaire.")
104
  if restart_button:
105
  st.session_state.step = 0
106
  st.session_state.user_data = {}