Update app.py
Browse files
app.py
CHANGED
|
@@ -11,21 +11,110 @@ import streamlit as st
|
|
| 11 |
# result = model_2.predict([[]])
|
| 12 |
# st.write(f"The predicted price of the rental house is {result}")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
import joblib
|
| 15 |
import streamlit as st
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
-
|
| 20 |
-
Device_Model = st.selectbox(
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# Load the model
|
| 31 |
model_path = "./rfc.pkl" # Adjust if in a subdirectory
|
|
@@ -41,13 +130,18 @@ try:
|
|
| 41 |
operating_system_encoded = mapping_os[Operating_System]
|
| 42 |
gender_encoded = mapping_gender[gender]
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
except FileNotFoundError:
|
| 48 |
-
st.error(f"Model file not found at: {model_path}")
|
| 49 |
except Exception as e:
|
| 50 |
-
st.error(f"An error occurred: {e}")
|
|
|
|
| 51 |
|
| 52 |
|
| 53 |
|
|
|
|
| 11 |
# result = model_2.predict([[]])
|
| 12 |
# st.write(f"The predicted price of the rental house is {result}")
|
| 13 |
|
| 14 |
+
# import joblib
|
| 15 |
+
# import streamlit as st
|
| 16 |
+
|
| 17 |
+
# st.title("User Behavior Using Mobile Prediction")
|
| 18 |
+
|
| 19 |
+
# # Inputs
|
| 20 |
+
# Device_Model = st.selectbox("Enter Device Model Type", ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'])
|
| 21 |
+
# age = st.number_input("Enter age", min_value=0, max_value=100, step=1, format="%d")
|
| 22 |
+
# gender = st.radio("Enter gender", ['Male', 'Female'])
|
| 23 |
+
# Operating_System = st.selectbox("Enter Operating System Type", ['Android', 'iOS'])
|
| 24 |
+
# App_Usage_Time = st.number_input("Enter the App Usage Time")
|
| 25 |
+
# Screen_On_Time = st.number_input("Enter the Screen On Time")
|
| 26 |
+
# Battery_Drain = st.number_input("Enter the Battery Drain")
|
| 27 |
+
# Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
|
| 28 |
+
# Data_Usage = st.number_input("Enter the Data Usage")
|
| 29 |
+
|
| 30 |
+
# # Load the model
|
| 31 |
+
# model_path = "./rfc.pkl" # Adjust if in a subdirectory
|
| 32 |
+
# try:
|
| 33 |
+
# model_2 = joblib.load(model_path)
|
| 34 |
+
|
| 35 |
+
# # Encode categorical variables
|
| 36 |
+
# mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4}
|
| 37 |
+
# mapping_os = {'Android': 0, 'iOS': 1}
|
| 38 |
+
# mapping_gender = {'Male': 0, 'Female': 1}
|
| 39 |
+
|
| 40 |
+
# device_model_encoded = mapping_device[Device_Model]
|
| 41 |
+
# operating_system_encoded = mapping_os[Operating_System]
|
| 42 |
+
# gender_encoded = mapping_gender[gender]
|
| 43 |
+
|
| 44 |
+
# if st.button("Submit"):
|
| 45 |
+
# result = model_2.predict([[device_model_encoded, operating_system_encoded, App_Usage_Time, Screen_On_Time, Battery_Drain, Number_of_Apps_Installed, Data_Usage, age, gender_encoded]])
|
| 46 |
+
# st.write(f"The predicted behavior is: {result}")
|
| 47 |
+
# except FileNotFoundError:
|
| 48 |
+
# st.error(f"Model file not found at: {model_path}")
|
| 49 |
+
# except Exception as e:
|
| 50 |
+
# st.error(f"An error occurred: {e}")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
import joblib
|
| 54 |
import streamlit as st
|
| 55 |
|
| 56 |
+
# Set page configuration
|
| 57 |
+
st.set_page_config(page_title="User Behavior Prediction", page_icon="π±", layout="wide")
|
| 58 |
+
|
| 59 |
+
# Title and Description
|
| 60 |
+
st.title("π± User Behavior Prediction Using Mobile Data")
|
| 61 |
+
st.markdown("""
|
| 62 |
+
Welcome to the **User Behavior Prediction App**!
|
| 63 |
+
This tool predicts user behavior based on mobile usage data, powered by a machine learning model.
|
| 64 |
+
Fill in the details below and click **Submit** to see the results.
|
| 65 |
+
""")
|
| 66 |
+
|
| 67 |
+
# Inputs in columns for better alignment
|
| 68 |
+
col1, col2 = st.columns(2)
|
| 69 |
|
| 70 |
+
with col1:
|
| 71 |
+
Device_Model = st.selectbox(
|
| 72 |
+
"π± Device Model Type",
|
| 73 |
+
['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'],
|
| 74 |
+
help="Select the type of mobile device being used."
|
| 75 |
+
)
|
| 76 |
+
Operating_System = st.selectbox(
|
| 77 |
+
"βοΈ Operating System Type",
|
| 78 |
+
['Android', 'iOS'],
|
| 79 |
+
help="Select the mobile's operating system."
|
| 80 |
+
)
|
| 81 |
+
gender = st.radio(
|
| 82 |
+
"π€ Gender",
|
| 83 |
+
['Male', 'Female'],
|
| 84 |
+
help="Select the gender of the user."
|
| 85 |
+
)
|
| 86 |
+
age = st.number_input(
|
| 87 |
+
"π Age",
|
| 88 |
+
min_value=0, max_value=100, step=1, format="%d",
|
| 89 |
+
help="Enter the user's age."
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
with col2:
|
| 93 |
+
App_Usage_Time = st.number_input(
|
| 94 |
+
"β±οΈ App Usage Time (in hours)",
|
| 95 |
+
min_value=0.0, step=0.1,
|
| 96 |
+
help="Enter the total app usage time (e.g., 3.5 hours)."
|
| 97 |
+
)
|
| 98 |
+
Screen_On_Time = st.number_input(
|
| 99 |
+
"π Screen On Time (in hours)",
|
| 100 |
+
min_value=0.0, step=0.1,
|
| 101 |
+
help="Enter the total screen on time (e.g., 5.2 hours)."
|
| 102 |
+
)
|
| 103 |
+
Battery_Drain = st.number_input(
|
| 104 |
+
"π Battery Drain (in percentage)",
|
| 105 |
+
min_value=0.0, step=0.1,
|
| 106 |
+
help="Enter the battery drain percentage (e.g., 15.5%)."
|
| 107 |
+
)
|
| 108 |
+
Number_of_Apps_Installed = st.number_input(
|
| 109 |
+
"π± Number of Apps Installed",
|
| 110 |
+
min_value=0, step=1,
|
| 111 |
+
help="Enter the total number of apps installed on the device."
|
| 112 |
+
)
|
| 113 |
+
Data_Usage = st.number_input(
|
| 114 |
+
"πΆ Data Usage (in GB)",
|
| 115 |
+
min_value=0.0, step=0.1,
|
| 116 |
+
help="Enter the total data usage (e.g., 1.5 GB)."
|
| 117 |
+
)
|
| 118 |
|
| 119 |
# Load the model
|
| 120 |
model_path = "./rfc.pkl" # Adjust if in a subdirectory
|
|
|
|
| 130 |
operating_system_encoded = mapping_os[Operating_System]
|
| 131 |
gender_encoded = mapping_gender[gender]
|
| 132 |
|
| 133 |
+
# Predict and display result
|
| 134 |
+
if st.button("π Submit"):
|
| 135 |
+
with st.spinner("Running prediction..."):
|
| 136 |
+
result = model_2.predict([[device_model_encoded, operating_system_encoded, App_Usage_Time, Screen_On_Time, Battery_Drain, Number_of_Apps_Installed, Data_Usage, age, gender_encoded]])
|
| 137 |
+
st.success("π Prediction Completed!")
|
| 138 |
+
st.markdown(f"**π Predicted User Behavior:** `{result[0]}`")
|
| 139 |
+
|
| 140 |
except FileNotFoundError:
|
| 141 |
+
st.error(f"π¨ Model file not found at: `{model_path}`. Please upload the model.")
|
| 142 |
except Exception as e:
|
| 143 |
+
st.error(f"π¨ An error occurred: {e}")
|
| 144 |
+
|
| 145 |
|
| 146 |
|
| 147 |
|