WickedFaith commited on
Commit
6e950ab
·
verified ·
1 Parent(s): 37d417a

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -101
app.py DELETED
@@ -1,101 +0,0 @@
1
-
2
- import pandas as pd
3
- import numpy as np
4
- from sklearn.metrics import accuracy_score, confusion_matrix, classification_report
5
- import matplotlib.pyplot as plt
6
- import seaborn as sns
7
- import pickle
8
- import gradio as gr
9
- import os
10
-
11
- # Load the model
12
- model_path = 'career_prediction_model.pkl'
13
- with open(model_path, 'rb') as f:
14
- saved_data = pickle.load(f)
15
-
16
- model = saved_data['model']
17
- label_encoders = saved_data['label_encoders']
18
- target_encoder = saved_data['target_encoder']
19
- features = saved_data['features']
20
- target = 'What would you like to become when you grow up'
21
-
22
- # Function for individual prediction
23
- def predict_career(work_env, academic_perf, motivation, leadership, tech_savvy, risk_taking=5, financial_stability=5, work_exp="No Experience"):
24
- # Prepare input data
25
- input_data = pd.DataFrame({
26
- 'Preferred Work Environment': [work_env],
27
- 'Academic Performance (CGPA/Percentage)': [float(academic_perf)],
28
- 'Motivation for Career Choice ': [motivation], # Note the space at the end
29
- 'Leadership Experience': [leadership],
30
- 'Tech-Savviness': [tech_savvy],
31
- 'Risk-Taking Ability ': [float(risk_taking)], # Note the space at the end
32
- 'Financial Stability - self/family (1 is low income and 10 is high income)': [float(financial_stability)],
33
- 'Previous Work Experience (If Any)': [work_exp]
34
- })
35
-
36
- # Encode categorical features
37
- for feature in features:
38
- if feature in input_data.columns:
39
- if feature in label_encoders and input_data[feature].dtype == 'object':
40
- try:
41
- input_data[feature] = label_encoders[feature].transform(input_data[feature])
42
- except ValueError:
43
- # Handle unknown categories
44
- print(f"Warning: Unknown category in {feature}. Using most frequent category.")
45
- input_data[feature] = 0 # Default to first category
46
- else:
47
- print(f"Warning: Feature {feature} not found in input data.")
48
-
49
- # Make prediction
50
- prediction = model.predict(input_data)[0]
51
- predicted_career = target_encoder.inverse_transform([int(prediction)])[0]
52
-
53
- # Get probabilities for all classes
54
- if hasattr(model, 'predict_proba'):
55
- probabilities = model.predict_proba(input_data)[0]
56
- class_probs = {target_encoder.inverse_transform([i])[0]: prob
57
- for i, prob in enumerate(probabilities)}
58
- sorted_probs = dict(sorted(class_probs.items(), key=lambda x: x[1], reverse=True))
59
-
60
- result = f"Predicted career: {predicted_career}\n\nProbabilities:\n"
61
- for career, prob in sorted_probs.items():
62
- result += f"{career}: {prob:.2f}\n"
63
- return result
64
- else:
65
- return f"Predicted career: {predicted_career}"
66
-
67
- # Get unique values for dropdowns
68
- work_env_options = list(label_encoders['Preferred Work Environment'].classes_)
69
- motivation_options = list(label_encoders['Motivation for Career Choice '].classes_)
70
- leadership_options = list(label_encoders['Leadership Experience'].classes_)
71
- tech_savvy_options = list(label_encoders['Tech-Savviness'].classes_)
72
-
73
- # Get work experience options if available
74
- work_exp_options = []
75
- if 'Previous Work Experience (If Any)' in label_encoders:
76
- work_exp_options = list(label_encoders['Previous Work Experience (If Any)'].classes_)
77
- else:
78
- work_exp_options = ["No Experience", "Internship", "Part Time", "Full Time"]
79
-
80
- # Create the Gradio interface
81
- # Create the Gradio interface
82
- iface = gr.Interface(
83
- fn=predict_career,
84
- inputs=[
85
- gr.Dropdown(work_env_options, label="Preferred Work Environment"),
86
- gr.Textbox(label="Academic Performance (CGPA/Percentage)", placeholder="Enter your CGPA (e.g. 8.75)"),
87
- gr.Dropdown(motivation_options, label="Motivation for Career Choice"),
88
- gr.Dropdown(leadership_options, label="Leadership Experience"),
89
- gr.Dropdown(tech_savvy_options, label="Tech-Savviness"),
90
- gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Risk-Taking Ability"),
91
- gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Financial Stability"),
92
- gr.Dropdown(work_exp_options, label="Previous Work Experience")
93
- ],
94
- outputs="text",
95
- title="Career Prediction Model",
96
- description="Enter your details to predict your future career path",
97
- theme="huggingface"
98
- )
99
- # Launch the interface
100
- if __name__ == "__main__":
101
- iface.launch()