Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app.py +39 -0
- data.csv +30 -0
- model.cpython-312.pyc +0 -0
- model.py +85 -0
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from model import predict_disease_risk # Import the prediction function from model.py
|
| 3 |
+
|
| 4 |
+
# Streamlit GUI
|
| 5 |
+
st.title('Health Risk Prediction Based on Diet')
|
| 6 |
+
|
| 7 |
+
# User inputs (as described in your previous code)
|
| 8 |
+
# Include the Streamlit code for user inputs here
|
| 9 |
+
# User inputs
|
| 10 |
+
age = st.selectbox('Age', options=[...]) # Populate with age categories
|
| 11 |
+
gender = st.selectbox('Gender', options=['Male', 'Female'])
|
| 12 |
+
meals_per_day = st.number_input('Number of meals per day', min_value=1, max_value=10)
|
| 13 |
+
diet = st.selectbox('Diet', options=['Pollotarian', 'Vegetarian', 'Pescatarian', 'Non-Vegetarian', 'Eggetarian'])
|
| 14 |
+
skip_meals = st.selectbox('Do you skip meals?', options=['Never', 'Rarely', 'Sometimes', 'Often', 'Very frequently'])
|
| 15 |
+
hunger = st.selectbox('Do you experience feelings of hunger during the day?', options=['Never', 'Rarely', 'Sometimes', 'Often', 'Very frequently'])
|
| 16 |
+
nutritionist = st.selectbox('Do you consult a nutritionist?', options=['Never', 'Rarely', 'Sometimes', 'Often', 'Very frequently'])
|
| 17 |
+
cook_meals = st.selectbox('Do you cook your own meals?', options=['Never', 'Rarely', 'Sometimes', 'Often', 'Very frequently'])
|
| 18 |
+
main_meal = st.selectbox('Main meal of the day', options=['Breakfast', 'Lunch', 'Dinner', 'All'])
|
| 19 |
+
diet_description = st.selectbox('Diet description', options=['Freshly home-cooked produce', 'Restaurant meals'])
|
| 20 |
+
|
| 21 |
+
# Collect all inputs in a dictionary
|
| 22 |
+
input_data = {
|
| 23 |
+
'Age': age,
|
| 24 |
+
'Gender': gender,
|
| 25 |
+
'How many meals do you have a day?': meals_per_day,
|
| 26 |
+
'What would best describe your diet': diet,
|
| 27 |
+
'Choose all that apply: [I skip meals]': skip_meals,
|
| 28 |
+
'Choose all that apply: [I experience feelings of hunger during the day]': hunger,
|
| 29 |
+
'Choose all that apply: [I consult a nutritionist/dietician]': nutritionist,
|
| 30 |
+
'Choose all that apply: [I cook my own meals]': cook_meals,
|
| 31 |
+
'What would you consider to be the main meal of YOUR day?': main_meal,
|
| 32 |
+
'What does your diet mostly consist of and how is it prepared?': diet_description,
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# Prediction button
|
| 37 |
+
if st.button('Predict Disease Risk'):
|
| 38 |
+
prediction = predict_disease_risk(input_data)
|
| 39 |
+
st.write(f'Predicted Disease Risk: {prediction}')
|
data.csv
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Age,Gender,How many meals do you have a day? (number of regular occasions in a day when a significant and reasonably filling amount of food is eaten),What would best describe your diet:,Choose all that apply: [I skip meals],Choose all that apply: [I experience feelings of hunger during the day],Choose all that apply: [I consult a nutritionist/dietician],Choose all that apply: [I cook my own meals],What would you consider to be the main meal of YOUR day?,What does your diet mostly consist of and how is it prepared?,How many times a week do you order-in or go out to eat?,Are you allergic to any of the following? (Tick all that apply),What is your weekly food intake frequency of the following food categories: [Sweet foods],What is your weekly food intake frequency of the following food categories: [Salty foods],What is your weekly food intake frequency of the following food categories: [Fresh fruit],What is your weekly food intake frequency of the following food categories: [Fresh vegetables],"What is your weekly food intake frequency of the following food categories: [Oily, fried foods]",What is your weekly food intake frequency of the following food categories: [Meat],What is your weekly food intake frequency of the following food categories: [Seafood ],How frequently do you consume these beverages [Tea],How frequently do you consume these beverages [Coffee],How frequently do you consume these beverages [Aerated (Soft) Drinks],How frequently do you consume these beverages [Fruit Juices (Fresh/Packaged)],"How frequently do you consume these beverages [Dairy Beverages (Milk, Milkshakes, Smoothies, Buttermilk, etc)]",How frequently do you consume these beverages [Alcoholic Beverages],"What is your water consumption like (in a day, 1 cup=250ml approx)",Disease Risk
|
| 2 |
+
18-24,Male,5,Pollotarian (Vegetarian who consumes poultry and white meat but no red meat),Rarely,Often,Never,Sometimes,Lunch,Freshly home-cooked produce,4,Milk,Less often,Once a day,Less often,Once a day,Less often,Often,Often,Never,Never,Less often,Never,Less often,Never,More than 15 cups,You are healthy
|
| 3 |
+
18-24,Male,4,Vegetarian (No egg or meat),Rarely,Often,Rarely,Rarely,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Often,Often,Less often,Often,Often,Never,Never,Less often,Never,Often,Once a day,Often,Never,11-14 cups,You are healthy
|
| 4 |
+
45-54,Male,3,Pescatarian (Vegetarian who consumes only seafood),Never,Rarely,Never,Never,All,Freshly home-cooked produce,3,I do not have any allergies,Once a day,Several times a day,In every meal,In every meal,Less often,Never,Often,Once a day,Less often,Never,Less often,Once a day,Often,3 cups,High Risk
|
| 5 |
+
18-24,Male,2,Non-Vegetarian,Often,Often,Never,Sometimes,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a day,Once a day,Several times a day,In every meal,Few times a week,Once a day,Few times a week,Few times a week,Once a day,Once a month,Once a month,Few times a week,Never,7-10 cups,High Risk
|
| 6 |
+
18-24,Female,3,Eggetarian (Vegetarian who consumes egg and egg products),Sometimes,Sometimes,Never,Often,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Few times a week,Once a day,In every meal,Few times a week,Never,Never,Never,Never,Once a month,Once a month,Once a day,Once a month,4-6 cups,You are healthy
|
| 7 |
+
18-24,Female,3,Eggetarian (Vegetarian who consumes egg and egg products),Sometimes,Rarely,Never,Rarely,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a month,Several times a day,Once a month,In every meal,Once a month,Never,Never,Once a day,Once a day,Once a month,Once a month,Once a day,Once a month,4-6 cups,You are healthy
|
| 8 |
+
18-24,Male,3,Non-Vegetarian,Never,Never,Rarely,Sometimes,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Once a month,Several times a day,Several times a day,Once a month,In every meal,Once a month,Never,Once a month,Never,Few times a week,Few times a week,Never,More than 15 cups,You are healthy
|
| 9 |
+
Above 65,Male,3,Pescatarian (Vegetarian who consumes only seafood),Never,Rarely,Never,Never,Lunch,Freshly home-cooked produce,2,I do not have any allergies,Once a day,Several times a day,Once a day,In every meal,Once a day,Never,Several times a day,Once a day,Never,Few times a week,Never,Few times a week,Never,More than 15 cups,Medium Risk
|
| 10 |
+
Above 65,Female,2,Vegetarian (No egg or meat),Sometimes,Never,Never,Very frequently,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Several times a day,Several times a day,Once a day,In every meal,Few times a week,Never,Never,Once a day,Never,Never,Once a month,Once a day,Never,11-14 cups,You are healthy
|
| 11 |
+
Under 18,Male,3,Eggetarian (Vegetarian who consumes egg and egg products),Never,Often,Never,Never,Lunch,Freshly home-cooked produce,2,I do not have any allergies,Few times a week,Once a day,In every meal,Several times a day,Several times a day,Never,Never,Never,Never,Once a month,Few times a week,Once a day,Never,4-6 cups,High Risk
|
| 12 |
+
45-54,Female,3,Eggetarian (Vegetarian who consumes egg and egg products),Never,Sometimes,Rarely,Very frequently,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a day,Several times a day,Once a day,Once a day,Once a day,Never,Never,Once a day,Several times a day,Once a month,Few times a week,Several times a day,Never,Less than 3 cups,High Risk
|
| 13 |
+
18-24,Male,2,Non-Vegetarian,Often,Often,Never,Sometimes,Lunch,Restaurant meals,5,I do not have any allergies,Few times a week,Once a day,Once a day,Once a day,Few times a week,Few times a week,Once a month,Once a day,Few times a week,Once a day,Once a day,Few times a week,Once a month,4-6 cups,High Risk
|
| 14 |
+
18-24,Male,4,Non-Vegetarian,Rarely,Never,Never,Rarely,Lunch,Freshly home-cooked produce,4,I do not have any allergies,Few times a week,Several times a day,Once a day,Once a day,Several times a day,Once a day,Once a month,Once a month,Once a month,Few times a week,Few times a week,Once a day,Once a month,11-14 cups,High Risk
|
| 15 |
+
18-24,Female,3,Vegetarian (No egg or meat),Rarely,Never,Never,Never,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a month,Few times a week,Once a month,Several times a day,Few times a week,Never,Never,Never,Once a day,Once a month,Once a month,Once a day,Never,4-6 cups,You are healthy
|
| 16 |
+
18-24,Male,3,Non-Vegetarian,Rarely,Sometimes,Rarely,Rarely,Dinner,Freshly home-cooked produce,1,I do not have any allergies,Once a month,Once a day,Once a day,Once a day,Few times a week,Once a month,Never,Few times a week,Few times a week,Once a month,Never,Few times a week,Never,7-10 cups,You are healthy
|
| 17 |
+
35-44,Female,3,Pescatarian (Vegetarian who consumes only seafood),Never,Sometimes,Never,Very frequently,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Few times a week,In every meal,In every meal,Few times a week,Once a month,Once a month,Once a day,Never,Never,Few times a week,Once a day,Never,4-6 cups,You are healthy
|
| 18 |
+
45-54,Female,2,Vegetarian (No egg or meat),Rarely,Sometimes,Never,Very frequently,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Few times a week,Several times a day,Several times a day,Often,Never,Never,Once a day,Once a day,Never,Rarely,Never,Never,7-10 cups,Medium Risk
|
| 19 |
+
45-54,Female,3,Non-Vegetarian,Rarely,Sometimes,Rarely,Very frequently,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,In every meal,In every meal,In every meal,In every meal,Once a month,Once a day,Once a month,Once a month,Few times a week,Once a month,Never,Never,Once a month,3 cups,High Risk
|
| 20 |
+
35-44,Female,2,Eggetarian (Vegetarian who consumes egg and egg products),Sometimes,Sometimes,Never,Sometimes,Lunch,Freshly home-cooked produce,2,I do not have any allergies,Once a day,In every meal,Several times a day,Several times a day,Few times a week,Never,Never,Several times a day,Never,Never,Few times a week,With every meal,Never,7-10 cups,Medium Risk
|
| 21 |
+
18-24,Female,2,Vegetarian (No egg or meat),Sometimes,Rarely,Never,Sometimes,Dinner,Freshly home-cooked produce,1,I do not have any allergies,Never,Few times a week,Once a month,Several times a day,Once a day,Never,Never,Never,Once a day,Few times a week,Few times a week,Few times a week,Never,4-6 cups,You are healthy
|
| 22 |
+
Under 18,Male,4,Vegetarian (No egg or meat),Sometimes,Often,Never,Never,Dinner,Freshly home-cooked produce,5,Onion,Few times a week,In every meal,Once a month,In every meal,Often,Never,Never,Once a day,Once a day,Never,Once a day,Once a day,Never,7-10 cups,High Risk
|
| 23 |
+
Under 18,Female,2,Non-Vegetarian,Sometimes,Sometimes,Never,Rarely,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Few times a week,Once a day,Few times a week,Once a month,Few times a week,Few times a week,Never,Few times a week,Once a month,Once a day,Once a day,Never,4-6 cups,You are healthy
|
| 24 |
+
Under 18,Male,3,Vegetarian (No egg or meat),Never,Sometimes,Never,Never,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Once a month,Few times a week,Once a day,Once a day,Few times a week,Never,Never,Never,Once a month,Never,Once a month,Few times a week,Never,4-6 cups,You are healthy
|
| 25 |
+
Under 18,Male,3,Non-Vegetarian,Rarely,Never,Never,Rarely,Lunch,Freshly home-cooked produce,3,I do not have any allergies,Few times a week,Few times a week,Few times a week,Once a day,Few times a week,Once a day,Once a month,Once a month,Once a day,Once a month,Once a month,Once a month,Once a month,7-10 cups,Medium Risk
|
| 26 |
+
Under 18,Male,4,Vegetarian (No egg or meat),Very frequently,Very frequently,Never,Never,Dinner,Freshly home-cooked produce,5,Curd,In every meal,In every meal,Once a month,In every meal,Several times a day,Never,Never,Never,Never,Never,Once a month,Few times a week,Never,4-6 cups,High Risk
|
| 27 |
+
Under 18,Male,3,Vegetarian (No egg or meat),Rarely,Sometimes,Never,Very frequently,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a month,Few times a week,Several times a day,Several times a day,Few times a week,Never,Never,Never,Once a month,Once a month,Never,Once a month,Never,7-10 cups,You are healthy
|
| 28 |
+
Under 18,Male,4,Non-Vegetarian,Sometimes,Rarely,Never,Rarely,Breakfast,Freshly home-cooked produce,1,I do not have any allergies,Few times a week,Few times a week,Never,In every meal,Few times a week,Once a month,Never,Once a month,Never,Once a month,Once a month,Once a month,Never,7-10 cups,You are healthy
|
| 29 |
+
18-24,Male,2,Vegetarian (No egg or meat),Sometimes,Sometimes,Never,Sometimes,Lunch,Freshly home-cooked produce,1,I do not have any allergies,Once a day,Once a day,Once a day,Once a day,Few times a week,Never,Never,Once a month,Once a day,Few times a week,Once a month,Few times a week,Never,4-6 cups,Medium Risk
|
| 30 |
+
18-24,Male,2,Eggetarian (Vegetarian who consumes egg and egg products),Rarely,Often,Never,Rarely,Breakfast,Freshly home-cooked produce,5,I do not have any allergies,Once a day,Once a day,Once a day,Once a day,Few times a week,Never,Never,Never,Few times a week,Once a month,Few times a week,Few times a week,Once a day,4-6 cups,High Risk
|
model.cpython-312.pyc
ADDED
|
Binary file (3.75 kB). View file
|
|
|
model.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
from sklearn.model_selection import train_test_split
|
| 3 |
+
from sklearn.preprocessing import LabelEncoder, StandardScaler
|
| 4 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 5 |
+
from sklearn.metrics import accuracy_score, classification_report
|
| 6 |
+
import streamlit as st
|
| 7 |
+
|
| 8 |
+
# Load the data
|
| 9 |
+
@st.cache
|
| 10 |
+
def load_data():
|
| 11 |
+
return pd.read_csv('data.csv')
|
| 12 |
+
|
| 13 |
+
data = load_data()
|
| 14 |
+
|
| 15 |
+
# Check for missing values (optional, but good practice)
|
| 16 |
+
st.write("Checking for missing values...")
|
| 17 |
+
missing_values = data.isnull().sum()
|
| 18 |
+
st.write(missing_values)
|
| 19 |
+
|
| 20 |
+
# Encode categorical variables
|
| 21 |
+
label_encoders = {}
|
| 22 |
+
for column in data.select_dtypes(include=['object']).columns:
|
| 23 |
+
le = LabelEncoder()
|
| 24 |
+
data[column] = le.fit_transform(data[column])
|
| 25 |
+
label_encoders[column] = le
|
| 26 |
+
|
| 27 |
+
# Split the data into features and target
|
| 28 |
+
X = data.drop(columns=['Disease Risk'])
|
| 29 |
+
y = data['Disease Risk']
|
| 30 |
+
|
| 31 |
+
# Standardize the features
|
| 32 |
+
scaler = StandardScaler()
|
| 33 |
+
X_scaled = scaler.fit_transform(X)
|
| 34 |
+
|
| 35 |
+
# Split the data into training and testing sets
|
| 36 |
+
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2, random_state=42)
|
| 37 |
+
|
| 38 |
+
# Initialize the model
|
| 39 |
+
model = RandomForestClassifier(n_estimators=100, random_state=42)
|
| 40 |
+
|
| 41 |
+
# Train the model (optional to train here, but recommended to show steps)
|
| 42 |
+
st.write("Training the model...")
|
| 43 |
+
model.fit(X_train, y_train)
|
| 44 |
+
|
| 45 |
+
# Make predictions (optional for initial run, but necessary for GUI)
|
| 46 |
+
y_pred = model.predict(X_test)
|
| 47 |
+
|
| 48 |
+
# Evaluate the model (optional, but good for understanding performance)
|
| 49 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 50 |
+
st.write(f'Model Accuracy: {accuracy}')
|
| 51 |
+
st.write(classification_report(y_test, y_pred))
|
| 52 |
+
|
| 53 |
+
# Function to get predictions
|
| 54 |
+
def predict_disease_risk(input_data):
|
| 55 |
+
input_df = pd.DataFrame([input_data])
|
| 56 |
+
for column, le in label_encoders.items():
|
| 57 |
+
input_df[column] = le.transform(input_df[column])
|
| 58 |
+
input_scaled = scaler.transform(input_df)
|
| 59 |
+
prediction = model.predict(input_scaled)
|
| 60 |
+
return prediction[0]
|
| 61 |
+
|
| 62 |
+
# Streamlit GUI
|
| 63 |
+
st.title('Health Risk Prediction Based on Diet')
|
| 64 |
+
|
| 65 |
+
# User inputs (simplified for demonstration, customize as needed)
|
| 66 |
+
st.sidebar.title('User Input')
|
| 67 |
+
|
| 68 |
+
age = st.sidebar.slider('Age', min_value=18, max_value=100, value=30)
|
| 69 |
+
gender = st.sidebar.radio('Gender', ['Male', 'Female'])
|
| 70 |
+
meals_per_day = st.sidebar.slider('Meals per Day', min_value=1, max_value=10, value=3)
|
| 71 |
+
diet = st.sidebar.selectbox('Diet Type', ['Pollotarian', 'Vegetarian', 'Pescatarian', 'Non-Vegetarian', 'Eggetarian'])
|
| 72 |
+
# Add more inputs based on your specific dataset columns
|
| 73 |
+
|
| 74 |
+
input_data = {
|
| 75 |
+
'Age': age,
|
| 76 |
+
'Gender': gender,
|
| 77 |
+
'Meals per Day': meals_per_day,
|
| 78 |
+
'Diet Type': diet,
|
| 79 |
+
# Add more keys based on your specific dataset columns
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# Prediction button
|
| 83 |
+
if st.button('Predict Disease Risk'):
|
| 84 |
+
prediction = predict_disease_risk(input_data)
|
| 85 |
+
st.write(f'Predicted Disease Risk: {prediction}')
|