-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (58 loc) · 2.29 KB
/
Copy pathapp.py
File metadata and controls
73 lines (58 loc) · 2.29 KB
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
import streamlit as st
import numpy as np
import joblib
# Load saved model + scaler
model = joblib.load(r"F:\Smart_Phone_ Addiction\smartphone_model.pkl")
scaler = joblib.load(r"F:\Smart_Phone_ Addiction\scaler.pkl")
st.set_page_config(page_title="Smartphone Addiction Predictor", layout="centered")
st.title("📱 Smartphone Addiction Predictor")
st.write("Enter user behavior details to predict addiction level.")
# User Inputs
age = st.slider("Age", 10, 60, 25)
gender = st.selectbox("Gender", ["Male", "Female"])
daily_screen_time = st.slider("Daily Screen Time (hours)", 0.0, 15.0, 5.0)
social_media = st.slider("Social Media Hours", 0.0, 10.0, 2.0)
gaming = st.slider("Gaming Hours", 0.0, 10.0, 1.0)
work_study = st.slider("Work/Study Hours", 0.0, 12.0, 4.0)
sleep = st.slider("Sleep Hours", 0.0, 12.0, 7.0)
notifications = st.slider("Notifications per Day", 0, 300, 50)
app_opens = st.slider("App Opens per Day", 0, 300, 40)
weekend_screen = st.slider("Weekend Screen Time", 0.0, 20.0, 6.0)
stress = st.selectbox("Stress Level", ["Low", "Medium", "High"])
impact = st.selectbox("Academic/Work Impact", ["Low", "Medium", "High"])
addiction_level = st.selectbox("Self-Reported Addiction Level", ["Low", "Medium", "High"])
# Encoding
def encode_inputs():
gender_val = 1 if gender == "Male" else 0
stress_val = {"Low": 0, "Medium": 1, "High": 2}[stress]
impact_val = {"Low": 0, "Medium": 1, "High": 2}[impact]
addiction_val = {"Low": 0, "Medium": 1, "High": 2}[addiction_level]
total_usage = social_media + gaming + work_study
sleep_deficit = 8 - sleep
features = np.array([[
age,
gender_val,
daily_screen_time,
social_media,
gaming,
work_study,
sleep,
notifications,
app_opens,
weekend_screen,
stress_val,
impact_val,
addiction_val,
total_usage,
sleep_deficit
]])
return features
# Prediction
if st.button("Predict"):
input_data = encode_inputs()
input_scaled = scaler.transform(input_data)
prediction = model.predict(input_scaled)[0]
if prediction == 1:
st.error(" High Risk of Smartphone Addiction")
else:
st.success(" Low Risk of Smartphone Addiction")