File size: 2,700 Bytes
aeb7752
 
 
 
a8ba087
aeb7752
 
a8ba087
 
 
 
aeb7752
 
 
 
 
a8ba087
aeb7752
a8ba087
aeb7752
 
 
 
 
 
 
 
 
 
 
a8ba087
aeb7752
 
a8ba087
aeb7752
a8ba087
aeb7752
a8ba087
 
aeb7752
a8ba087
 
aeb7752
 
a8ba087
 
 
 
 
aeb7752
a8ba087
 
aeb7752
a8ba087
aeb7752
a8ba087
 
 
 
 
 
aeb7752
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import streamlit as st
import pandas as pd
import requests

# Function to get health advice based on inputs
def get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp):
    filtered_df = df[
        (df['Age'].between(age - 2, age + 2)) &  # Allow ±2 years
        (df['Heart_Rate'].between(heart_rate - 5, heart_rate + 5)) &  # Allow ±5 bpm
        (df['Blood_Pressure_Systolic'].between(systolic_bp - 10, systolic_bp + 10)) &  # Allow ±10
        (df['Blood_Pressure_Diastolic'].between(diastolic_bp - 10, diastolic_bp + 10))  # Allow ±10
    ]
    if not filtered_df.empty:
        return filtered_df.iloc[0]['Health_Risk_Level']
    return "No matching health data found."

# Function to get health articles from GROC API
def get_health_documents_from_groc(query):
    api_key = "YOUR_GROC_API_KEY"  # Replace with your actual GROC API key
    url = f"https://api.groc.com/v1/search"
    params = {
        "query": query,
        "api_key": api_key,
        "type": "article"
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        data = response.json()
        return data.get("results", [])
    else:
        st.error(f"Error {response.status_code}: {response.text}")
        return [{"title": f"Error: {response.status_code}", "url": ""}]

# Main Streamlit app
def main():
    st.title("Health Risk Level and Advisory Assistant")

    # File upload
    uploaded_file = st.file_uploader("Upload your dataset (CSV)", type="csv")
    if uploaded_file is not None:
        df = pd.read_csv(uploaded_file)
        st.write("Dataset Preview:")
        st.dataframe(df.head())

        # User input
        age = st.number_input("Enter Age", min_value=1, max_value=100, step=1)
        heart_rate = st.number_input("Enter Heart Rate (bpm)", min_value=30, max_value=200, step=1)
        systolic_bp = st.number_input("Enter Systolic Blood Pressure", min_value=80, max_value=200, step=1)
        diastolic_bp = st.number_input("Enter Diastolic Blood Pressure", min_value=40, max_value=120, step=1)

        # Predict health risk level
        if st.button("Get Health Risk Level"):
            risk_level = get_health_advice(df, age, heart_rate, systolic_bp, diastolic_bp)
            st.write(f"Health Risk Level: {risk_level}")

            # Retrieve related health articles
            query = f"Health risk for age {age}, heart rate {heart_rate}, BP {systolic_bp}/{diastolic_bp}"
            st.write("Related Health Articles:")
            articles = get_health_documents_from_groc(query)
            for article in articles:
                st.markdown(f"- [{article['title']}]({article['url']})")

if __name__ == "__main__":
    main()