Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,22 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import requests
|
4 |
-
from transformers import pipeline
|
5 |
-
import datetime
|
6 |
|
7 |
-
#
|
8 |
-
@st.cache
|
9 |
-
def load_data(file):
|
10 |
-
return pd.read_csv(file)
|
11 |
-
|
12 |
-
# Fetch health advice from the dataset
|
13 |
def get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp):
|
14 |
filtered_df = df[
|
15 |
-
(df['Age']
|
16 |
-
(df['Heart_Rate']
|
17 |
-
(df['Blood_Pressure_Systolic']
|
18 |
-
(df['Blood_Pressure_Diastolic']
|
19 |
]
|
20 |
if not filtered_df.empty:
|
21 |
return filtered_df.iloc[0]['Health_Risk_Level']
|
22 |
return "No matching health data found."
|
23 |
|
24 |
-
#
|
25 |
def get_health_documents_from_groc(query):
|
26 |
-
api_key = "
|
27 |
url = f"https://api.groc.com/v1/search"
|
28 |
params = {
|
29 |
"query": query,
|
@@ -35,57 +28,37 @@ def get_health_documents_from_groc(query):
|
|
35 |
data = response.json()
|
36 |
return data.get("results", [])
|
37 |
else:
|
|
|
38 |
return [{"title": f"Error: {response.status_code}", "url": ""}]
|
39 |
|
40 |
-
#
|
41 |
-
@st.cache(allow_output_mutation=True)
|
42 |
-
def load_gpt2_model():
|
43 |
-
return pipeline("text-generation", model="gpt2")
|
44 |
-
|
45 |
-
# Main Streamlit App
|
46 |
def main():
|
47 |
-
st.title("Health Advisory Assistant")
|
48 |
-
st.write("A personalized health advisor based on student health data.")
|
49 |
|
50 |
-
#
|
51 |
-
uploaded_file = st.
|
52 |
if uploaded_file is not None:
|
53 |
-
df =
|
54 |
-
st.
|
55 |
-
st.write("### Dataset Preview")
|
56 |
st.dataframe(df.head())
|
57 |
|
58 |
-
# User input
|
59 |
-
st.
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
diastolic_bp = st.number_input("Diastolic Blood Pressure", min_value=0, max_value=200, value=80)
|
64 |
|
65 |
-
#
|
66 |
-
|
67 |
-
|
68 |
-
# Fetch health advice
|
69 |
-
if st.button("Get Health Advice"):
|
70 |
risk_level = get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp)
|
71 |
-
st.write(f"
|
72 |
-
|
73 |
-
# Fetch related health articles
|
74 |
-
st.write("### Related Health Articles")
|
75 |
-
articles = get_health_documents_from_groc("Blood Pressure and Heart Rate")
|
76 |
-
if articles:
|
77 |
-
for article in articles:
|
78 |
-
st.write(f"- [{article['title']}]({article['url']})")
|
79 |
-
else:
|
80 |
-
st.write("No articles found.")
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
# Run the app
|
90 |
if __name__ == "__main__":
|
91 |
main()
|
|
|
1 |
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,
|
|
|
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 |
|
|
|
63 |
if __name__ == "__main__":
|
64 |
main()
|