ArchiMathur commited on
Commit
21ce756
·
verified ·
1 Parent(s): 516c73e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -224
app.py CHANGED
@@ -1,201 +1,11 @@
1
 
2
 
3
 
4
- # import gradio as gr
5
- # import pandas as pd
6
- # import numpy as np
7
- # import pickle
8
- # import sklearn
9
- # from datasets import load_dataset
10
-
11
- # # Read the data
12
- # data = pd.read_csv("mldata.csv")
13
-
14
- # # Function to load model based on selection
15
- # def load_model(model_choice):
16
- # if model_choice == "Random Forest":
17
- # with open('rfweights (1).pkl', 'rb') as pickleFile:
18
- # return pickle.load(pickleFile)
19
- # elif model_choice == "Decision Tree":
20
- # with open('dtreeweights.pkl', 'rb') as pickleFile:
21
- # return pickle.load(pickleFile)
22
- # else:
23
- # raise ValueError("Invalid model selection")
24
-
25
- # # Prepare categorical data (same as original code)
26
- # categorical_cols = data[[
27
- # 'certifications',
28
- # 'workshops',
29
- # 'Interested subjects',
30
- # 'interested career area ',
31
- # 'Type of company want to settle in?',
32
- # 'Interested Type of Books'
33
- # ]]
34
-
35
- # # Assign category codes
36
- # for i in categorical_cols:
37
- # data[i] = data[i].astype('category')
38
- # data[i] = data[i].cat.codes
39
-
40
- # # Create reference dictionaries for embeddings (same as original code)
41
- # def create_embedding_dict(column):
42
- # unique_names = list(categorical_cols[column].unique())
43
- # unique_codes = list(data[column].unique())
44
- # return dict(zip(unique_names, unique_codes))
45
-
46
- # certificates_references = create_embedding_dict('certifications')
47
- # workshop_references = create_embedding_dict('workshops')
48
- # subjects_interest_references = create_embedding_dict('Interested subjects')
49
- # career_interest_references = create_embedding_dict('interested career area ')
50
- # company_intends_references = create_embedding_dict('Type of company want to settle in?')
51
- # book_interest_references = create_embedding_dict('Interested Type of Books')
52
-
53
- # # Prediction function (modified to accept model choice)
54
- # def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
55
- # self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
56
- # subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
57
- # team_player, management_technical, smart_hardworker):
58
- # # Load the selected model
59
- # rfmodel = load_model(model_choice)
60
-
61
- # # Create DataFrame (same as original code)
62
- # df = pd.DataFrame.from_dict(
63
- # {
64
- # "logical_thinking": [logical_thinking],
65
- # "hackathon_attend": [hackathon_attend],
66
- # "coding_skills": [coding_skills],
67
- # "public_speaking_skills": [public_speaking_skills],
68
- # "self_learning": [self_learning],
69
- # "extra_course": [extra_course],
70
- # "certificate": [certificate_code],
71
- # "workshop": [worskhop_code],
72
- # "read_writing_skills": [
73
- # (0 if "poor" in read_writing_skill else 1 if "medium" in read_writing_skill else 2)
74
- # ],
75
- # "memory_capability": [
76
- # (0 if "poor" in memory_capability else 1 if "medium" in memory_capability else 2)
77
- # ],
78
- # "subject_interest": [subject_interest],
79
- # "career_interest": [career_interest],
80
- # "company_intend": [company_intend],
81
- # "senior_elder_advise": [senior_elder_advise],
82
- # "book_interest": [book_interest],
83
- # "introvert_extro": [introvert_extro],
84
- # "team_player": [team_player],
85
- # "management_technical":[management_technical],
86
- # "smart_hardworker": [smart_hardworker]
87
- # }
88
- # )
89
-
90
- # # Replace string values with numeric representations
91
- # df = df.replace({
92
- # "certificate": certificates_references,
93
- # "workshop": workshop_references,
94
- # "subject_interest": subjects_interest_references,
95
- # "career_interest": career_interest_references,
96
- # "company_intend": company_intends_references,
97
- # "book_interest": book_interest_references
98
- # })
99
-
100
- # # Dummy encoding (same as original code)
101
- # userdata_list = df.values.tolist()
102
-
103
- # # Management-Technical dummy encoding
104
- # if(df["management_technical"].values == "Management"):
105
- # userdata_list[0].extend([1])
106
- # userdata_list[0].extend([0])
107
- # userdata_list[0].remove('Management')
108
- # elif(df["management_technical"].values == "Technical"):
109
- # userdata_list[0].extend([0])
110
- # userdata_list[0].extend([1])
111
- # userdata_list[0].remove('Technical')
112
- # else:
113
- # return "Error in Management-Technical encoding"
114
-
115
- # # Smart-Hard worker dummy encoding
116
- # if(df["smart_hardworker"].values == "smart worker"):
117
- # userdata_list[0].extend([1])
118
- # userdata_list[0].extend([0])
119
- # userdata_list[0].remove('smart worker')
120
- # elif(df["smart_hardworker"].values == "hard worker"):
121
- # userdata_list[0].extend([0])
122
- # userdata_list[0].extend([1])
123
- # userdata_list[0].remove('hard worker')
124
- # else:
125
- # return "Error in Smart-Hard worker encoding"
126
-
127
- # # Prediction
128
- # prediction_result_all = rfmodel.predict_proba(userdata_list)
129
-
130
- # # Create result dictionary
131
- # result_list = {
132
- # "Applications Developer": float(prediction_result_all[0][0]),
133
- # "CRM Technical Developer": float(prediction_result_all[0][1]),
134
- # "Database Developer": float(prediction_result_all[0][2]),
135
- # "Mobile Applications Developer": float(prediction_result_all[0][3]),
136
- # "Network Security Engineer": float(prediction_result_all[0][4]),
137
- # "Software Developer": float(prediction_result_all[0][5]),
138
- # "Software Engineer": float(prediction_result_all[0][6]),
139
- # "Software Quality Assurance (QA)/ Testing": float(prediction_result_all[0][7]),
140
- # "Systems Security Administrator": float(prediction_result_all[0][8]),
141
- # "Technical Support": float(prediction_result_all[0][9]),
142
- # "UX Designer": float(prediction_result_all[0][10]),
143
- # "Web Developer": float(prediction_result_all[0][11]),
144
- # }
145
- # return result_list
146
-
147
- # # Lists for dropdown menus (same as original code)
148
- # cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
149
- # workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
150
- # skill = ["excellent", "medium", "poor"]
151
- # subject_list = ["cloud computing", "Computer Architecture", "data engineering", "hacking", "IOT", "Management", "networks", "parallel computing", "programming", "Software Engineering"]
152
- # career_list = ["Business process analyst", "cloud computing", "developer", "security", "system developer", "testing"]
153
- # company_list = ["BPA", "Cloud Services", "Finance", "Product based", "product development", "SAaS services", "Sales and Marketing", "Service Based", "Testing and Maintainance Services", "Web Services"]
154
- # 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"]
155
- # Choice_list = ["Management", "Technical"]
156
- # worker_list = ["hard worker", "smart worker"]
157
-
158
- # # Create Gradio interface (modified to include model selection)
159
- # demo = gr.Interface(
160
- # fn=rfprediction,
161
- # inputs=[
162
- # gr.Dropdown(["Random Forest", "Decision Tree"], label="Select Machine Learning Model"),
163
- # gr.Textbox(placeholder="What is your name?", label="Name"),
164
- # gr.Slider(minimum=1, maximum=9, value=3, step=1, label="Are you a logical thinking person?", info="Scale: 1 - 9"),
165
- # 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"),
166
- # gr.Slider(minimum=1, maximum=9, value=5, step=1, label="How do you rate your coding skills?", info="Scale: 1 - 9"),
167
- # gr.Slider(minimum=1, maximum=9, value=3, step=1, label="How do you rate your public speaking skills/confidency?", info="Scale: 1 - 9"),
168
- # gr.Radio({"Yes", "No"}, type="index", label="Are you a self-learning person? *"),
169
- # gr.Radio({"Yes", "No"}, type="index", label="Do you take extra courses in uni (other than IT)? *"),
170
- # gr.Dropdown(cert_list, label="Select a certificate you took!"),
171
- # gr.Dropdown(workshop_list, label="Select a workshop you attended!"),
172
- # gr.Dropdown(skill, label="Select your read and writing skill"),
173
- # gr.Dropdown(skill, label="Is your memory capability good?"),
174
- # gr.Dropdown(subject_list, label="What subject you are interested in?"),
175
- # gr.Dropdown(career_list, label="Which IT-Career do you have interests in?"),
176
- # gr.Dropdown(company_list, label="Do you have any interested company that you intend to settle in?"),
177
- # gr.Radio({"Yes", "No"}, type="index", label="Do you ever seek any advices from senior or elders? *"),
178
- # gr.Dropdown(book_list, label="Select your interested genre of book!"),
179
- # gr.Radio({"Yes", "No"}, type="index", label="Are you an Introvert?| No - extrovert *"),
180
- # gr.Radio({"Yes", "No"}, type="index", label="Ever worked in a team? *"),
181
- # gr.Dropdown(Choice_list, label="Which area do you prefer: Management or Technical?"),
182
- # gr.Dropdown(worker_list, label="Are you a Smart worker or Hard worker?")
183
- # ],
184
- # outputs=gr.Label(num_top_classes=5),
185
- # title="IT-Career Recommendation System: TMI4033 Colletive Intelligence, Group 12",
186
- # description="Members: Derrick Lim Kin Yeap 74597, Jason Jong Sheng Tat 75125, Jason Ng Yong Xing 75127, Muhamad Hazrie Bin Suhkery 73555 "
187
- # )
188
-
189
- # # Main execution
190
- # if __name__ == "__main__":
191
- # demo.launch(share=True)
192
-
193
  import gradio as gr
194
  import pandas as pd
195
  import numpy as np
196
  import pickle
197
  import sklearn
198
- import requests
199
  from datasets import load_dataset
200
 
201
  # Read the data
@@ -209,10 +19,13 @@ def load_model(model_choice):
209
  elif model_choice == "Decision Tree":
210
  with open('dtreeweights.pkl', 'rb') as pickleFile:
211
  return pickle.load(pickleFile)
 
 
 
212
  else:
213
  raise ValueError("Invalid model selection")
214
 
215
- # Prepare categorical data
216
  categorical_cols = data[[
217
  'certifications',
218
  'workshops',
@@ -227,7 +40,7 @@ for i in categorical_cols:
227
  data[i] = data[i].astype('category')
228
  data[i] = data[i].cat.codes
229
 
230
- # Create reference dictionaries for embeddings
231
  def create_embedding_dict(column):
232
  unique_names = list(categorical_cols[column].unique())
233
  unique_codes = list(data[column].unique())
@@ -240,7 +53,7 @@ career_interest_references = create_embedding_dict('interested career area ')
240
  company_intends_references = create_embedding_dict('Type of company want to settle in?')
241
  book_interest_references = create_embedding_dict('Interested Type of Books')
242
 
243
- # Prediction function (modified to fetch job details)
244
  def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
245
  self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
246
  subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
@@ -248,7 +61,7 @@ def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_
248
  # Load the selected model
249
  rfmodel = load_model(model_choice)
250
 
251
- # Create DataFrame
252
  df = pd.DataFrame.from_dict(
253
  {
254
  "logical_thinking": [logical_thinking],
@@ -287,7 +100,7 @@ def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_
287
  "book_interest": book_interest_references
288
  })
289
 
290
- # Dummy encoding
291
  userdata_list = df.values.tolist()
292
 
293
  # Management-Technical dummy encoding
@@ -332,35 +145,9 @@ def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_
332
  "UX Designer": float(prediction_result_all[0][10]),
333
  "Web Developer": float(prediction_result_all[0][11]),
334
  }
335
-
336
- # Get the top predicted job
337
- job_pre = max(result_list, key=result_list.get)
338
-
339
- # Fetch job details using RapidAPI
340
- url = "https://jobs-api14.p.rapidapi.com/v2/list"
341
- querystring = {
342
- "query": job_pre,
343
- "location": "India",
344
- "autoTranslateLocation": "false",
345
- "remoteOnly": "false",
346
- "employmentTypes": "fulltime;parttime;intern;contractor"
347
- }
348
- headers = {
349
- "x-rapidapi-key": "714f5a2539msh798d996c3243876p19c71ajsnfcd7ce481cb9",
350
- "x-rapidapi-host": "jobs-api14.p.rapidapi.com"
351
- }
352
-
353
- try:
354
- response = requests.get(url, headers=headers, params=querystring)
355
- job_response = response.json()
356
- print(job_response) # Print the response for debugging
357
- except Exception as e:
358
- print(f"Error fetching job details: {e}")
359
- job_response = {}
360
-
361
  return result_list
362
 
363
- # Lists for dropdown menus
364
  cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
365
  workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
366
  skill = ["excellent", "medium", "poor"]
@@ -371,7 +158,7 @@ book_list = ["Action and Adventure", "Anthology", "Art", "Autobiographies", "Bio
371
  Choice_list = ["Management", "Technical"]
372
  worker_list = ["hard worker", "smart worker"]
373
 
374
- # Create Gradio interface
375
  demo = gr.Interface(
376
  fn=rfprediction,
377
  inputs=[
@@ -404,4 +191,5 @@ demo = gr.Interface(
404
 
405
  # Main execution
406
  if __name__ == "__main__":
407
- demo.launch(share=True)
 
 
1
 
2
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  import gradio as gr
5
  import pandas as pd
6
  import numpy as np
7
  import pickle
8
  import sklearn
 
9
  from datasets import load_dataset
10
 
11
  # Read the data
 
19
  elif model_choice == "Decision Tree":
20
  with open('dtreeweights.pkl', 'rb') as pickleFile:
21
  return pickle.load(pickleFile)
22
+ elif model_choice == "Sequential Model":
23
+ with open('my_seq_model (1).pkl', 'rb') as pickleFile:
24
+ return pickle.load(pickleFile)
25
  else:
26
  raise ValueError("Invalid model selection")
27
 
28
+ # Prepare categorical data (same as original code)
29
  categorical_cols = data[[
30
  'certifications',
31
  'workshops',
 
40
  data[i] = data[i].astype('category')
41
  data[i] = data[i].cat.codes
42
 
43
+ # Create reference dictionaries for embeddings (same as original code)
44
  def create_embedding_dict(column):
45
  unique_names = list(categorical_cols[column].unique())
46
  unique_codes = list(data[column].unique())
 
53
  company_intends_references = create_embedding_dict('Type of company want to settle in?')
54
  book_interest_references = create_embedding_dict('Interested Type of Books')
55
 
56
+ # Prediction function (modified to accept model choice)
57
  def rfprediction(model_choice, name, logical_thinking, hackathon_attend, coding_skills, public_speaking_skills,
58
  self_learning, extra_course, certificate_code, worskhop_code, read_writing_skill, memory_capability,
59
  subject_interest, career_interest, company_intend, senior_elder_advise, book_interest, introvert_extro,
 
61
  # Load the selected model
62
  rfmodel = load_model(model_choice)
63
 
64
+ # Create DataFrame (same as original code)
65
  df = pd.DataFrame.from_dict(
66
  {
67
  "logical_thinking": [logical_thinking],
 
100
  "book_interest": book_interest_references
101
  })
102
 
103
+ # Dummy encoding (same as original code)
104
  userdata_list = df.values.tolist()
105
 
106
  # Management-Technical dummy encoding
 
145
  "UX Designer": float(prediction_result_all[0][10]),
146
  "Web Developer": float(prediction_result_all[0][11]),
147
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  return result_list
149
 
150
+ # Lists for dropdown menus (same as original code)
151
  cert_list = ["app development", "distro making", "full stack", "hadoop", "information security", "machine learning", "python", "r programming", "shell programming"]
152
  workshop_list = ["cloud computing", "data science", "database security", "game development", "hacking", "system designing", "testing", "web technologies"]
153
  skill = ["excellent", "medium", "poor"]
 
158
  Choice_list = ["Management", "Technical"]
159
  worker_list = ["hard worker", "smart worker"]
160
 
161
+ # Create Gradio interface (modified to include model selection)
162
  demo = gr.Interface(
163
  fn=rfprediction,
164
  inputs=[
 
191
 
192
  # Main execution
193
  if __name__ == "__main__":
194
+ demo.launch(share=True)
195
+