QuratUlAin-ai11 commited on
Commit
eb0e1c4
·
verified ·
1 Parent(s): 9be9a0d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -0
app.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ import gradio as gr
4
+ import numpy as np
5
+ import sklearn
6
+
7
+ model = joblib.load("salary_prediction_model.pkl")
8
+
9
+ def predict_salary_category(work_year, experience_level, company_size, employment_type, employee_residence, company_location, job_title, country, remote_ratio):
10
+ # Create a DataFrame for the new input data
11
+ input_data = pd.DataFrame({
12
+ 'work_year': [work_year],
13
+ 'experience_level': [experience_level],
14
+ 'company_size': [company_size],
15
+ 'employment_type': [employment_type],
16
+ 'employee_residence': [employee_residence],
17
+ 'company_location': [company_location],
18
+ 'job_title': [job_title],
19
+ 'country': [country],
20
+ 'remote_ratio': [remote_ratio]
21
+ })
22
+
23
+ # Make predictions using the loaded model
24
+ prediction = model.predict(input_data)
25
+
26
+ # Map the encoded prediction back to the salary label
27
+ salary_labels = ['Low', 'Medium-Low', 'High']
28
+ return salary_labels[prediction[0]]
29
+
30
+
31
+
32
+ # Define Gradio inputs and outputs
33
+ inputs = [
34
+ gr.Number(label="Work Year", value=2024),
35
+ gr.Dropdown(['EN', 'MI', 'SE', 'EX'], label="Experience Level", value='MI'), # Default value must be in the options
36
+ gr.Dropdown(['S', 'M', 'L'], label="Company Size", value='M'),
37
+ gr.Dropdown(['FT', 'PT', 'CT', 'FL'], label="Employment Type", value='FT'),
38
+ gr.Textbox(label="Employee Residence", value=''),
39
+ gr.Textbox(label="Company Location", value=''),
40
+ gr.Textbox(label="Job Title", value=''),
41
+ gr.Textbox(label="Country", value=''),
42
+ gr.Number(label="Remote Ratio", value=0)
43
+ ]
44
+
45
+ output = gr.Textbox(label="Predicted Salary Category")
46
+
47
+ # Create the Gradio interface using the loaded model
48
+ interface = gr.Interface(
49
+ fn=predict_salary_category,
50
+ inputs=inputs,
51
+ outputs=output,
52
+ title="KNN Salary Category Predictor",
53
+ description="Enter details to predict the salary category (Low, Medium-Low, High) based on job and company information."
54
+ )
55
+
56
+ # Launch the Gradio interface
57
+ interface.launch(debug=True)