Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import os
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
from groq import Groq
|
|
@@ -9,13 +8,9 @@ groq_api_key = "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"
|
|
| 9 |
# Initialize Groq client
|
| 10 |
client = Groq(api_key=groq_api_key)
|
| 11 |
|
| 12 |
-
|
| 13 |
-
def load_data(file):
|
| 14 |
-
return pd.read_csv(file)
|
| 15 |
-
|
| 16 |
def get_personalized_advice(user_data):
|
| 17 |
"""Fetch personalized advice using the Groq API based on user data"""
|
| 18 |
-
# Construct the query for the Groq API
|
| 19 |
query = f"Based on the user's data: 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']}, provide personalized mental health advice."
|
| 20 |
|
| 21 |
try:
|
|
@@ -37,92 +32,73 @@ def stress_level_to_string(stress_level):
|
|
| 37 |
else:
|
| 38 |
return "High"
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
def main():
|
| 41 |
-
|
| 42 |
-
page_title="Student Well-being Advisor",
|
| 43 |
-
page_icon="π",
|
| 44 |
-
layout="wide",
|
| 45 |
-
initial_sidebar_state="expanded",
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
st.sidebar.title("Navigation")
|
| 49 |
-
st.sidebar.write("Use the sidebar to navigate through the app.")
|
| 50 |
-
st.sidebar.markdown("### π Upload Data")
|
| 51 |
-
st.sidebar.write("Start by uploading your dataset for analysis.")
|
| 52 |
-
st.sidebar.markdown("### π Analysis & Advice")
|
| 53 |
-
st.sidebar.write("Get detailed insights and personalized advice.")
|
| 54 |
-
|
| 55 |
-
st.title("π Student Well-being Advisor")
|
| 56 |
-
st.subheader("Analyze data and provide professional mental health recommendations.")
|
| 57 |
-
st.write("""
|
| 58 |
-
This app helps identify areas of concern in students' well-being and provides personalized advice based on their responses.
|
| 59 |
-
""")
|
| 60 |
-
|
| 61 |
-
# Dynamic Data Input
|
| 62 |
-
st.markdown("## π Enter Your Data")
|
| 63 |
-
st.write("Please fill out the form below to receive personalized well-being advice.")
|
| 64 |
-
|
| 65 |
-
# Alternative form inputs for user data
|
| 66 |
-
anxiety_level = st.text_input("Anxiety Level (1 to 10)", "5")
|
| 67 |
-
self_esteem = st.text_input("Self-esteem (1 to 10)", "5")
|
| 68 |
-
mental_health_history = st.selectbox("Mental Health History", ["None", "Minor Issues", "Moderate Issues", "Severe Issues"])
|
| 69 |
-
depression = st.text_input("Depression Level (1 to 10)", "5")
|
| 70 |
-
headache = st.text_input("Headache Level (1 to 10)", "5")
|
| 71 |
-
blood_pressure = st.text_input("Blood Pressure (1 to 10)", "5")
|
| 72 |
-
sleep_quality = st.text_input("Sleep Quality (1 to 10)", "5")
|
| 73 |
-
breathing_problem = st.selectbox("Breathing Problem", ["None", "Mild", "Severe"])
|
| 74 |
-
noise_level = st.text_input("Noise Level (1 to 10)", "5")
|
| 75 |
-
living_conditions = st.text_input("Living Conditions (1 to 10)", "5")
|
| 76 |
-
safety = st.text_input("Safety (1 to 10)", "5")
|
| 77 |
-
basic_needs = st.text_input("Basic Needs Satisfaction (1 to 10)", "5")
|
| 78 |
-
academic_performance = st.text_input("Academic Performance (1 to 10)", "5")
|
| 79 |
-
study_load = st.text_input("Study Load (1 to 10)", "5")
|
| 80 |
-
teacher_student_relationship = st.text_input("Teacher-Student Relationship (1 to 10)", "5")
|
| 81 |
-
future_career_concerns = st.text_input("Future Career Concerns (1 to 10)", "5")
|
| 82 |
-
social_support = st.text_input("Social Support (1 to 10)", "5")
|
| 83 |
-
peer_pressure = st.text_input("Peer Pressure (1 to 10)", "5")
|
| 84 |
-
extracurricular_activities = st.text_input("Extracurricular Activities (1 to 10)", "5")
|
| 85 |
-
bullying = st.text_input("Bullying Level (1 to 10)", "5")
|
| 86 |
-
stress_level = st.radio("Stress Level", [0, 1, 2], index=1)
|
| 87 |
-
|
| 88 |
-
# Convert text inputs to integers
|
| 89 |
-
try:
|
| 90 |
-
user_data = {
|
| 91 |
-
"anxiety_level": int(anxiety_level),
|
| 92 |
-
"self_esteem": int(self_esteem),
|
| 93 |
-
"mental_health_history": mental_health_history,
|
| 94 |
-
"depression": int(depression),
|
| 95 |
-
"headache": int(headache),
|
| 96 |
-
"blood_pressure": int(blood_pressure),
|
| 97 |
-
"sleep_quality": int(sleep_quality),
|
| 98 |
-
"breathing_problem": breathing_problem,
|
| 99 |
-
"noise_level": int(noise_level),
|
| 100 |
-
"living_conditions": int(living_conditions),
|
| 101 |
-
"safety": int(safety),
|
| 102 |
-
"basic_needs": int(basic_needs),
|
| 103 |
-
"academic_performance": int(academic_performance),
|
| 104 |
-
"study_load": int(study_load),
|
| 105 |
-
"teacher_student_relationship": int(teacher_student_relationship),
|
| 106 |
-
"future_career_concerns": int(future_career_concerns),
|
| 107 |
-
"social_support": int(social_support),
|
| 108 |
-
"peer_pressure": int(peer_pressure),
|
| 109 |
-
"extracurricular_activities": int(extracurricular_activities),
|
| 110 |
-
"bullying": int(bullying),
|
| 111 |
-
"stress_level": stress_level
|
| 112 |
-
}
|
| 113 |
-
except ValueError:
|
| 114 |
-
st.error("Please enter valid numeric values.")
|
| 115 |
-
return
|
| 116 |
-
|
| 117 |
-
st.write(f"### Selected User Data: {user_data}")
|
| 118 |
-
|
| 119 |
-
# Provide personalized advice
|
| 120 |
-
st.subheader("π Health Advice Based on Your Input")
|
| 121 |
-
advice = get_personalized_advice(user_data)
|
| 122 |
-
if advice:
|
| 123 |
-
st.write(advice)
|
| 124 |
-
else:
|
| 125 |
-
st.warning("No advice available at the moment.")
|
| 126 |
|
| 127 |
if __name__ == "__main__":
|
| 128 |
main()
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
from groq import Groq
|
|
|
|
| 8 |
# Initialize Groq client
|
| 9 |
client = Groq(api_key=groq_api_key)
|
| 10 |
|
| 11 |
+
# Define a function to fetch personalized advice using Groq API
|
|
|
|
|
|
|
|
|
|
| 12 |
def get_personalized_advice(user_data):
|
| 13 |
"""Fetch personalized advice using the Groq API based on user data"""
|
|
|
|
| 14 |
query = f"Based on the user's data: 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']}, provide personalized mental health advice."
|
| 15 |
|
| 16 |
try:
|
|
|
|
| 32 |
else:
|
| 33 |
return "High"
|
| 34 |
|
| 35 |
+
def chatbot_interface():
|
| 36 |
+
st.title("π Student Well-being Chatbot")
|
| 37 |
+
st.write("I can help you with personalized well-being advice based on your responses. Let's get started!")
|
| 38 |
+
|
| 39 |
+
# Initializing session state
|
| 40 |
+
if 'step' not in st.session_state:
|
| 41 |
+
st.session_state.step = 0
|
| 42 |
+
st.session_state.user_data = {}
|
| 43 |
+
|
| 44 |
+
def next_step():
|
| 45 |
+
st.session_state.step += 1
|
| 46 |
+
|
| 47 |
+
# Step 0: Welcome message and initial question
|
| 48 |
+
if st.session_state.step == 0:
|
| 49 |
+
st.write("Hi! I am your well-being assistant. I'll ask you some questions to understand how you're feeling.")
|
| 50 |
+
next_step_button = st.button("Start Chat")
|
| 51 |
+
if next_step_button:
|
| 52 |
+
next_step()
|
| 53 |
+
|
| 54 |
+
# Step 1: Ask for anxiety level
|
| 55 |
+
elif st.session_state.step == 1:
|
| 56 |
+
anxiety_level = st.text_input("On a scale of 1 to 10, how would you rate your anxiety level?", "")
|
| 57 |
+
if anxiety_level:
|
| 58 |
+
st.session_state.user_data['anxiety_level'] = int(anxiety_level)
|
| 59 |
+
next_step()
|
| 60 |
+
|
| 61 |
+
# Step 2: Ask for self-esteem
|
| 62 |
+
elif st.session_state.step == 2:
|
| 63 |
+
self_esteem = st.text_input("On a scale of 1 to 10, how would you rate your self-esteem?", "")
|
| 64 |
+
if self_esteem:
|
| 65 |
+
st.session_state.user_data['self_esteem'] = int(self_esteem)
|
| 66 |
+
next_step()
|
| 67 |
+
|
| 68 |
+
# Step 3: Ask for mental health history
|
| 69 |
+
elif st.session_state.step == 3:
|
| 70 |
+
mental_health_history = st.selectbox("How would you describe your mental health history?", ["None", "Minor Issues", "Moderate Issues", "Severe Issues"])
|
| 71 |
+
st.session_state.user_data['mental_health_history'] = mental_health_history
|
| 72 |
+
next_step()
|
| 73 |
+
|
| 74 |
+
# Step 4: Ask for stress level
|
| 75 |
+
elif st.session_state.step == 4:
|
| 76 |
+
stress_level = st.radio("On a scale of 0 to 2, how would you rate your stress level?", [0, 1, 2])
|
| 77 |
+
st.session_state.user_data['stress_level'] = stress_level
|
| 78 |
+
next_step()
|
| 79 |
+
|
| 80 |
+
# Step 5: Show advice based on user input
|
| 81 |
+
elif st.session_state.step == 5:
|
| 82 |
+
st.write("Thank you for providing the information!")
|
| 83 |
+
user_data = st.session_state.user_data
|
| 84 |
+
st.write(f"Your data: {user_data}")
|
| 85 |
+
|
| 86 |
+
st.subheader("π Personalized Health Advice")
|
| 87 |
+
advice = get_personalized_advice(user_data)
|
| 88 |
+
if advice:
|
| 89 |
+
st.write(advice)
|
| 90 |
+
else:
|
| 91 |
+
st.write("No advice available at the moment.")
|
| 92 |
+
|
| 93 |
+
# Option to restart the chat
|
| 94 |
+
restart_button = st.button("Restart Chat")
|
| 95 |
+
if restart_button:
|
| 96 |
+
st.session_state.step = 0
|
| 97 |
+
st.session_state.user_data = {}
|
| 98 |
+
|
| 99 |
+
# Main function to run the chatbot
|
| 100 |
def main():
|
| 101 |
+
chatbot_interface()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
if __name__ == "__main__":
|
| 104 |
main()
|