poudel commited on
Commit
5bde516
·
verified ·
1 Parent(s): 3b72cf2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
+ from huggingface_hub import hf_hub_download
6
+
7
+ # Download the model from Hugging Face hub
8
+ model_filename = hf_hub_download(repo_id="poudel/Job_Predictor", filename="random_forest_pipeline.pkl")
9
+
10
+ # Load the model
11
+ loaded_model = joblib.load(model_filename)
12
+
13
+ # Download the dataset from Hugging Face hub
14
+ data_filename = hf_hub_download(repo_id="poudel/Job_Predictor", filename="cleaned_erecruit_open_data.xlsx")
15
+
16
+ # Load the dataset
17
+ data = pd.read_excel(data_filename)
18
+
19
+ # Get unique values for dropdowns
20
+ position_titles = data['PositionTitle'].unique().tolist()
21
+ designations = data['Designation'].unique().tolist()
22
+ agencies = data['Agency'].unique().tolist()
23
+ vacancy_types = data['VacancyType'].unique().tolist()
24
+ employment_categories = data['EmploymentCategory'].unique().tolist()
25
+ locations = data['Locations'].unique().tolist()
26
+ vacancy_6_months_or_less = data['Vacancy6MonthsOrLess'].unique().tolist()
27
+
28
+ # Define a function to make predictions based on user input
29
+ def predict_applicants(position_title, designation, agency, vacancy_type, employment_category, location, vacancy_6_months_or_less, number_of_vacancies, number_of_successful_applicants):
30
+ # Create a DataFrame from the inputs
31
+ input_data = pd.DataFrame({
32
+ 'PositionTitle': [position_title],
33
+ 'Designation': [designation],
34
+ 'Agency': [agency],
35
+ 'VacancyType': [vacancy_type],
36
+ 'EmploymentCategory': [employment_category],
37
+ 'Locations': [location],
38
+ 'Vacancy6MonthsOrLess': [vacancy_6_months_or_less],
39
+ 'NumberOfSuccessfulApplicants': [number_of_successful_applicants],
40
+ 'NumberOfVacancies': [number_of_vacancies]
41
+ })
42
+
43
+ # Calculate additional features
44
+ input_data['Success_Ratio'] = input_data['NumberOfSuccessfulApplicants'] / input_data['NumberOfVacancies'].replace(0, np.nan)
45
+ input_data['Applicants_per_Vacancy'] = input_data['NumberOfVacancies'] / np.where(input_data['NumberOfSuccessfulApplicants'] == 0, np.nan, input_data['NumberOfSuccessfulApplicants'])
46
+ input_data['Success_Ratio'].fillna(0, inplace=True)
47
+ input_data['Applicants_per_Vacancy'].fillna(0, inplace=True)
48
+
49
+ # Make predictions using the loaded model pipeline
50
+ try:
51
+ prediction = loaded_model.predict(input_data)
52
+ return f"Predicted Number of Applicants: {int(prediction[0])}"
53
+ except Exception as e:
54
+ return f"Error during prediction: {str(e)}"
55
+
56
+ # Create the Gradio Blocks Interface
57
+ with gr.Blocks() as interface:
58
+ # Add a title and description
59
+ gr.Markdown("# NT's Job Predictor")
60
+ gr.Markdown("Select the job details below to predict the number of applicants for a given position.")
61
+
62
+ with gr.Row():
63
+ position_title_input = gr.Dropdown(choices=position_titles, label="Position Title", value=None)
64
+ designation_input = gr.Dropdown(choices=designations, label="Designation", value=None)
65
+ agency_input = gr.Dropdown(choices=agencies, label="Agency", value=None)
66
+
67
+ with gr.Row():
68
+ vacancy_type_input = gr.Dropdown(choices=vacancy_types, label="Vacancy Type", value=None)
69
+ employment_category_input = gr.Dropdown(choices=employment_categories, label="Employment Category", value=None)
70
+ location_input = gr.Dropdown(choices=locations, label="Locations", value=None)
71
+ vacancy_6_months_or_less_input = gr.Dropdown(choices=vacancy_6_months_or_less, label="Vacancy 6 Months or Less", value=None)
72
+
73
+ with gr.Row():
74
+ number_of_vacancies_input = gr.Number(label="Past Number of Vacancies", value=None)
75
+ number_of_successful_applicants_input = gr.Number(label="Past Number of Successful Applicants", value=None)
76
+
77
+ predict_button = gr.Button("Predict")
78
+
79
+ predicted_applicants_output = gr.Textbox(label="Predicted Number of Applicants")
80
+
81
+ predict_button.click(
82
+ fn=predict_applicants,
83
+ inputs=[
84
+ position_title_input,
85
+ designation_input,
86
+ agency_input,
87
+ vacancy_type_input,
88
+ employment_category_input,
89
+ location_input,
90
+ vacancy_6_months_or_less_input,
91
+ number_of_vacancies_input,
92
+ number_of_successful_applicants_input
93
+ ],
94
+ outputs=predicted_applicants_output
95
+ )
96
+
97
+ interface.launch()