File size: 7,956 Bytes
ce9fd41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7880504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e6e5e7f
f10a1ca
 
7880504
 
 
bde0c07
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7880504
 
 
 
 
 
 
f10a1ca
7880504
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f10a1ca
63f0a91
 
 
 
bdae506
63f0a91
 
 
 
bdae506
63f0a91
 
 
bdae506
7880504
 
 
 
 
 
 
63f0a91
7880504
63f0a91
7880504
 
bdae506
ce9fd41
bde0c07
f10a1ca
 
 
 
 
 
 
 
 
 
 
 
 
ec20f8f
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# import pandas as pd,numpy as np
# import joblib
# import streamlit as st

# st.title("User Behavior Using Mobile Prediction")

# Device_Model = st.selectbox("Enter Device Model Type",['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5','Google Pixel 5','OnePlus 9','Samsung Galaxy S21'])
# age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" )
# gender = st.radio("Enter gender",['Male','Female'])
# Operating_System= st.selectbox("Enter Operating System Type",['Android','iOS'])
# App_Usage_Time = st.number_input("Enter the App Usage Time")
# Screen_On_Time= st.number_input("Enter the Screen On Time")
# Battery_Drain= st.number_input("Enter the Battery Drain")
# Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
# Data_Usage = st.number_input("Enter the Data Usage")

# model_2 = joblib.load(r"Mobile_data_user_behaviour/rfc.pkl") #pickle file path


# if st.button("Submit"):
#     result = model_2.predict([[Device_Model,Operating_System,App_Usage_Time,Screen_On_Time,Battery_Drain,Number_of_Apps_Installed,Data_Usage,age,gender]])
#     st.write(f"The predicted price of the rental house is {result}")


# import joblib
# import streamlit as st

# st.title("User Behavior Using Mobile Prediction")

# # Inputs
# Device_Model = st.selectbox("Enter Device Model Type", ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'])
# age = st.number_input("Enter age", min_value=0, max_value=100, step=1, format="%d")
# gender = st.radio("Enter gender", ['Male', 'Female'])
# Operating_System = st.selectbox("Enter Operating System Type", ['Android', 'iOS'])
# App_Usage_Time = st.number_input("Enter the App Usage Time")
# Screen_On_Time = st.number_input("Enter the Screen On Time")
# Battery_Drain = st.number_input("Enter the Battery Drain")
# Number_of_Apps_Installed = st.number_input("Enter the Number of Apps Installed")
# Data_Usage = st.number_input("Enter the Data Usage")

# # Load the model
# model_path = "./rfc.pkl"  # Adjust if in a subdirectory
# try:
#     model_2 = joblib.load(model_path)

#     # Encode categorical variables
#     mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4}
#     mapping_os = {'Android': 0, 'iOS': 1}
#     mapping_gender = {'Male': 0, 'Female': 1}

#     device_model_encoded = mapping_device[Device_Model]
#     operating_system_encoded = mapping_os[Operating_System]
#     gender_encoded = mapping_gender[gender]

#     if st.button("Submit"):
#         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]])
#         st.write(f"The predicted behavior is: {result}")
# except FileNotFoundError:
#     st.error(f"Model file not found at: {model_path}")
# except Exception as e:
#     st.error(f"An error occurred: {e}")


import joblib
import streamlit as st

# Set page configuration
st.set_page_config(page_title="User Behavior Prediction", page_icon="πŸ“±", layout="wide")

# Add background image using custom CSS
def add_bg_from_url():
    st.markdown(
        f"""
        <style>
        .stApp {{
            background-image: url("https://images.unsplash.com/photo-1520968959305-3c85d514f690?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&q=80&w=1080");
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            background-attachment: fixed;
            color: white;
        }}
        .stMarkdown h1, .stMarkdown h2, .stMarkdown h3 {{
            color: #F7F9FB !important;
        }}
        </style>
        """,
        unsafe_allow_html=True
    )

add_bg_from_url()

# Title and Description
st.title("πŸ“± User Behavior Prediction Using Mobile Data")
st.markdown("""
Welcome to the **User Behavior Prediction App**!  
This tool predicts user behavior based on mobile usage data, powered by a machine learning model.  
Fill in the details below and click **Submit** to see the results.
""")

# Inputs in columns for better alignment
col1, col2 = st.columns(2)

with col1:
    Device_Model = st.selectbox(
        "πŸ“± Device Model Type",
        ['Xiaomi Mi 11', 'iPhone 12', 'Google Pixel 5', 'OnePlus 9', 'Samsung Galaxy S21'],
        help="Select the type of mobile device being used."
    )
    Operating_System = st.selectbox(
        "βš™οΈ Operating System Type",
        ['Android', 'iOS'],
        help="Select the mobile's operating system."
    )
    gender = st.radio(
        "πŸ‘€ Gender",
        ['Male', 'Female'],
        help="Select the gender of the user."
    )
    age = st.number_input(
        "πŸŽ‚ Age",
        min_value=0, max_value=100, step=1, format="%d",
        help="Enter the user's age."
    )

with col2:
    App_Usage_Time = st.number_input(
        "⏱️ App Usage Time (in hours)",
        min_value=0.0, step=0.1,
        help="Enter the total app usage time (e.g., 3.5 hours)."
    )
    Screen_On_Time = st.number_input(
        "πŸ”† Screen On Time (in hours)",
        min_value=0.0, step=0.1,
        help="Enter the total screen on time (e.g., 5.2 hours)."
    )
    Battery_Drain = st.number_input(
        "πŸ”‹ Battery Drain (in percentage)",
        min_value=0.0, step=0.1,
        help="Enter the battery drain percentage (e.g., 15.5%)."
    )
    Number_of_Apps_Installed = st.number_input(
        "πŸ“± Number of Apps Installed",
        min_value=0, step=1,
        help="Enter the total number of apps installed on the device."
    )
    Data_Usage = st.number_input(
        "πŸ“Ά Data Usage (in GB)",
        min_value=0.0, step=0.1,
        help="Enter the total data usage (e.g., 1.5 GB)."
    )

# Load the model
model_path = "./rfc.pkl"  # Adjust if in a subdirectory
try:
    model_2 = joblib.load(model_path)

    # Encode categorical variables
    mapping_device = {'Xiaomi Mi 11': 0, 'iPhone 12': 1, 'Google Pixel 5': 2, 'OnePlus 9': 3, 'Samsung Galaxy S21': 4}
    mapping_os = {'Android': 0, 'iOS': 1}
    mapping_gender = {'Male': 0, 'Female': 1}

    device_model_encoded = mapping_device[Device_Model]
    operating_system_encoded = mapping_os[Operating_System]
    gender_encoded = mapping_gender[gender]

    # Predict and display result
    if st.button("πŸš€ Submit"):
        with st.spinner("Running prediction..."):
            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]])
        st.success("πŸŽ‰ Prediction Completed!")
        st.markdown(f"**πŸ“Š Predicted User Behavior:** `{result[0]}`")

except FileNotFoundError:
    st.error(f"🚨 Model file not found at: `{model_path}`. Please upload the model.")
except Exception as e:
    st.error(f"🚨 An error occurred: {e}")




    
    
# age = st.number_input("Enter age",min_value=0,max_value=1000,step=1,format="%d" )
# gender = st.radio("Enter gender",['Male','Female'])
# chestpain = st.selectbox("chestpain",['non-anginal_pain', 'typical_angina', 'atypical_angina','asymptomatic'])
# restingBP =  st.number_input("Enter BP",min_value=0,max_value=1000,step=1,format="%d")
# serum_cholesterol = st.number_input("Enter serum_cholesterol",min_value=0,max_value=10000,step=1,format="%d")
# fasting_blood_sugar = st.radio("Enter fasting_blood_sugar",['yes','no'])
# restingrelectro= st.selectbox("Enter resting_electro",['ST-T_wave_abnormality', 'normal', 'left_ventricular_hypertrophy'])
# maxheartrate = st.number_input("Enter max_heart_rate",min_value=0,max_value=1000,step=1,format="%d")
# exerciseangia =  st.radio("Enter exercise_angia",['yes','no'])
# oldpeak= st.number_input("Enter oldpeak")
# slope = st.selectbox("Enter slope",['downsloping', 'upsloping', 'flat'])
# noofmajorvessels = st.selectbox("enter number of major vessels",['Three', 'One', 'Zero', 'Two'])