Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,7 @@
|
|
| 22 |
# st.write(f"The predicted price of the rental house is {result}")
|
| 23 |
|
| 24 |
|
| 25 |
-
import
|
| 26 |
-
import numpy as np
|
| 27 |
import joblib
|
| 28 |
import streamlit as st
|
| 29 |
|
|
@@ -39,19 +38,29 @@ Battery_Drain = st.number_input("Enter the Battery Drain")
|
|
| 39 |
Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
|
| 40 |
Data_Usage = st.number_input("Enter the Data Usage")
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
st.error("Model file
|
| 46 |
-
|
| 47 |
-
if st.button("Submit"):
|
| 48 |
try:
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
except Exception as e:
|
| 54 |
-
st.error(f"
|
|
|
|
| 55 |
|
| 56 |
|
| 57 |
|
|
|
|
| 22 |
# st.write(f"The predicted price of the rental house is {result}")
|
| 23 |
|
| 24 |
|
| 25 |
+
import os
|
|
|
|
| 26 |
import joblib
|
| 27 |
import streamlit as st
|
| 28 |
|
|
|
|
| 38 |
Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
|
| 39 |
Data_Usage = st.number_input("Enter the Data Usage")
|
| 40 |
|
| 41 |
+
# Path Debugging
|
| 42 |
+
model_path = r"Mobile_data_user_behaviour/rfc.pkl"
|
| 43 |
+
if not os.path.exists(model_path):
|
| 44 |
+
st.error(f"Model file not found at: {model_path}")
|
| 45 |
+
else:
|
|
|
|
| 46 |
try:
|
| 47 |
+
model_2 = joblib.load(model_path)
|
| 48 |
+
|
| 49 |
+
# Encode categorical variables
|
| 50 |
+
mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4}
|
| 51 |
+
mapping_os = {'Android': 0, 'iOS': 1}
|
| 52 |
+
mapping_gender = {'Male': 0, 'Female': 1}
|
| 53 |
+
|
| 54 |
+
device_model_encoded = mapping_device[Device_Model]
|
| 55 |
+
operating_system_encoded = mapping_os[Operating_System]
|
| 56 |
+
gender_encoded = mapping_gender[gender]
|
| 57 |
+
|
| 58 |
+
if st.button("Submit"):
|
| 59 |
+
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]])
|
| 60 |
+
st.write(f"The predicted behavior is: {result}")
|
| 61 |
except Exception as e:
|
| 62 |
+
st.error(f"Failed to load the model or predict: {e}")
|
| 63 |
+
|
| 64 |
|
| 65 |
|
| 66 |
|