Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,22 +2,23 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
|
5 |
-
# Function to
|
6 |
-
def
|
7 |
filtered_df = df[
|
8 |
-
(df['
|
9 |
-
(df['
|
10 |
-
(df['
|
11 |
-
(df['
|
|
|
12 |
]
|
13 |
if not filtered_df.empty:
|
14 |
-
return filtered_df.iloc[0]['
|
15 |
-
return "No matching
|
16 |
|
17 |
-
# Function to
|
18 |
def get_health_documents_from_groc(query):
|
19 |
api_key = "YOUR_GROC_API_KEY" # Replace with your actual GROC API key
|
20 |
-
url =
|
21 |
params = {
|
22 |
"query": query,
|
23 |
"api_key": api_key,
|
@@ -25,38 +26,38 @@ def get_health_documents_from_groc(query):
|
|
25 |
}
|
26 |
response = requests.get(url, params=params)
|
27 |
if response.status_code == 200:
|
28 |
-
|
29 |
-
return data.get("results", [])
|
30 |
else:
|
31 |
st.error(f"Error {response.status_code}: {response.text}")
|
32 |
-
return [
|
33 |
|
34 |
# Main Streamlit app
|
35 |
def main():
|
36 |
-
st.title("
|
37 |
|
38 |
-
#
|
39 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type="csv")
|
40 |
if uploaded_file is not None:
|
41 |
df = pd.read_csv(uploaded_file)
|
42 |
st.write("Dataset Preview:")
|
43 |
st.dataframe(df.head())
|
44 |
|
45 |
-
#
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
-
#
|
52 |
-
if st.button("
|
53 |
-
|
54 |
-
st.write(f"
|
55 |
|
56 |
-
#
|
57 |
-
query = f"
|
58 |
-
st.write("Related Health Articles:")
|
59 |
articles = get_health_documents_from_groc(query)
|
|
|
60 |
for article in articles:
|
61 |
st.markdown(f"- [{article['title']}]({article['url']})")
|
62 |
|
|
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
|
5 |
+
# Function to analyze stress level based on various factors
|
6 |
+
def analyze_stress_level(df, anxiety_level, self_esteem, academic_performance, study_load, depression):
|
7 |
filtered_df = df[
|
8 |
+
(df['anxiety_level'] == anxiety_level) &
|
9 |
+
(df['self_esteem'] == self_esteem) &
|
10 |
+
(df['academic_performance'] == academic_performance) &
|
11 |
+
(df['study_load'] == study_load) &
|
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 = "YOUR_GROC_API_KEY" # Replace with your actual GROC API key
|
21 |
+
url = "https://api.groc.com/v1/search"
|
22 |
params = {
|
23 |
"query": query,
|
24 |
"api_key": api_key,
|
|
|
26 |
}
|
27 |
response = requests.get(url, params=params)
|
28 |
if response.status_code == 200:
|
29 |
+
return response.json().get("results", [])
|
|
|
30 |
else:
|
31 |
st.error(f"Error {response.status_code}: {response.text}")
|
32 |
+
return []
|
33 |
|
34 |
# Main Streamlit app
|
35 |
def main():
|
36 |
+
st.title("Student Stress Analysis and Health Advisory")
|
37 |
|
38 |
+
# Upload dataset
|
39 |
uploaded_file = st.file_uploader("Upload your dataset (CSV)", type="csv")
|
40 |
if uploaded_file is not None:
|
41 |
df = pd.read_csv(uploaded_file)
|
42 |
st.write("Dataset Preview:")
|
43 |
st.dataframe(df.head())
|
44 |
|
45 |
+
# Input fields
|
46 |
+
anxiety_level = st.selectbox("Anxiety Level", df['anxiety_level'].unique())
|
47 |
+
self_esteem = st.selectbox("Self Esteem", df['self_esteem'].unique())
|
48 |
+
academic_performance = st.selectbox("Academic Performance", df['academic_performance'].unique())
|
49 |
+
study_load = st.selectbox("Study Load", df['study_load'].unique())
|
50 |
+
depression = st.selectbox("Depression", df['depression'].unique())
|
51 |
|
52 |
+
# Analyze stress level
|
53 |
+
if st.button("Analyze Stress Level"):
|
54 |
+
stress_level = analyze_stress_level(df, anxiety_level, self_esteem, academic_performance, study_load, depression)
|
55 |
+
st.write(f"Stress Level: {stress_level}")
|
56 |
|
57 |
+
# Fetch related health articles
|
58 |
+
query = f"Stress management articles for stress level: {stress_level}"
|
|
|
59 |
articles = get_health_documents_from_groc(query)
|
60 |
+
st.write("Related Health Articles:")
|
61 |
for article in articles:
|
62 |
st.markdown(f"- [{article['title']}]({article['url']})")
|
63 |
|