msgasu commited on
Commit
79b1e4f
·
verified ·
1 Parent(s): 0eb7602

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +121 -0
  2. requirements.txt +5 -0
  3. trained_model.joblib +3 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+ import numpy as np
4
+ import gradio as gr
5
+
6
+ # Load your trained model
7
+ model = joblib.load('trained_model.joblib')
8
+
9
+ # Define grade to numeric conversion (same as before)
10
+ def grade_to_numeric(grade):
11
+ if pd.isna(grade) or grade == "":
12
+ return np.nan
13
+ grade_map = {
14
+ "A1": 1, "B2": 2, "B3": 3, "C4": 4, "C5": 5, "C6": 6,
15
+ "D7": 7, "E8": 8, "F9": 9
16
+ }
17
+ return grade_map.get(grade, np.nan)
18
+
19
+ # Define your preprocessing function
20
+ def preprocess_input(desired_career, aggregate, english, core_maths, science,
21
+ social_studies, electives, elective_maths=None,
22
+ business_management=None, government=None, chemistry=None,
23
+ physics=None, economics=None, visual_arts=None, geography=None,
24
+ e_ict=None, literature=None, biology=None):
25
+
26
+ # Create a dictionary with all inputs
27
+ input_data = {
28
+ "Desired_Career": desired_career,
29
+ "Aggregate": aggregate,
30
+ "English": english,
31
+ "Core Maths": core_maths,
32
+ "Science": science,
33
+ "Social Studies": social_studies,
34
+ "Electives": electives,
35
+ "Elective Maths": elective_maths,
36
+ "Business Management": business_management,
37
+ "Government": government,
38
+ "Chemistry": chemistry,
39
+ "Physics": physics,
40
+ "Economics": economics,
41
+ "Visual Arts": visual_arts,
42
+ "Geography": geography,
43
+ "E-ICT": e_ict,
44
+ "Literature": literature,
45
+ "Biology": biology
46
+ }
47
+
48
+ # Convert to DataFrame
49
+ student_df = pd.DataFrame([input_data])
50
+
51
+ # Convert grades to numerical
52
+ grade_cols = ['English', 'Core Maths', 'Science', 'Social Studies',
53
+ 'Elective Maths', 'Business Management', 'Government',
54
+ 'Chemistry', 'Physics', 'Economics', 'Visual Arts',
55
+ 'Geography', 'E-ICT', 'Literature', 'Biology']
56
+
57
+ for col in grade_cols:
58
+ if col in student_df.columns:
59
+ student_df[col] = student_df[col].apply(grade_to_numeric)
60
+
61
+ return student_df
62
+
63
+ def predict_career(desired_career, aggregate, english, core_maths, science,
64
+ social_studies, electives, elective_maths=None,
65
+ business_management=None, government=None, chemistry=None,
66
+ physics=None, economics=None, visual_arts=None, geography=None,
67
+ e_ict=None, literature=None, biology=None):
68
+
69
+ # Preprocess input
70
+ processed_input = preprocess_input(
71
+ desired_career, aggregate, english, core_maths, science,
72
+ social_studies, electives, elective_maths, business_management,
73
+ government, chemistry, physics, economics, visual_arts, geography,
74
+ e_ict, literature, biology
75
+ )
76
+
77
+ # Make prediction
78
+ prediction = model.predict(processed_input)
79
+ probabilities = model.predict_proba(processed_input)[0]
80
+
81
+ # Get top 3 recommendations
82
+ class_indices = np.argsort(probabilities)[::-1][:3]
83
+ classes = model.classes_
84
+ recommendations = [
85
+ (classes[idx], float(probabilities[idx]))
86
+ for idx in class_indices
87
+ ]
88
+
89
+ # Format output
90
+ output = "\n".join(
91
+ [f"{course}: {prob*100:.1f}%" for course, prob in recommendations]
92
+ )
93
+
94
+ return output
95
+
96
+ # Create Gradio interface
97
+ inputs = [
98
+ gr.Dropdown(["Medicine", "Pharmacy", "Law", "Computer Science", "Engineering",
99
+ "Business", "Nursing", "Agriculture", "Journalism", "Education"],
100
+ label="Desired Career"),
101
+ gr.Number(label="Aggregate Score"),
102
+ gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="English"),
103
+ gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Core Maths"),
104
+ gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Science"),
105
+ gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9"], label="Social Studies"),
106
+ gr.Textbox(label="Electives (comma separated)"),
107
+ gr.Dropdown(["A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9", None], label="Elective Maths (optional)"),
108
+ # Add other optional subjects similarly
109
+ ]
110
+
111
+ outputs = gr.Textbox(label="Recommended Courses")
112
+
113
+ interface = gr.Interface(
114
+ fn=predict_career,
115
+ inputs=inputs,
116
+ outputs=outputs,
117
+ title="Career Path Recommender",
118
+ description="Enter your academic information to get career recommendations"
119
+ )
120
+
121
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==3.50.2
2
+ pandas==1.5.3
3
+ numpy==1.23.5
4
+ scikit-learn==1.2.2
5
+ joblib==1.2.0
trained_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:572ea685ee5d87389cd0e370ed4db6d85415cc2e94396459a40cab5fdba64b94
3
+ size 88291291