Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,18 +3,27 @@ import pandas as pd
|
|
3 |
import requests
|
4 |
|
5 |
# Function to analyze stress level based on various factors
|
6 |
-
def analyze_stress_level(df,
|
7 |
-
filtered_df = df
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
(df['depression'] == depression)
|
13 |
-
]
|
14 |
if not filtered_df.empty:
|
15 |
return filtered_df.iloc[0]['stress_level']
|
16 |
return "No matching data found."
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Function to fetch related health articles from GROC API
|
19 |
def get_health_documents_from_groc(query):
|
20 |
api_key = "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" # Replace with your actual GROC API key
|
@@ -42,20 +51,30 @@ def main():
|
|
42 |
st.write("Dataset Preview:")
|
43 |
st.dataframe(df.head())
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
# Analyze stress level
|
53 |
if st.button("Analyze Stress Level"):
|
54 |
-
stress_level = analyze_stress_level(df,
|
55 |
st.write(f"Stress Level: {stress_level}")
|
56 |
|
|
|
|
|
|
|
|
|
57 |
# Fetch related health articles
|
58 |
-
query = f"
|
59 |
articles = get_health_documents_from_groc(query)
|
60 |
st.write("Related Health Articles:")
|
61 |
for article in articles:
|
|
|
3 |
import requests
|
4 |
|
5 |
# Function to analyze stress level based on various factors
|
6 |
+
def analyze_stress_level(df, inputs):
|
7 |
+
filtered_df = df
|
8 |
+
for column, value in inputs.items():
|
9 |
+
if column in df.columns:
|
10 |
+
filtered_df = filtered_df[filtered_df[column] == value]
|
11 |
+
|
|
|
|
|
12 |
if not filtered_df.empty:
|
13 |
return filtered_df.iloc[0]['stress_level']
|
14 |
return "No matching data found."
|
15 |
|
16 |
+
# Function to provide advice based on stress level
|
17 |
+
def provide_advice(stress_level):
|
18 |
+
if stress_level == "Low":
|
19 |
+
return "Keep up the good work! Continue maintaining a balanced lifestyle."
|
20 |
+
elif stress_level == "Moderate":
|
21 |
+
return "Consider practicing relaxation techniques like yoga or meditation. Maintain healthy sleep and exercise routines."
|
22 |
+
elif stress_level == "High":
|
23 |
+
return "Seek support from counselors or health professionals. Share your concerns with trusted friends or family."
|
24 |
+
else:
|
25 |
+
return "No specific advice available."
|
26 |
+
|
27 |
# Function to fetch related health articles from GROC API
|
28 |
def get_health_documents_from_groc(query):
|
29 |
api_key = "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" # Replace with your actual GROC API key
|
|
|
51 |
st.write("Dataset Preview:")
|
52 |
st.dataframe(df.head())
|
53 |
|
54 |
+
# Dynamic input fields based on dataset columns
|
55 |
+
inputs = {}
|
56 |
+
for column in [
|
57 |
+
'anxiety_level', 'self_esteem', 'mental_health_history', 'depression',
|
58 |
+
'headache', 'blood_pressure', 'sleep_quality', 'breathing_problem',
|
59 |
+
'noise_level', 'living_conditions', 'safety', 'basic_needs',
|
60 |
+
'academic_performance', 'study_load', 'teacher_student_relationship',
|
61 |
+
'future_career_concerns', 'social_support', 'peer_pressure',
|
62 |
+
'extracurricular_activities', 'bullying'
|
63 |
+
]:
|
64 |
+
if column in df.columns:
|
65 |
+
inputs[column] = st.selectbox(f"Select {column.replace('_', ' ').title()}", df[column].unique())
|
66 |
|
67 |
# Analyze stress level
|
68 |
if st.button("Analyze Stress Level"):
|
69 |
+
stress_level = analyze_stress_level(df, inputs)
|
70 |
st.write(f"Stress Level: {stress_level}")
|
71 |
|
72 |
+
# Provide advice
|
73 |
+
advice = provide_advice(stress_level)
|
74 |
+
st.write(f"Advice: {advice}")
|
75 |
+
|
76 |
# Fetch related health articles
|
77 |
+
query = f"Health advice for stress level: {stress_level}"
|
78 |
articles = get_health_documents_from_groc(query)
|
79 |
st.write("Related Health Articles:")
|
80 |
for article in articles:
|