zaid002 commited on
Commit
9ca5a7b
·
verified ·
1 Parent(s): 461be08

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +54 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,56 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import pandas as pd
3
+ import json
4
+ import numpy as np
5
 
6
+ # Load lightweight JSON model
7
+ light_model = json.load(open("lightweight_model.json"))
8
+ means = light_model["feature_means"]
9
+ stds = light_model["feature_stds"]
10
+
11
+ st.set_page_config(page_title="Employee Attrition Predictor", page_icon="👩‍💼")
12
+
13
+ st.title("👩‍💼 Employee Attrition Prediction (HF-Safe Version)")
14
+ st.write("This version uses a *lightweight*, non-pickle model for safe deployment.")
15
+
16
+ # Input Fields
17
+ age = st.number_input("Age", 18, 60, 30)
18
+ monthly_income = st.number_input("Monthly Income", 1000, 20000, 5000)
19
+ job_satisfaction = st.slider("Job Satisfaction (1–4)", 1, 4, 3)
20
+ work_life_balance = st.slider("Work-Life Balance (1–4)", 1, 4, 3)
21
+ years_at_company = st.number_input("Years at Company", 0, 40, 5)
22
+ overtime = st.selectbox("OverTime", ["Yes", "No"])
23
+
24
+ overtime_value = 1 if overtime == "Yes" else 0
25
+
26
+ # Create DataFrame
27
+ input_data = pd.DataFrame([{
28
+ "Age": age,
29
+ "MonthlyIncome": monthly_income,
30
+ "JobSatisfaction": job_satisfaction,
31
+ "WorkLifeBalance": work_life_balance,
32
+ "YearsAtCompany": years_at_company,
33
+ "OverTime": overtime_value
34
+ }])
35
+
36
+ # Basic logistic-like probability calculation
37
+ def simple_predict(df):
38
+ # Normalize
39
+ for col in df.columns:
40
+ df[col] = (df[col] - means[col]) / (stds[col] + 1e-6)
41
+
42
+ score = df.sum(axis=1).values[0]
43
+
44
+ probability = 1 / (1 + np.exp(-score))
45
+ return probability
46
+
47
+ if st.button("Predict Attrition"):
48
+ prob = simple_predict(input_data)
49
+
50
+ if prob > 0.5:
51
+ st.error(f"⚠️ Employee likely to leave (confidence {prob:.2f})")
52
+ else:
53
+ st.success(f"✅ Employee likely to stay (confidence {1-prob:.2f})")
54
+
55
+ st.markdown("---")
56
+ st.caption("HF-Safe: No pickle, no joblib, lightweight model used.")