Spaces:
Sleeping
Sleeping
File size: 22,287 Bytes
afdad4f 0332e5e 56528d4 5910691 bc71126 637679a 3289837 aad3504 c1db44b 5910691 aad3504 3289837 aad3504 5910691 56528d4 5910691 aad3504 5910691 56528d4 aad3504 5910691 aad3504 56528d4 1ccbd5a 56528d4 1ccbd5a 56528d4 1ccbd5a 56528d4 aad3504 5910691 aad3504 56528d4 5910691 aad3504 5910691 56528d4 5910691 aad3504 5910691 aad3504 5910691 aad3504 5910691 aad3504 5910691 3289837 aad3504 56528d4 3289837 56528d4 5910691 56528d4 5910691 aad3504 5910691 56528d4 1ccbd5a 56528d4 aad3504 3289837 aad3504 56528d4 ee35562 aad3504 5910691 aad3504 5910691 1ccbd5a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# import gradio as gr
# import pandas as pd
# import numpy as np
# import pickle
# import sklearn
# from datasets import load_dataset
# import joblib
# import requests
# # Read the data
# data = pd.read_csv("mldata.csv")
# # Function to load model based on selection
# def load_model(model_choice):
# if model_choice == "Random Forest":
# with open('rfweights (1).pkl', 'rb') as pickleFile:
# return pickle.load(pickleFile)
# elif model_choice == "Decision Tree":
# with open('dtreeweights.pkl', 'rb') as pickleFile:
# return pickle.load(pickleFile)
# else:
# raise ValueError("Invalid model selection")
# # Prepare categorical data (same as original code)
# categorical_cols = data[[
# 'certifications',
# 'workshops',
# 'Interested subjects',
# 'interested career area ',
# 'Type of company want to settle in?',
# 'Interested Type of Books'
# ]]
# # Assign category codes
# for i in categorical_cols:
# data[i] = data[i].astype('category')
# data[i] = data[i].cat.codes
# # Create reference dictionaries for embeddings (same as original code)
# def create_embedding_dict(column):
# unique_names = list(categorical_cols[column].unique())
# unique_codes = list(data[column].unique())
# return dict(zip(unique_names, unique_codes))
# certificates_references = create_embedding_dict('certifications')
# workshop_references = create_embedding_dict('workshops')
# subjects_interest_references = create_embedding_dict('Interested subjects')
# career_interest_references = create_embedding_dict('interested career area ')
# company_intends_references = create_embedding_dict('Type of company want to settle in?')
# book_interest_references = create_embedding_dict('Interested Type of Books')
# # Prediction function (modified to accept model choice)
# def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
# self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
# subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
# team_player, management_technical, smart_hardworker):
# # Load the selected model
# rfmodel = load_model(model_choice)
# # Create DataFrame (same as original code)
# df = pd.DataFrame.from_dict(
# {
# "logical_thinking": [logical_thinking],
# "hackathon_attend": [hackathon_attend],
# "coding_skills": [coding_skills],
# "public_speaking_skills": [public_speaking_skills],
# "self_learning": [self_learning],
# "extra_course": [extra_course],
# "certificate": [certificate_code],
# "workshop": [worskhop_code],
# "read_writing_skills": [
# (0 if "poor" in read_writing_skill else 1 if "medium" in read_writing_skill else 2)
# ],
# "memory_capability": [
# (0 if "poor" in memory_capability else 1 if "medium" in memory_capability else 2)
# ],
# "subject_interest": [subject_interest],
# "career_interest": [career_interest],
# "company_intend": [company_intend],
# "senior_elder_advise": [senior_elder_advise],
# "book_interest": [book_interest],
# "introvert_extro": [introvert_extro],
# "team_player": [team_player],
# "management_technical":[management_technical],
# "smart_hardworker": [smart_hardworker]
# }
# )
# # Replace string values with numeric representations
# df = df.replace({
# "certificate": certificates_references,
# "workshop": workshop_references,
# "subject_interest": subjects_interest_references,
# "career_interest": career_interest_references,
# "company_intend": company_intends_references,
# "book_interest": book_interest_references
# })
# # Dummy encoding (same as original code)
# userdata_list = df.values.tolist()
# # Management-Technical dummy encoding
# if(df["management_technical"].values == "Management"):
# userdata_list[0].extend([1])
# userdata_list[0].extend([0])
# userdata_list[0].remove('Management')
# elif(df["management_technical"].values == "Technical"):
# userdata_list[0].extend([0])
# userdata_list[0].extend([1])
# userdata_list[0].remove('Technical')
# else:
# return "Error in Management-Technical encoding"
# # Smart-Hard worker dummy encoding
# if(df["smart_hardworker"].values == "smart worker"):
# userdata_list[0].extend([1])
# userdata_list[0].extend([0])
# userdata_list[0].remove('smart worker')
# elif(df["smart_hardworker"].values == "hard worker"):
# userdata_list[0].extend([0])
# userdata_list[0].extend([1])
# userdata_list[0].remove('hard worker')
# else:
# return "Error in Smart-Hard worker encoding"
# # Prediction
# prediction_result_all = rfmodel.predict_proba(userdata_list)
# # Create result dictionary
# result_list = {
# "Applications Developer": float(prediction_result_all[0][0]),
# "CRM Technical Developer": float(prediction_result_all[0][1]),
# "Database Developer": float(prediction_result_all[0][2]),
# "Mobile Applications Developer": float(prediction_result_all[0][3]),
# "Network Security Engineer": float(prediction_result_all[0][4]),
# "Software Developer": float(prediction_result_all[0][5]),
# "Software Engineer": float(prediction_result_all[0][6]),
# "Software Quality Assurance (QA)/ Testing": float(prediction_result_all[0][7]),
# "Systems Security Administrator": float(prediction_result_all[0][8]),
# "Technical Support": float(prediction_result_all[0][9]),
# "UX Designer": float(prediction_result_all[0][10]),
# "Web Developer": float(prediction_result_all[0][11]),
# }
# return result_list
# # Lists for dropdown menus (same as original code)
# cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
# workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
# skill = ["excellent", "medium", "poor"]
# subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
# career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
# company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
# 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"]
# Choice_list = ["Management", "Technical"]
# worker_list = ["hard worker", "smart worker"]
# # Create Gradio interface (modified to include model selection)
# demo = gr.Interface(
# fn=rfprediction,
# inputs=[
# gr.Dropdown(["Random Forest", "Decision Tree"], label="Select Machine Learning Model"),
# gr.Textbox(placeholder="What is your name?", label="Name"),
# gr.Slider(minimum=1, maximum=9, value=3, step=1, label="Are you a logical thinking person?", info="Scale: 1 - 9"),
# 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"),
# gr.Slider(minimum=1, maximum=9, value=5, step=1, label="How do you rate your coding skills?", info="Scale: 1 - 9"),
# gr.Slider(minimum=1, maximum=9, value=3, step=1, label="How do you rate your public speaking skills/confidency?", info="Scale: 1 - 9"),
# gr.Radio({"Yes", "No"}, type="index", label="Are you a self-learning person? *"),
# gr.Radio({"Yes", "No"}, type="index", label="Do you take extra courses in uni (other than IT)? *"),
# gr.Dropdown(cert_list, label="Select a certificate you took!"),
# gr.Dropdown(workshop_list, label="Select a workshop you attended!"),
# gr.Dropdown(skill, label="Select your read and writing skill"),
# gr.Dropdown(skill, label="Is your memory capability good?"),
# gr.Dropdown(subject_list, label="What subject you are interested in?"),
# gr.Dropdown(career_list, label="Which IT-Career do you have interests in?"),
# gr.Dropdown(company_list, label="Do you have any interested company that you intend to settle in?"),
# gr.Radio({"Yes", "No"}, type="index", label="Do you ever seek any advices from senior or elders? *"),
# gr.Dropdown(book_list, label="Select your interested genre of book!"),
# gr.Radio({"Yes", "No"}, type="index", label="Are you an Introvert?| No - extrovert *"),
# gr.Radio({"Yes", "No"}, type="index", label="Ever worked in a team? *"),
# gr.Dropdown(Choice_list, label="Which area do you prefer: Management or Technical?"),
# gr.Dropdown(worker_list, label="Are you a Smart worker or Hard worker?")
# ],
# outputs=gr.Label(num_top_classes=5),
# title="IT-Career Recommendation System: TMI4033 Colletive Intelligence, Group 12",
# description="Members: Derrick Lim Kin Yeap 74597, Jason Jong Sheng Tat 75125, Jason Ng Yong Xing 75127, Muhamad Hazrie Bin Suhkery 73555 "
# )
# url = "https://jobs-api14.p.rapidapi.com/v2/list"
# querystring = {
# "query":"Web Developer",
# "location":"India",
# "autoTranslateLocation":"false",
# "remoteOnly":"false",
# "employmentTypes":"fulltime;parttime;intern;contractor"
# }
# headers = {
# "x-rapidapi-key": "714f5a2539msh798d996c3243876p19c71ajsnfcd7ce481cb9",
# "x-rapidapi-host": "jobs-api14.p.rapidapi.com"
# }
# # Main execution
# if __name__ == "__main__":
# # Fetch job listings before launching the app
# try:
# response = requests.get(url, headers=headers, params=querystring)
# job_listings = response.json()
# print("Job Listings Retrieved Successfully")
# # You could potentially store or process job_listings here
# except requests.RequestException as e:
# print(f"Error fetching job listings: {e}")
# demo.launch(share=True)
import gradio as gr
import pandas as pd
import numpy as np
import pickle
import sklearn
from datasets import load_dataset
import joblib
import requests
# Read the data
data = pd.read_csv("mldata.csv")
# Function to load model based on selection
def load_model(model_choice):
if model_choice == "Random Forest":
with open('rfweights (1).pkl', 'rb') as pickleFile:
return pickle.load(pickleFile)
elif model_choice == "Decision Tree":
with open('dtreeweights.pkl', 'rb') as pickleFile:
return pickle.load(pickleFile)
else:
raise ValueError("Invalid model selection")
# Prepare categorical data
categorical_cols = data[[
'certifications',
'workshops',
'Interested subjects',
'interested career area ',
'Type of company want to settle in?',
'Interested Type of Books'
]]
# Assign category codes
for i in categorical_cols:
data[i] = data[i].astype('category')
data[i] = data[i].cat.codes
# Create reference dictionaries for embeddings
def create_embedding_dict(column):
unique_names = list(categorical_cols[column].unique())
unique_codes = list(data[column].unique())
return dict(zip(unique_names, unique_codes))
certificates_references = create_embedding_dict('certifications')
workshop_references = create_embedding_dict('workshops')
subjects_interest_references = create_embedding_dict('Interested subjects')
career_interest_references = create_embedding_dict('interested career area ')
company_intends_references = create_embedding_dict('Type of company want to settle in?')
book_interest_references = create_embedding_dict('Interested Type of Books')
# Function to fetch job listings
def fetch_job_listings(job_title):
url = "https://jobs-api14.p.rapidapi.com/v2/list"
querystring = {
"query": job_title,
"location": "India",
"autoTranslateLocation": "false",
"remoteOnly": "false",
"employmentTypes": "fulltime;parttime;intern;contractor"
}
headers = {
"x-rapidapi-key": "714f5a2539msh798d996c3243876p19c71ajsnfcd7ce481cb9",
"x-rapidapi-host": "jobs-api14.p.rapidapi.com"
}
try:
response = requests.get(url, headers=headers, params=querystring)
job_data = response.json()
# Process and format job listings
if job_data.get('jobs'):
job_listings = []
for job in job_data['jobs'][:5]: # Limit to 5 job listings
job_listings.append([
job.get('title', 'N/A'),
job.get('company', 'N/A'),
job.get('location', 'N/A'),
job.get('salary', 'Not specified')
])
return job_listings
else:
return [['No job listings', 'found', 'for this', 'career path']]
except requests.RequestException as e:
return [['Error', 'fetching', 'job listings', str(e)]]
# Prediction function (modified to return job suggestions)
def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
team_player, management_technical, smart_hardworker):
# Load the selected model
rfmodel = load_model(model_choice)
# Create DataFrame
df = pd.DataFrame.from_dict(
{
"logical_thinking": [logical_thinking],
"hackathon_attend": [hackathon_attend],
"coding_skills": [coding_skills],
"public_speaking_skills": [public_speaking_skills],
"self_learning": [self_learning],
"extra_course": [extra_course],
"certificate": [certificate_code],
"workshop": [worskhop_code],
"read_writing_skills": [
(0 if "poor" in read_writing_skill else 1 if "medium" in read_writing_skill else 2)
],
"memory_capability": [
(0 if "poor" in memory_capability else 1 if "medium" in memory_capability else 2)
],
"subject_interest": [subject_interest],
"career_interest": [career_interest],
"company_intend": [company_intend],
"senior_elder_advise": [senior_elder_advise],
"book_interest": [book_interest],
"introvert_extro": [introvert_extro],
"team_player": [team_player],
"management_technical":[management_technical],
"smart_hardworker": [smart_hardworker]
}
)
# Replace string values with numeric representations
df = df.replace({
"certificate": certificates_references,
"workshop": workshop_references,
"subject_interest": subjects_interest_references,
"career_interest": career_interest_references,
"company_intend": company_intends_references,
"book_interest": book_interest_references
})
# Dummy encoding
userdata_list = df.values.tolist()
# Management-Technical dummy encoding
if(df["management_technical"].values == "Management"):
userdata_list[0].extend([1])
userdata_list[0].extend([0])
userdata_list[0].remove('Management')
elif(df["management_technical"].values == "Technical"):
userdata_list[0].extend([0])
userdata_list[0].extend([1])
userdata_list[0].remove('Technical')
else:
return "Error in Management-Technical encoding"
# Smart-Hard worker dummy encoding
if(df["smart_hardworker"].values == "smart worker"):
userdata_list[0].extend([1])
userdata_list[0].extend([0])
userdata_list[0].remove('smart worker')
elif(df["smart_hardworker"].values == "hard worker"):
userdata_list[0].extend([0])
userdata_list[0].extend([1])
userdata_list[0].remove('hard worker')
else:
return "Error in Smart-Hard worker encoding"
# Prediction
prediction_result_all = rfmodel.predict_proba(userdata_list)
# Create result dictionary with probabilities
result_list = {
"Applications Developer": float(prediction_result_all[0][0]),
"CRM Technical Developer": float(prediction_result_all[0][1]),
"Database Developer": float(prediction_result_all[0][2]),
"Mobile Applications Developer": float(prediction_result_all[0][3]),
"Network Security Engineer": float(prediction_result_all[0][4]),
"Software Developer": float(prediction_result_all[0][5]),
"Software Engineer": float(prediction_result_all[0][6]),
"Software Quality Assurance (QA)/ Testing": float(prediction_result_all[0][7]),
"Systems Security Administrator": float(prediction_result_all[0][8]),
"Technical Support": float(prediction_result_all[0][9]),
"UX Designer": float(prediction_result_all[0][10]),
"Web Developer": float(prediction_result_all[0][11]),
}
# Find the top predicted career
top_career = max(result_list, key=result_list.get)
# Fetch job listings for the top predicted career
job_suggestions = fetch_job_listings(top_career)
return result_list, job_suggestions
# Lists for dropdown menus
cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
skill = ["excellent", "medium", "poor"]
subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
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"]
Choice_list = ["Management", "Technical"]
worker_list = ["hard worker", "smart worker"]
# Create Gradio interface
def create_output_component():
return [
gr.Label(label="Career Probabilities"),
gr.Dataframe(
headers=["Job Title", "Company", "Location", "Salary"],
label="Job Suggestions"
)
]
demo = gr.Interface(
fn=rfprediction,
inputs=[
gr.Dropdown(["Random Forest", "Decision Tree"], label="Select Machine Learning Model"),
gr.Textbox(placeholder="What is your name?", label="Name"),
gr.Slider(minimum=1, maximum=9, value=3, step=1, label="Are you a logical thinking person?", info="Scale: 1 - 9"),
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"),
gr.Slider(minimum=1, maximum=9, value=5, step=1, label="How do you rate your coding skills?", info="Scale: 1 - 9"),
gr.Slider(minimum=1, maximum=9, value=3, step=1, label="How do you rate your public speaking skills/confidency?", info="Scale: 1 - 9"),
gr.Radio({"Yes", "No"}, type="index", label="Are you a self-learning person? *"),
gr.Radio({"Yes", "No"}, type="index", label="Do you take extra courses in uni (other than IT)? *"),
gr.Dropdown(cert_list, label="Select a certificate you took!"),
gr.Dropdown(workshop_list, label="Select a workshop you attended!"),
gr.Dropdown(skill, label="Select your read and writing skill"),
gr.Dropdown(skill, label="Is your memory capability good?"),
gr.Dropdown(subject_list, label="What subject you are interested in?"),
gr.Dropdown(career_list, label="Which IT-Career do you have interests in?"),
gr.Dropdown(company_list, label="Do you have any interested company that you intend to settle in?"),
gr.Radio({"Yes", "No"}, type="index", label="Do you ever seek any advices from senior or elders? *"),
gr.Dropdown(book_list, label="Select your interested genre of book!"),
gr.Radio({"Yes", "No"}, type="index", label="Are you an Introvert?| No - extrovert *"),
gr.Radio({"Yes", "No"}, type="index", label="Ever worked in a team? *"),
gr.Dropdown(Choice_list, label="Which area do you prefer: Management or Technical?"),
gr.Dropdown(worker_list, label="Are you a Smart worker or Hard worker?")
],
outputs=create_output_component(),
title="AI-Enhanced Career guidance System",
)
# Main execution
if __name__ == "__main__":
demo.launch(share=True) |