saherPervaiz commited on
Commit
9e67cb5
Β·
verified Β·
1 Parent(s): c4587cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -68
app.py CHANGED
@@ -3,13 +3,10 @@ import streamlit as st
3
  import pandas as pd
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
6
- import requests
7
- from googleapiclient.discovery import build
8
- from google.oauth2.credentials import Credentials
9
  from groq import Groq
10
 
11
  # Groq API Key (replace with your actual API key)
12
- groq_api_key = "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"
13
 
14
  # Initialize Groq client
15
  client = Groq(api_key=groq_api_key)
@@ -75,70 +72,69 @@ def main():
75
  This app helps identify areas of concern in students' well-being and provides personalized advice based on their responses.
76
  """)
77
 
78
- st.markdown("## πŸ“‚ Upload Your Dataset")
79
- uploaded_file = st.file_uploader("Upload your dataset (CSV)", type=["csv"])
80
- if uploaded_file:
81
- df = load_data(uploaded_file)
82
- st.success("Dataset uploaded successfully!")
83
- st.write("### Dataset Preview:")
84
- st.dataframe(df.head())
85
-
86
- required_columns = [
87
- 'anxiety_level', 'self_esteem', 'mental_health_history', 'depression',
88
- 'headache', 'blood_pressure', 'sleep_quality', 'breathing_problem',
89
- 'noise_level', 'living_conditions', 'safety', 'basic_needs',
90
- 'academic_performance', 'study_load', 'teacher_student_relationship',
91
- 'future_career_concerns', 'social_support', 'peer_pressure',
92
- 'extracurricular_activities', 'bullying', 'stress_level'
93
- ]
94
- missing_columns = [col for col in required_columns if col not in df.columns]
95
-
96
- if missing_columns:
97
- st.error(f"The uploaded dataset is missing the following required columns: {', '.join(missing_columns)}")
98
- else:
99
- if df.isnull().values.any():
100
- st.warning("The dataset contains missing values. Rows with missing values will be skipped.")
101
- df = df.dropna()
102
-
103
- tab1, tab2, tab3 = st.tabs(["🏠 Home", "πŸ“Š Analysis", "πŸ“° Resources"])
104
-
105
- with tab1:
106
- st.write("### Welcome to the Well-being Advisor!")
107
- st.write("""
108
- Use the tabs to explore data, generate advice, and access mental health resources.
109
- """)
110
-
111
- with tab2:
112
- st.markdown("### πŸ“Š Select a Row for Analysis")
113
- selected_row = st.selectbox(
114
- "Select a row (based on index) to analyze:",
115
- options=df.index,
116
- format_func=lambda x: f"Row {x} - Stress Level: {stress_level_to_string(df.loc[x, 'stress_level'])}, Anxiety: {df.loc[x, 'anxiety_level']}, Depression: {df.loc[x, 'depression']}",
117
- )
118
- row_data = df.loc[selected_row].to_dict()
119
- st.write("### Selected User Details:")
120
- st.json(row_data)
121
-
122
- st.subheader("πŸ”” Health Advice Based on Groq")
123
- advice = get_personalized_advice(row_data)
124
- if advice:
125
- st.write(advice)
126
- else:
127
- st.warning("No specific advice available based on this user's data.")
128
-
129
- # Include graphs in analysis tab
130
- plot_graphs(df)
131
-
132
- with tab3:
133
- st.subheader("πŸ“° Mental Health Resources")
134
- articles = fetch_health_articles("mental health")
135
- if articles:
136
- for article in articles:
137
- st.write(f"**{article['title']}**")
138
- st.write(f"{article['description']}")
139
- st.write(f"[Read more]({article['url']})")
140
- else:
141
- st.write("No articles available at the moment.")
142
 
143
  if __name__ == "__main__":
144
  main()
 
3
  import pandas as pd
4
  import matplotlib.pyplot as plt
5
  import seaborn as sns
 
 
 
6
  from groq import Groq
7
 
8
  # Groq API Key (replace with your actual API key)
9
+ groq_api_key = "your_groq_api_key"
10
 
11
  # Initialize Groq client
12
  client = Groq(api_key=groq_api_key)
 
72
  This app helps identify areas of concern in students' well-being and provides personalized advice based on their responses.
73
  """)
74
 
75
+ # Dynamic Data Input
76
+ st.markdown("## πŸ“‹ Enter Your Data")
77
+ st.write("Please fill out the form below to receive personalized well-being advice.")
78
+
79
+ # Dynamic form for user input
80
+ anxiety_level = st.slider("Anxiety Level (1 to 10)", 1, 10, 5)
81
+ self_esteem = st.slider("Self-esteem (1 to 10)", 1, 10, 5)
82
+ mental_health_history = st.selectbox("Mental Health History", ["None", "Minor Issues", "Moderate Issues", "Severe Issues"])
83
+ depression = st.slider("Depression Level (1 to 10)", 1, 10, 5)
84
+ headache = st.slider("Headache Level (1 to 10)", 1, 10, 5)
85
+ blood_pressure = st.slider("Blood Pressure (1 to 10)", 1, 10, 5)
86
+ sleep_quality = st.slider("Sleep Quality (1 to 10)", 1, 10, 5)
87
+ breathing_problem = st.selectbox("Breathing Problem", ["None", "Mild", "Severe"])
88
+ noise_level = st.slider("Noise Level (1 to 10)", 1, 10, 5)
89
+ living_conditions = st.slider("Living Conditions (1 to 10)", 1, 10, 5)
90
+ safety = st.slider("Safety (1 to 10)", 1, 10, 5)
91
+ basic_needs = st.slider("Basic Needs Satisfaction (1 to 10)", 1, 10, 5)
92
+ academic_performance = st.slider("Academic Performance (1 to 10)", 1, 10, 5)
93
+ study_load = st.slider("Study Load (1 to 10)", 1, 10, 5)
94
+ teacher_student_relationship = st.slider("Teacher-Student Relationship (1 to 10)", 1, 10, 5)
95
+ future_career_concerns = st.slider("Future Career Concerns (1 to 10)", 1, 10, 5)
96
+ social_support = st.slider("Social Support (1 to 10)", 1, 10, 5)
97
+ peer_pressure = st.slider("Peer Pressure (1 to 10)", 1, 10, 5)
98
+ extracurricular_activities = st.slider("Extracurricular Activities (1 to 10)", 1, 10, 5)
99
+ bullying = st.slider("Bullying Level (1 to 10)", 1, 10, 5)
100
+ stress_level = st.slider("Stress Level (0 - Low, 1 - Moderate, 2 - High)", 0, 2, 1)
101
+
102
+ user_data = {
103
+ "anxiety_level": anxiety_level,
104
+ "self_esteem": self_esteem,
105
+ "mental_health_history": mental_health_history,
106
+ "depression": depression,
107
+ "headache": headache,
108
+ "blood_pressure": blood_pressure,
109
+ "sleep_quality": sleep_quality,
110
+ "breathing_problem": breathing_problem,
111
+ "noise_level": noise_level,
112
+ "living_conditions": living_conditions,
113
+ "safety": safety,
114
+ "basic_needs": basic_needs,
115
+ "academic_performance": academic_performance,
116
+ "study_load": study_load,
117
+ "teacher_student_relationship": teacher_student_relationship,
118
+ "future_career_concerns": future_career_concerns,
119
+ "social_support": social_support,
120
+ "peer_pressure": peer_pressure,
121
+ "extracurricular_activities": extracurricular_activities,
122
+ "bullying": bullying,
123
+ "stress_level": stress_level
124
+ }
125
+
126
+ st.write(f"### Selected User Data: {user_data}")
127
+
128
+ # Provide personalized advice
129
+ st.subheader("πŸ”” Health Advice Based on Your Input")
130
+ advice = get_personalized_advice(user_data)
131
+ if advice:
132
+ st.write(advice)
133
+ else:
134
+ st.warning("No advice available at the moment.")
135
+
136
+ # Include graphs (if relevant data exists)
137
+ plot_graphs(pd.DataFrame([user_data])) # Placeholder for any data visualization logic
 
138
 
139
  if __name__ == "__main__":
140
  main()