Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +61 -0
- requirements.txt +3 -0
- salary_model.joblib +3 -0
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn.linear_model import LinearRegression
|
4 |
+
from sklearn.model_selection import train_test_split
|
5 |
+
from sklearn.metrics import mean_squared_error
|
6 |
+
import joblib
|
7 |
+
|
8 |
+
# Mock dataset
|
9 |
+
data = {
|
10 |
+
'age': [25, 32, 47, 51, 29, 45, 35, 33, 29, 24],
|
11 |
+
'education_level': [16, 18, 20, 21, 16, 18, 17, 16, 16, 15],
|
12 |
+
'experience': [1, 6, 20, 25, 3, 15, 8, 4, 2, 1],
|
13 |
+
'salary': [30000, 50000, 120000, 140000, 35000, 110000, 60000, 52000, 40000, 32000]
|
14 |
+
}
|
15 |
+
df = pd.DataFrame(data)
|
16 |
+
|
17 |
+
# Split dataset
|
18 |
+
X = df[['age', 'education_level', 'experience']]
|
19 |
+
y = df['salary']
|
20 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
21 |
+
|
22 |
+
# Train model
|
23 |
+
model = LinearRegression()
|
24 |
+
model.fit(X_train, y_train)
|
25 |
+
|
26 |
+
# Evaluate model
|
27 |
+
y_pred = model.predict(X_test)
|
28 |
+
mse = mean_squared_error(y_test, y_pred)
|
29 |
+
print(f"Model MSE: {mse}")
|
30 |
+
|
31 |
+
# Save model
|
32 |
+
joblib.dump(model, 'salary_model.joblib')
|
33 |
+
|
34 |
+
|
35 |
+
import gradio as gr
|
36 |
+
import joblib
|
37 |
+
|
38 |
+
# Load the trained model
|
39 |
+
model = joblib.load('salary_model.joblib')
|
40 |
+
|
41 |
+
# Define prediction function
|
42 |
+
def predict_salary(age, education_level, experience):
|
43 |
+
input_data = [[age, education_level, experience]]
|
44 |
+
prediction = model.predict(input_data)
|
45 |
+
return f"Predicted Salary: ${prediction[0]:.2f}"
|
46 |
+
|
47 |
+
# Create Gradio interface
|
48 |
+
demo = gr.Interface(
|
49 |
+
fn=predict_salary,
|
50 |
+
inputs=[
|
51 |
+
gr.Number(label="Age"),
|
52 |
+
gr.Number(label="Education Level (years)"),
|
53 |
+
gr.Number(label="Experience (years)")
|
54 |
+
],
|
55 |
+
outputs="text",
|
56 |
+
title="Salary Prediction Model",
|
57 |
+
description="Predict salary based on age, education level, and years of experience."
|
58 |
+
)
|
59 |
+
|
60 |
+
# Launch the Gradio app
|
61 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
scikit-learn
|
3 |
+
joblib
|
salary_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6c850ebd628e432cac3fb9007130839457d13b5e284c77118ff69d73dd67c95d
|
3 |
+
size 928
|