Anders-sonderby commited on
Commit
5da9a75
·
verified ·
1 Parent(s): 3901aa6

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import joblib
4
+ import os
5
+
6
+ # Make Streamlit write configs locally instead of root
7
+ os.environ["STREAMLIT_HOME"] = os.path.join(os.getcwd(), ".streamlit")
8
+
9
+ # --- Load the model ---
10
+ script_dir = os.path.dirname(__file__)
11
+ model_path = os.path.join(script_dir, "salary_model.pkl") # your saved model
12
+
13
+ st.title("💼 AI Salary Prediction App")
14
+ st.write("This tool predicts a developer's estimated salary based on their background and experience.")
15
+
16
+ try:
17
+ model_pipeline = joblib.load(model_path)
18
+ st.success("✅ Model loaded successfully!")
19
+ except Exception as e:
20
+ st.error(f"❌ Error loading the model: {e}")
21
+ st.stop()
22
+
23
+ # --- User input section ---
24
+ st.sidebar.header("Input your details")
25
+
26
+ age = st.sidebar.slider("Age", 18, 65, 30)
27
+ years_code_pro = st.sidebar.slider("Years of professional coding experience", 0, 40, 5)
28
+ country = st.sidebar.selectbox("Country", ["Denmark", "Germany", "Croatia", "Portugal", "Italy", "Netherlands"])
29
+ education = st.sidebar.selectbox("Education level", [
30
+ "Bachelor’s degree",
31
+ "Master’s degree (M.A., M.S., M.Eng., MBA, etc.)",
32
+ "Doctoral degree",
33
+ "Less than Bachelor’s"
34
+ ])
35
+ remote = st.sidebar.selectbox("Work arrangement", ["Remote", "Hybrid", "On-site"])
36
+
37
+ # --- Create a DataFrame for prediction ---
38
+ input_data = pd.DataFrame({
39
+ "age_group": [age],
40
+ "years_code_pro": [years_code_pro],
41
+ "country": [country],
42
+ "ed_level": [education],
43
+ "remote_work": [remote]
44
+ })
45
+
46
+ # --- Predict salary ---
47
+ if st.button("Predict Salary"):
48
+ try:
49
+ predicted_salary = model_pipeline.predict(input_data)[0]
50
+ st.subheader(f"💰 Predicted Salary: €{predicted_salary:,.0f}")
51
+ except Exception as e:
52
+ st.error(f"Error making prediction: {e}")
53
+