Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,207 @@
|
|
| 1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import numpy as np
|
|
@@ -6,16 +209,21 @@ import pickle
|
|
| 6 |
import sklearn
|
| 7 |
from datasets import load_dataset
|
| 8 |
|
|
|
|
| 9 |
data = pd.read_csv("mldata.csv")
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
# pickleFile = open('rfweights (1).pkl','rb')
|
| 14 |
-
pickelFile=open('dtreeweights.pkl','rb')
|
| 15 |
-
rfmodel = pickle.load(pickelFile)
|
| 16 |
-
|
| 17 |
-
#Obtain the categorical/nominal data because it is not coded according (but based on the first occurence, first come first assign number)
|
| 18 |
-
#Therefore, need to read from the file to obtain the number.
|
| 19 |
categorical_cols = data[[
|
| 20 |
'certifications',
|
| 21 |
'workshops',
|
|
@@ -23,63 +231,35 @@ categorical_cols = data[[
|
|
| 23 |
'interested career area ',
|
| 24 |
'Type of company want to settle in?',
|
| 25 |
'Interested Type of Books'
|
| 26 |
-
|
| 27 |
-
|
|
|
|
| 28 |
for i in categorical_cols:
|
| 29 |
data[i] = data[i].astype('category')
|
| 30 |
data[i] = data[i].cat.codes
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
#embedding for workshops
|
| 38 |
-
workshop_name = list(categorical_cols['workshops'].unique())
|
| 39 |
-
workshop_code = list(data['workshops'].unique())
|
| 40 |
-
workshop_references = dict(zip(workshop_name, workshop_code))
|
| 41 |
-
|
| 42 |
-
#embedding for subjects_interests
|
| 43 |
-
subjects_interest_name = list(categorical_cols['Interested subjects'].unique())
|
| 44 |
-
subjects_interest_code = list(data['Interested subjects'].unique())
|
| 45 |
-
subjects_interest_references = dict(zip(subjects_interest_name, subjects_interest_code))
|
| 46 |
-
|
| 47 |
-
#embedding for career_interests
|
| 48 |
-
career_interest_name = list(categorical_cols['interested career area '].unique())
|
| 49 |
-
career_interest_code = list(data['interested career area '].unique())
|
| 50 |
-
career_interest_references = dict(zip(career_interest_name, career_interest_code))
|
| 51 |
-
|
| 52 |
-
#embedding for company_intends
|
| 53 |
-
company_intends_name = list(categorical_cols['Type of company want to settle in?'].unique())
|
| 54 |
-
company_intends_code = list(data['Type of company want to settle in?'].unique())
|
| 55 |
-
company_intends_references = dict(zip(company_intends_name, company_intends_code))
|
| 56 |
-
|
| 57 |
-
#embedding for book_interests
|
| 58 |
-
book_interest_name = list(categorical_cols['Interested Type of Books'].unique())
|
| 59 |
-
book_interest_code = list(data['Interested Type of Books'].unique())
|
| 60 |
-
book_interest_references = dict(zip(book_interest_name, book_interest_code))
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
def greet(name):
|
| 64 |
-
return f"Hello, {name}!"
|
| 65 |
-
|
| 66 |
-
'''#dummy encode
|
| 67 |
-
def dummy_encode(df):
|
| 68 |
-
if input == "Management":
|
| 69 |
-
return [1, 0]
|
| 70 |
-
elif input == "Technical":
|
| 71 |
-
return [0, 1]
|
| 72 |
-
elif input == "smart worker":
|
| 73 |
-
return [1, 0]
|
| 74 |
-
elif input == "hard worker":
|
| 75 |
-
return [0, 1]
|
| 76 |
-
else:
|
| 77 |
-
return "Invalid choice"'''
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
team_player, management_technical, smart_hardworker):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
df = pd.DataFrame.from_dict(
|
| 84 |
{
|
| 85 |
"logical_thinking": [logical_thinking],
|
|
@@ -108,18 +288,20 @@ def rfprediction(name, logical_thinking, hackathon_attend, coding_skills, public
|
|
| 108 |
}
|
| 109 |
)
|
| 110 |
|
| 111 |
-
#
|
| 112 |
-
df = df.replace({
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
#
|
| 120 |
-
#first we convert into list from df
|
| 121 |
userdata_list = df.values.tolist()
|
| 122 |
-
|
|
|
|
| 123 |
if(df["management_technical"].values == "Management"):
|
| 124 |
userdata_list[0].extend([1])
|
| 125 |
userdata_list[0].extend([0])
|
|
@@ -128,8 +310,10 @@ def rfprediction(name, logical_thinking, hackathon_attend, coding_skills, public
|
|
| 128 |
userdata_list[0].extend([0])
|
| 129 |
userdata_list[0].extend([1])
|
| 130 |
userdata_list[0].remove('Technical')
|
| 131 |
-
else:
|
|
|
|
| 132 |
|
|
|
|
| 133 |
if(df["smart_hardworker"].values == "smart worker"):
|
| 134 |
userdata_list[0].extend([1])
|
| 135 |
userdata_list[0].extend([0])
|
|
@@ -138,30 +322,33 @@ def rfprediction(name, logical_thinking, hackathon_attend, coding_skills, public
|
|
| 138 |
userdata_list[0].extend([0])
|
| 139 |
userdata_list[0].extend([1])
|
| 140 |
userdata_list[0].remove('hard worker')
|
| 141 |
-
else:
|
|
|
|
| 142 |
|
| 143 |
-
|
| 144 |
prediction_result_all = rfmodel.predict_proba(userdata_list)
|
| 145 |
-
|
| 146 |
-
#
|
| 147 |
-
result_list = {
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
| 160 |
return result_list
|
| 161 |
|
|
|
|
| 162 |
cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
|
| 163 |
workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
|
| 164 |
-
skill = ["excellent", "medium", "poor"]
|
| 165 |
subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
|
| 166 |
career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
|
| 167 |
company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
|
|
@@ -169,34 +356,37 @@ book_list = ["Action and Adventure", "Anthology", "Art", "Autobiographies", "Bio
|
|
| 169 |
Choice_list = ["Management", "Technical"]
|
| 170 |
worker_list = ["hard worker", "smart worker"]
|
| 171 |
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
-
#
|
| 201 |
if __name__ == "__main__":
|
| 202 |
demo.launch(share=True)
|
|
|
|
| 1 |
|
| 2 |
+
# import gradio as gr
|
| 3 |
+
# import pandas as pd
|
| 4 |
+
# import numpy as np
|
| 5 |
+
# import pickle
|
| 6 |
+
# import sklearn
|
| 7 |
+
# from datasets import load_dataset
|
| 8 |
+
|
| 9 |
+
# data = pd.read_csv("mldata.csv")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# #load prediction model from notebook
|
| 13 |
+
# # pickleFile = open('rfweights (1).pkl','rb')
|
| 14 |
+
# pickelFile=open('dtreeweights.pkl','rb')
|
| 15 |
+
# rfmodel = pickle.load(pickelFile)
|
| 16 |
+
|
| 17 |
+
# #Obtain the categorical/nominal data because it is not coded according (but based on the first occurence, first come first assign number)
|
| 18 |
+
# #Therefore, need to read from the file to obtain the number.
|
| 19 |
+
# categorical_cols = data[[
|
| 20 |
+
# 'certifications',
|
| 21 |
+
# 'workshops',
|
| 22 |
+
# 'Interested subjects',
|
| 23 |
+
# 'interested career area ',
|
| 24 |
+
# 'Type of company want to settle in?',
|
| 25 |
+
# 'Interested Type of Books'
|
| 26 |
+
# ]]
|
| 27 |
+
# #assign the datatype and automated assigned code
|
| 28 |
+
# for i in categorical_cols:
|
| 29 |
+
# data[i] = data[i].astype('category')
|
| 30 |
+
# data[i] = data[i].cat.codes
|
| 31 |
+
|
| 32 |
+
# #embedded nominal/ categorical values for certicates
|
| 33 |
+
# certificates_name = list(categorical_cols['certifications'].unique())
|
| 34 |
+
# certificates_code = list(data['certifications'].unique())
|
| 35 |
+
# certificates_references = dict(zip(certificates_name,certificates_code))
|
| 36 |
+
|
| 37 |
+
# #embedding for workshops
|
| 38 |
+
# workshop_name = list(categorical_cols['workshops'].unique())
|
| 39 |
+
# workshop_code = list(data['workshops'].unique())
|
| 40 |
+
# workshop_references = dict(zip(workshop_name, workshop_code))
|
| 41 |
+
|
| 42 |
+
# #embedding for subjects_interests
|
| 43 |
+
# subjects_interest_name = list(categorical_cols['Interested subjects'].unique())
|
| 44 |
+
# subjects_interest_code = list(data['Interested subjects'].unique())
|
| 45 |
+
# subjects_interest_references = dict(zip(subjects_interest_name, subjects_interest_code))
|
| 46 |
+
|
| 47 |
+
# #embedding for career_interests
|
| 48 |
+
# career_interest_name = list(categorical_cols['interested career area '].unique())
|
| 49 |
+
# career_interest_code = list(data['interested career area '].unique())
|
| 50 |
+
# career_interest_references = dict(zip(career_interest_name, career_interest_code))
|
| 51 |
+
|
| 52 |
+
# #embedding for company_intends
|
| 53 |
+
# company_intends_name = list(categorical_cols['Type of company want to settle in?'].unique())
|
| 54 |
+
# company_intends_code = list(data['Type of company want to settle in?'].unique())
|
| 55 |
+
# company_intends_references = dict(zip(company_intends_name, company_intends_code))
|
| 56 |
+
|
| 57 |
+
# #embedding for book_interests
|
| 58 |
+
# book_interest_name = list(categorical_cols['Interested Type of Books'].unique())
|
| 59 |
+
# book_interest_code = list(data['Interested Type of Books'].unique())
|
| 60 |
+
# book_interest_references = dict(zip(book_interest_name, book_interest_code))
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# def greet(name):
|
| 64 |
+
# return f"Hello, {name}!"
|
| 65 |
+
|
| 66 |
+
# '''#dummy encode
|
| 67 |
+
# def dummy_encode(df):
|
| 68 |
+
# if input == "Management":
|
| 69 |
+
# return [1, 0]
|
| 70 |
+
# elif input == "Technical":
|
| 71 |
+
# return [0, 1]
|
| 72 |
+
# elif input == "smart worker":
|
| 73 |
+
# return [1, 0]
|
| 74 |
+
# elif input == "hard worker":
|
| 75 |
+
# return [0, 1]
|
| 76 |
+
# else:
|
| 77 |
+
# return "Invalid choice"'''
|
| 78 |
+
|
| 79 |
+
# def rfprediction(name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
|
| 80 |
+
# self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability
|
| 81 |
+
# ,subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
|
| 82 |
+
# team_player, management_technical, smart_hardworker):
|
| 83 |
+
# df = pd.DataFrame.from_dict(
|
| 84 |
+
# {
|
| 85 |
+
# "logical_thinking": [logical_thinking],
|
| 86 |
+
# "hackathon_attend": [hackathon_attend],
|
| 87 |
+
# "coding_skills": [coding_skills],
|
| 88 |
+
# "public_speaking_skills": [public_speaking_skills],
|
| 89 |
+
# "self_learning": [self_learning],
|
| 90 |
+
# "extra_course": [extra_course],
|
| 91 |
+
# "certificate": [certificate_code],
|
| 92 |
+
# "workshop": [worskhop_code],
|
| 93 |
+
# "read_writing_skills": [
|
| 94 |
+
# (0 if "poor" in read_writing_skill else 1 if "medium" in read_writing_skill else 2)
|
| 95 |
+
# ],
|
| 96 |
+
# "memory_capability": [
|
| 97 |
+
# (0 if "poor" in memory_capability else 1 if "medium" in memory_capability else 2)
|
| 98 |
+
# ],
|
| 99 |
+
# "subject_interest": [subject_interest],
|
| 100 |
+
# "career_interest": [career_interest],
|
| 101 |
+
# "company_intend": [company_intend],
|
| 102 |
+
# "senior_elder_advise": [senior_elder_advise],
|
| 103 |
+
# "book_interest": [book_interest],
|
| 104 |
+
# "introvert_extro": [introvert_extro],
|
| 105 |
+
# "team_player": [team_player],
|
| 106 |
+
# "management_technical":[management_technical],
|
| 107 |
+
# "smart_hardworker": [smart_hardworker]
|
| 108 |
+
# }
|
| 109 |
+
# )
|
| 110 |
+
|
| 111 |
+
# #replace str to numeric representation, dtype chged to int8
|
| 112 |
+
# df = df.replace({"certificate": certificates_references,
|
| 113 |
+
# "workshop":workshop_references,
|
| 114 |
+
# "subject_interest":subjects_interest_references,
|
| 115 |
+
# "career_interest": career_interest_references,
|
| 116 |
+
# "company_intend":company_intends_references,
|
| 117 |
+
# "book_interest":book_interest_references})
|
| 118 |
+
|
| 119 |
+
# #dummy encoding
|
| 120 |
+
# #first we convert into list from df
|
| 121 |
+
# userdata_list = df.values.tolist()
|
| 122 |
+
# #now we append boolean based conditions
|
| 123 |
+
# if(df["management_technical"].values == "Management"):
|
| 124 |
+
# userdata_list[0].extend([1])
|
| 125 |
+
# userdata_list[0].extend([0])
|
| 126 |
+
# userdata_list[0].remove('Management')
|
| 127 |
+
# elif(df["management_technical"].values == "Technical"):
|
| 128 |
+
# userdata_list[0].extend([0])
|
| 129 |
+
# userdata_list[0].extend([1])
|
| 130 |
+
# userdata_list[0].remove('Technical')
|
| 131 |
+
# else: return "Err"
|
| 132 |
+
|
| 133 |
+
# if(df["smart_hardworker"].values == "smart worker"):
|
| 134 |
+
# userdata_list[0].extend([1])
|
| 135 |
+
# userdata_list[0].extend([0])
|
| 136 |
+
# userdata_list[0].remove('smart worker')
|
| 137 |
+
# elif(df["smart_hardworker"].values == "hard worker"):
|
| 138 |
+
# userdata_list[0].extend([0])
|
| 139 |
+
# userdata_list[0].extend([1])
|
| 140 |
+
# userdata_list[0].remove('hard worker')
|
| 141 |
+
# else: return "Err"
|
| 142 |
+
|
| 143 |
+
# prediction_result = rfmodel.predict(userdata_list)
|
| 144 |
+
# prediction_result_all = rfmodel.predict_proba(userdata_list)
|
| 145 |
+
# print(prediction_result_all)
|
| 146 |
+
# #create a list for output
|
| 147 |
+
# result_list = {"Applications Developer": float(prediction_result_all[0][0]),
|
| 148 |
+
# "CRM Technical Developer": float(prediction_result_all[0][1]),
|
| 149 |
+
# "Database Developer": float(prediction_result_all[0][2]),
|
| 150 |
+
# "Mobile Applications Developer": float(prediction_result_all[0][3]),
|
| 151 |
+
# "Network Security Engineer": float(prediction_result_all[0][4]),
|
| 152 |
+
# "Software Developer": float(prediction_result_all[0][5]),
|
| 153 |
+
# "Software Engineer": float(prediction_result_all[0][6]),
|
| 154 |
+
# "Software Quality Assurance (QA)/ Testing": float(prediction_result_all[0][7]),
|
| 155 |
+
# "Systems Security Administrator": float(prediction_result_all[0][8]),
|
| 156 |
+
# "Technical Support": float(prediction_result_all[0][9]),
|
| 157 |
+
# "UX Designer": float(prediction_result_all[0][10]),
|
| 158 |
+
# "Web Developer": float(prediction_result_all[0][11]),
|
| 159 |
+
# }
|
| 160 |
+
# return result_list
|
| 161 |
+
|
| 162 |
+
# cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
|
| 163 |
+
# workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
|
| 164 |
+
# skill = ["excellent", "medium", "poor"] #can be used in this section and memory capability section
|
| 165 |
+
# subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
|
| 166 |
+
# career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
|
| 167 |
+
# company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
|
| 168 |
+
# book_list = ["Action and Adventure", "Anthology", "Art", "Autobiographies", "Biographies", "Childrens", "Comics","Cookbooks","Diaries","Dictionaries","Drama","Encyclopedias","Fantasy","Guide","Health","History","Horror","Journals","Math","Mystery","Poetry","Prayer books","Religion-Spirituality","Romance","Satire","Science","Science fiction","Self help","Series","Travel","Trilogy"]
|
| 169 |
+
# Choice_list = ["Management", "Technical"]
|
| 170 |
+
# worker_list = ["hard worker", "smart worker"]
|
| 171 |
+
|
| 172 |
+
# demo =gr.Interface(fn = rfprediction, inputs=[
|
| 173 |
+
# gr.Textbox(placeholder="What is your name?", label="Name"),
|
| 174 |
+
# gr.Slider(minimum=1,maximum=9,value=3,step=1,label="Are you a logical thinking person?", info="Scale: 1 - 9"),
|
| 175 |
+
# gr.Slider(minimum=0,maximum=6,value=0,step=1,label="Do you attend any Hackathons?", info="Scale: 0 - 6 | 0 - if not attended any"),
|
| 176 |
+
# gr.Slider(minimum=1,maximum=9,value=5,step=1,label="How do you rate your coding skills?", info="Scale: 1 - 9"),
|
| 177 |
+
# gr.Slider(minimum=1,maximum=9,value=3,step=1,label="How do you rate your public speaking skills/confidency?", info="Scale: 1 - 9"),
|
| 178 |
+
# gr.Radio({"Yes", "No"}, type="index", label="Are you a self-learning person? *"),
|
| 179 |
+
# gr.Radio({"Yes", "No"}, type="index", label="Do you take extra courses in uni (other than IT)? *"),
|
| 180 |
+
# gr.Dropdown(cert_list, label="Select a certificate you took!"),
|
| 181 |
+
# gr.Dropdown(workshop_list, label="Select a workshop you attended!"),
|
| 182 |
+
# gr.Dropdown(skill, label="Select your read and writing skill"),
|
| 183 |
+
# gr.Dropdown(skill, label="Is your memory capability good?"),
|
| 184 |
+
# gr.Dropdown(subject_list, label="What subject you are interested in?"),
|
| 185 |
+
# gr.Dropdown(career_list, label="Which IT-Career do you have interests in?"),
|
| 186 |
+
# gr.Dropdown(company_list, label="Do you have any interested company that you intend to settle in?"),
|
| 187 |
+
# gr.Radio({"Yes", "No"}, type="index", label="Do you ever seek any advices from senior or elders? *"),
|
| 188 |
+
# gr.Dropdown(book_list, label="Select your interested genre of book!"),
|
| 189 |
+
# gr.Radio({"Yes", "No"}, type="index", label="Are you an Introvert?| No - extrovert *"),
|
| 190 |
+
# gr.Radio({"Yes", "No"}, type="index", label="Ever worked in a team? *"),
|
| 191 |
+
# gr.Dropdown(Choice_list, label="Which area do you prefer: Management or Technical?"),
|
| 192 |
+
# gr.Dropdown(worker_list, label="Are you a Smart worker or Hard worker?")
|
| 193 |
+
# ],
|
| 194 |
+
# outputs=gr.Label(num_top_classes=5),
|
| 195 |
+
# title="IT-Career Recommendation System: TMI4033 Colletive Intelligence, Group 12",
|
| 196 |
+
# description="Members: Derrick Lim Kin Yeap 74597, Jason Jong Sheng Tat 75125, Jason Ng Yong Xing 75127, Muhamad Hazrie Bin Suhkery 73555 "
|
| 197 |
+
# )
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
# #main
|
| 201 |
+
# if __name__ == "__main__":
|
| 202 |
+
# demo.launch(share=True)
|
| 203 |
+
|
| 204 |
+
|
| 205 |
import gradio as gr
|
| 206 |
import pandas as pd
|
| 207 |
import numpy as np
|
|
|
|
| 209 |
import sklearn
|
| 210 |
from datasets import load_dataset
|
| 211 |
|
| 212 |
+
# Read the data
|
| 213 |
data = pd.read_csv("mldata.csv")
|
| 214 |
|
| 215 |
+
# Function to load model based on selection
|
| 216 |
+
def load_model(model_choice):
|
| 217 |
+
if model_choice == "Random Forest":
|
| 218 |
+
with open('rfweights (1).pkl', 'rb') as pickleFile:
|
| 219 |
+
return pickle.load(pickleFile)
|
| 220 |
+
elif model_choice == "Decision Tree":
|
| 221 |
+
with open('dtreeweights.pkl', 'rb') as pickleFile:
|
| 222 |
+
return pickle.load(pickleFile)
|
| 223 |
+
else:
|
| 224 |
+
raise ValueError("Invalid model selection")
|
| 225 |
|
| 226 |
+
# Prepare categorical data (same as original code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
categorical_cols = data[[
|
| 228 |
'certifications',
|
| 229 |
'workshops',
|
|
|
|
| 231 |
'interested career area ',
|
| 232 |
'Type of company want to settle in?',
|
| 233 |
'Interested Type of Books'
|
| 234 |
+
]]
|
| 235 |
+
|
| 236 |
+
# Assign category codes
|
| 237 |
for i in categorical_cols:
|
| 238 |
data[i] = data[i].astype('category')
|
| 239 |
data[i] = data[i].cat.codes
|
| 240 |
|
| 241 |
+
# Create reference dictionaries for embeddings (same as original code)
|
| 242 |
+
def create_embedding_dict(column):
|
| 243 |
+
unique_names = list(categorical_cols[column].unique())
|
| 244 |
+
unique_codes = list(data[column].unique())
|
| 245 |
+
return dict(zip(unique_names, unique_codes))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
+
certificates_references = create_embedding_dict('certifications')
|
| 248 |
+
workshop_references = create_embedding_dict('workshops')
|
| 249 |
+
subjects_interest_references = create_embedding_dict('Interested subjects')
|
| 250 |
+
career_interest_references = create_embedding_dict('interested career area ')
|
| 251 |
+
company_intends_references = create_embedding_dict('Type of company want to settle in?')
|
| 252 |
+
book_interest_references = create_embedding_dict('Interested Type of Books')
|
| 253 |
+
|
| 254 |
+
# Prediction function (modified to accept model choice)
|
| 255 |
+
def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
|
| 256 |
+
self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
|
| 257 |
+
subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
|
| 258 |
team_player, management_technical, smart_hardworker):
|
| 259 |
+
# Load the selected model
|
| 260 |
+
rfmodel = load_model(model_choice)
|
| 261 |
+
|
| 262 |
+
# Create DataFrame (same as original code)
|
| 263 |
df = pd.DataFrame.from_dict(
|
| 264 |
{
|
| 265 |
"logical_thinking": [logical_thinking],
|
|
|
|
| 288 |
}
|
| 289 |
)
|
| 290 |
|
| 291 |
+
# Replace string values with numeric representations
|
| 292 |
+
df = df.replace({
|
| 293 |
+
"certificate": certificates_references,
|
| 294 |
+
"workshop": workshop_references,
|
| 295 |
+
"subject_interest": subjects_interest_references,
|
| 296 |
+
"career_interest": career_interest_references,
|
| 297 |
+
"company_intend": company_intends_references,
|
| 298 |
+
"book_interest": book_interest_references
|
| 299 |
+
})
|
| 300 |
|
| 301 |
+
# Dummy encoding (same as original code)
|
|
|
|
| 302 |
userdata_list = df.values.tolist()
|
| 303 |
+
|
| 304 |
+
# Management-Technical dummy encoding
|
| 305 |
if(df["management_technical"].values == "Management"):
|
| 306 |
userdata_list[0].extend([1])
|
| 307 |
userdata_list[0].extend([0])
|
|
|
|
| 310 |
userdata_list[0].extend([0])
|
| 311 |
userdata_list[0].extend([1])
|
| 312 |
userdata_list[0].remove('Technical')
|
| 313 |
+
else:
|
| 314 |
+
return "Error in Management-Technical encoding"
|
| 315 |
|
| 316 |
+
# Smart-Hard worker dummy encoding
|
| 317 |
if(df["smart_hardworker"].values == "smart worker"):
|
| 318 |
userdata_list[0].extend([1])
|
| 319 |
userdata_list[0].extend([0])
|
|
|
|
| 322 |
userdata_list[0].extend([0])
|
| 323 |
userdata_list[0].extend([1])
|
| 324 |
userdata_list[0].remove('hard worker')
|
| 325 |
+
else:
|
| 326 |
+
return "Error in Smart-Hard worker encoding"
|
| 327 |
|
| 328 |
+
# Prediction
|
| 329 |
prediction_result_all = rfmodel.predict_proba(userdata_list)
|
| 330 |
+
|
| 331 |
+
# Create result dictionary
|
| 332 |
+
result_list = {
|
| 333 |
+
"Applications Developer": float(prediction_result_all[0][0]),
|
| 334 |
+
"CRM Technical Developer": float(prediction_result_all[0][1]),
|
| 335 |
+
"Database Developer": float(prediction_result_all[0][2]),
|
| 336 |
+
"Mobile Applications Developer": float(prediction_result_all[0][3]),
|
| 337 |
+
"Network Security Engineer": float(prediction_result_all[0][4]),
|
| 338 |
+
"Software Developer": float(prediction_result_all[0][5]),
|
| 339 |
+
"Software Engineer": float(prediction_result_all[0][6]),
|
| 340 |
+
"Software Quality Assurance (QA)/ Testing": float(prediction_result_all[0][7]),
|
| 341 |
+
"Systems Security Administrator": float(prediction_result_all[0][8]),
|
| 342 |
+
"Technical Support": float(prediction_result_all[0][9]),
|
| 343 |
+
"UX Designer": float(prediction_result_all[0][10]),
|
| 344 |
+
"Web Developer": float(prediction_result_all[0][11]),
|
| 345 |
+
}
|
| 346 |
return result_list
|
| 347 |
|
| 348 |
+
# Lists for dropdown menus (same as original code)
|
| 349 |
cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
|
| 350 |
workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
|
| 351 |
+
skill = ["excellent", "medium", "poor"]
|
| 352 |
subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
|
| 353 |
career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
|
| 354 |
company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
|
|
|
|
| 356 |
Choice_list = ["Management", "Technical"]
|
| 357 |
worker_list = ["hard worker", "smart worker"]
|
| 358 |
|
| 359 |
+
# Create Gradio interface (modified to include model selection)
|
| 360 |
+
demo = gr.Interface(
|
| 361 |
+
fn=rfprediction,
|
| 362 |
+
inputs=[
|
| 363 |
+
gr.Dropdown(["Random Forest", "Decision Tree"], label="Select Machine Learning Model"),
|
| 364 |
+
gr.Textbox(placeholder="What is your name?", label="Name"),
|
| 365 |
+
gr.Slider(minimum=1, maximum=9, value=3, step=1, label="Are you a logical thinking person?", info="Scale: 1 - 9"),
|
| 366 |
+
gr.Slider(minimum=0, maximum=6, value=0, step=1, label="Do you attend any Hackathons?", info="Scale: 0 - 6 | 0 - if not attended any"),
|
| 367 |
+
gr.Slider(minimum=1, maximum=9, value=5, step=1, label="How do you rate your coding skills?", info="Scale: 1 - 9"),
|
| 368 |
+
gr.Slider(minimum=1, maximum=9, value=3, step=1, label="How do you rate your public speaking skills/confidency?", info="Scale: 1 - 9"),
|
| 369 |
+
gr.Radio({"Yes", "No"}, type="index", label="Are you a self-learning person? *"),
|
| 370 |
+
gr.Radio({"Yes", "No"}, type="index", label="Do you take extra courses in uni (other than IT)? *"),
|
| 371 |
+
gr.Dropdown(cert_list, label="Select a certificate you took!"),
|
| 372 |
+
gr.Dropdown(workshop_list, label="Select a workshop you attended!"),
|
| 373 |
+
gr.Dropdown(skill, label="Select your read and writing skill"),
|
| 374 |
+
gr.Dropdown(skill, label="Is your memory capability good?"),
|
| 375 |
+
gr.Dropdown(subject_list, label="What subject you are interested in?"),
|
| 376 |
+
gr.Dropdown(career_list, label="Which IT-Career do you have interests in?"),
|
| 377 |
+
gr.Dropdown(company_list, label="Do you have any interested company that you intend to settle in?"),
|
| 378 |
+
gr.Radio({"Yes", "No"}, type="index", label="Do you ever seek any advices from senior or elders? *"),
|
| 379 |
+
gr.Dropdown(book_list, label="Select your interested genre of book!"),
|
| 380 |
+
gr.Radio({"Yes", "No"}, type="index", label="Are you an Introvert?| No - extrovert *"),
|
| 381 |
+
gr.Radio({"Yes", "No"}, type="index", label="Ever worked in a team? *"),
|
| 382 |
+
gr.Dropdown(Choice_list, label="Which area do you prefer: Management or Technical?"),
|
| 383 |
+
gr.Dropdown(worker_list, label="Are you a Smart worker or Hard worker?")
|
| 384 |
+
],
|
| 385 |
+
outputs=gr.Label(num_top_classes=5),
|
| 386 |
+
title="IT-Career Recommendation System: TMI4033 Colletive Intelligence, Group 12",
|
| 387 |
+
description="Members: Derrick Lim Kin Yeap 74597, Jason Jong Sheng Tat 75125, Jason Ng Yong Xing 75127, Muhamad Hazrie Bin Suhkery 73555 "
|
| 388 |
+
)
|
| 389 |
|
| 390 |
+
# Main execution
|
| 391 |
if __name__ == "__main__":
|
| 392 |
demo.launch(share=True)
|