Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +62 -0
- emp.csv +0 -0
- prep.pkl +3 -0
- requirements.txt +6 -0
- rid.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle as pkl
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
# Load saved model & preprocessor
|
| 6 |
+
model = pkl.load(open("rid.pkl", "rb"))
|
| 7 |
+
preprocessor = pkl.load(open("prep.pkl", "rb"))
|
| 8 |
+
|
| 9 |
+
# Define prediction function
|
| 10 |
+
def predict_salary(name, age, gender, department, job_title, experience_years, education_level, location):
|
| 11 |
+
# Build input dataframe (same schema as training)
|
| 12 |
+
input_df = pd.DataFrame([{
|
| 13 |
+
"Name": name,
|
| 14 |
+
"Age": int(age),
|
| 15 |
+
"Gender": gender,
|
| 16 |
+
"Department": department,
|
| 17 |
+
"Job_Title": job_title,
|
| 18 |
+
"Experience_Years": int(experience_years),
|
| 19 |
+
"Education_Level": education_level,
|
| 20 |
+
"Location": location
|
| 21 |
+
}])
|
| 22 |
+
|
| 23 |
+
# Apply preprocessing
|
| 24 |
+
processed = preprocessor.transform(input_df)
|
| 25 |
+
|
| 26 |
+
# Predict salary
|
| 27 |
+
prediction = model.predict(processed)[0]
|
| 28 |
+
return f"💰 Predicted Salary: {round(prediction, 2)}"
|
| 29 |
+
|
| 30 |
+
# Define Gradio interface
|
| 31 |
+
with gr.Blocks() as demo:
|
| 32 |
+
gr.Markdown("# 🏢 Employer Salary Prediction App")
|
| 33 |
+
gr.Markdown("Fill in the employee details and get the predicted salary.")
|
| 34 |
+
|
| 35 |
+
with gr.Row():
|
| 36 |
+
with gr.Column():
|
| 37 |
+
name = gr.Textbox(label="Name", placeholder="Enter employee name")
|
| 38 |
+
age = gr.Number(label="Age", value=25)
|
| 39 |
+
gender = gr.Dropdown(choices=["Male", "Female", "Other"], label="Gender")
|
| 40 |
+
department = gr.Textbox(label="Department", placeholder="e.g. HR, IT, Finance")
|
| 41 |
+
job_title = gr.Textbox(label="Job Title", placeholder="e.g. Data Scientist")
|
| 42 |
+
experience = gr.Number(label="Experience (Years)", value=1)
|
| 43 |
+
education = gr.Dropdown(
|
| 44 |
+
choices=["High School", "Bachelors", "Masters", "PhD"],
|
| 45 |
+
label="Education Level"
|
| 46 |
+
)
|
| 47 |
+
location = gr.Textbox(label="Location", placeholder="Enter city")
|
| 48 |
+
|
| 49 |
+
submit_btn = gr.Button("🔮 Predict Salary")
|
| 50 |
+
|
| 51 |
+
with gr.Column():
|
| 52 |
+
output = gr.Textbox(label="Prediction")
|
| 53 |
+
|
| 54 |
+
submit_btn.click(
|
| 55 |
+
fn=predict_salary,
|
| 56 |
+
inputs=[name, age, gender, department, job_title, experience, education, location],
|
| 57 |
+
outputs=output
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Run the app
|
| 61 |
+
if __name__ == "__main__":
|
| 62 |
+
demo.launch()
|
emp.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
prep.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9cd2eb5e08d6445a800c16f0a2c5cde852725006827d2304634a0378903bb29c
|
| 3 |
+
size 4004
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
numpy
|
| 3 |
+
scikit-learn
|
| 4 |
+
gradio
|
| 5 |
+
xgboost
|
| 6 |
+
imbalanced-learn
|
rid.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a98e94be0d7503daff615467e901ed3d81868998e1711847279dc578f3beeabb
|
| 3 |
+
size 4415
|