Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import pickle
|
5 |
+
|
6 |
+
@st.cache_resource()
|
7 |
+
def load_rfr():
|
8 |
+
model = pickle.load(open('rfr.sav', 'rb'))
|
9 |
+
return model
|
10 |
+
|
11 |
+
def load_xgb():
|
12 |
+
model = pickle.load(open('xgb.sav', 'rb'))
|
13 |
+
return model
|
14 |
+
|
15 |
+
def load_lr():
|
16 |
+
model = pickle.load(open('lr.sav', 'rb'))
|
17 |
+
return model
|
18 |
+
|
19 |
+
st.title(":red[AI Journey] Burnt Calories Prediction")
|
20 |
+
|
21 |
+
st.write("""
|
22 |
+
# Linear Regression
|
23 |
+
"""
|
24 |
+
)
|
25 |
+
|
26 |
+
number = st.number_input('Input the amount of exercise time!')
|
27 |
+
|
28 |
+
def model_prediction(age, height, weight, duration, heart_rate, body_temp, gender, model):
|
29 |
+
with st.spinner('Model is being loaded..'):
|
30 |
+
inputs = pd.DataFrame([{'Gender': gender, 'Age': age, 'Height': height, 'Weight': weight, 'Duration': duration, 'Heart_Rate': heart_rate, 'Body_Temp': body_temp}])
|
31 |
+
predictions = model.predict(inputs)
|
32 |
+
st.write("""# Prediction : """ , predictions)
|
33 |
+
|
34 |
+
|
35 |
+
with st.sidebar:
|
36 |
+
st.markdown("<h2 style='text-align: center; color: red;'>Settings Tab</h2>", unsafe_allow_html=True)
|
37 |
+
|
38 |
+
|
39 |
+
st.write("Input Settings:")
|
40 |
+
|
41 |
+
#define the age for the model
|
42 |
+
age = st.slider('age :', 18, 80, 1)
|
43 |
+
|
44 |
+
#define the height for the model
|
45 |
+
height = st.slider('height :', 120.0, 230.0, 1.0)
|
46 |
+
|
47 |
+
#define the weight for the model
|
48 |
+
weight = st.slider('weight :', 35.0, 140.0, 1.0)
|
49 |
+
|
50 |
+
#define the duration for the model
|
51 |
+
duration = st.slider('duration :', 1.0, 30.0, 10.0)
|
52 |
+
|
53 |
+
#define the heart_rate for the model
|
54 |
+
heart_rate = st.slider('heart_rate :', 60.0, 130.0, 20.0)
|
55 |
+
|
56 |
+
#define the body_temp for the model
|
57 |
+
body_temp = st.slider('body_temp :', 35.0, 45.0, 1.0)
|
58 |
+
|
59 |
+
#define the gender for the model
|
60 |
+
gender_input = st.radio("gender", ["Male", "Female"], index=None)
|
61 |
+
if gender_input == "Male":
|
62 |
+
gender = 0
|
63 |
+
else:
|
64 |
+
gender = 1
|
65 |
+
|
66 |
+
model_input = st.radio("model", ["Random Forest Regressor", "Linear Regressor", "XG Boost"], index=None)
|
67 |
+
if model_input == "Random Forest Regressor":
|
68 |
+
model = load_rfr()
|
69 |
+
elif model_input == "Linear Regressor":
|
70 |
+
model = load_lr()
|
71 |
+
else:
|
72 |
+
model_input == load_xgb()
|
73 |
+
|
74 |
+
with st.container():
|
75 |
+
if st.button("Calculate"):
|
76 |
+
model_prediction(age, height, weight, duration, heart_rate, body_temp, gender, model)
|