saherPervaiz commited on
Commit
e561de7
·
verified ·
1 Parent(s): a8ba087

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -2,22 +2,23 @@ import streamlit as st
2
  import pandas as pd
3
  import requests
4
 
5
- # Function to get health advice based on inputs
6
- def get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp):
7
  filtered_df = df[
8
- (df['Age'].between(age - 2, age + 2)) & # Allow ±2 years
9
- (df['Heart_Rate'].between(heart_rate - 5, heart_rate + 5)) & # Allow ±5 bpm
10
- (df['Blood_Pressure_Systolic'].between(systolic_bp - 10, systolic_bp + 10)) & # Allow ±10
11
- (df['Blood_Pressure_Diastolic'].between(diastolic_bp - 10, diastolic_bp + 10)) # Allow ±10
 
12
  ]
13
  if not filtered_df.empty:
14
- return filtered_df.iloc[0]['Health_Risk_Level']
15
- return "No matching health data found."
16
 
17
- # Function to get health articles from GROC API
18
  def get_health_documents_from_groc(query):
19
  api_key = "YOUR_GROC_API_KEY" # Replace with your actual GROC API key
20
- url = f"https://api.groc.com/v1/search"
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
- data = response.json()
29
- return data.get("results", [])
30
  else:
31
  st.error(f"Error {response.status_code}: {response.text}")
32
- return [{"title": f"Error: {response.status_code}", "url": ""}]
33
 
34
  # Main Streamlit app
35
  def main():
36
- st.title("Health Risk Level and Advisory Assistant")
37
 
38
- # File upload
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
- # User input
46
- age = st.number_input("Enter Age", min_value=1, max_value=100, step=1)
47
- heart_rate = st.number_input("Enter Heart Rate (bpm)", min_value=30, max_value=200, step=1)
48
- systolic_bp = st.number_input("Enter Systolic Blood Pressure", min_value=80, max_value=200, step=1)
49
- diastolic_bp = st.number_input("Enter Diastolic Blood Pressure", min_value=40, max_value=120, step=1)
 
50
 
51
- # Predict health risk level
52
- if st.button("Get Health Risk Level"):
53
- risk_level = get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp)
54
- st.write(f"Health Risk Level: {risk_level}")
55
 
56
- # Retrieve related health articles
57
- query = f"Health risk for age {age}, heart rate {heart_rate}, BP {systolic_bp}/{diastolic_bp}"
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