harshiv commited on
Commit
4892bb0
1 Parent(s): 13fe00a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -57
app.py CHANGED
@@ -1,73 +1,94 @@
1
  import gradio as gr
2
  import numpy as np
3
  import pandas as pd
4
- import joblib
5
 
6
- # Load the trained models
7
- rf_fullstk = joblib.load('rf_hacathon_fullstk.pkl')
8
- rf_prodengg = joblib.load('rf_hacathon_prodengg.pkl')
9
- rf_mkt = joblib.load('rf_hacathon_mkt.pkl')
 
 
 
10
 
11
- # Define prediction functions for each model
12
- def predict_fullstk(degree_p, internship, DSA, java):
13
- new_data = pd.DataFrame({
14
- 'degree_p': degree_p,
15
- 'internship': internship,
16
- 'DSA': DSA,
17
- 'java': java,
18
- }, index=[0])
19
- prediction = rf_fullstk.predict(new_data)[0]
20
- probability = rf_fullstk.predict_proba(new_data)[0][1]
21
- return 'Placed' if prediction == 1 else 'Not Placed', probability
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- def predict_prodengg(degree_p, internship, management, leadership):
24
- new_data = pd.DataFrame({
25
- 'degree_p': degree_p,
26
- 'internship': internship,
27
- 'management': management,
28
- 'leadership': leadership,
29
- }, index=[0])
30
- prediction = rf_prodengg.predict(new_data)[0]
31
- probability = rf_prodengg.predict_proba(new_data)[0][1]
32
- return 'Placed' if prediction == 1 else 'Not Placed', probability
33
 
34
- def predict_mkt(degree_p, internship, communication, sales):
35
- new_data = pd.DataFrame({
36
- 'degree_p': degree_p,
37
- 'internship': internship,
38
- 'communication': communication,
39
- 'sales': sales,
40
- }, index=[0])
41
- prediction = rf_mkt.predict(new_data)[0]
42
- probability = rf_mkt.predict_proba(new_data)[0][1]
43
- return 'Placed' if prediction == 1 else 'Not Placed', probability
44
 
45
- # Create input and output components for each model
46
- fullstk_inputs = [
47
- gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
48
- gr.inputs.Radio(label='Internship', choices=[0, 1]),
49
- gr.inputs.Radio(label='DSA', choices=[0, 1]),
50
- gr.inputs.Radio(label='Java', choices=[0, 1])
51
- ]
52
- fullstk_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
53
 
54
- prodengg_inputs = [
 
55
  gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
56
  gr.inputs.Radio(label='Internship', choices=[0, 1]),
 
 
57
  gr.inputs.Radio(label='Management Skills', choices=[0, 1]),
58
- gr.inputs.Radio(label='Leadership Skills', choices=[0, 1])
 
 
 
59
  ]
60
- prodengg_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
61
 
62
- mkt_inputs = [
63
- gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
64
- gr.inputs.Radio(label='Internship', choices=[0, 1]),
65
- gr.inputs.Radio(label='Communication Skills', choices=[0, 1]),
66
- gr.inputs.Radio(label='Sales Skills', choices=[0, 1])
67
  ]
68
- mkt_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
69
 
70
- # Create the Gradio app
71
- fullstk_interface = gr.Interface(
72
- fn=predict_fullstk,
73
- inputs=fullstk
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import numpy as np
3
  import pandas as pd
4
+ import pickle
5
 
6
+ # Load trained models
7
+ with open('rf_hacathon_fullstk.pkl', 'rb') as f1:
8
+ rf_fullstk = pickle.load(f1)
9
+ with open('rf_hacathon_prodengg.pkl', 'rb') as f2:
10
+ rf_prodengg = pickle.load(f2)
11
+ with open('rf_hacathon_mkt.pkl', 'rb') as f3:
12
+ rf_mkt = pickle.load(f3)
13
 
14
+ # Define prediction function
15
+ def predict_placed(degree_p, internship, DSA, java, management, leadership, communication, sales, model_name):
16
+ if model_name == 'Full Stack':
17
+ new_data = pd.DataFrame({
18
+ 'degree_p': degree_p,
19
+ 'internship': internship,
20
+ 'DSA': DSA,
21
+ 'java': java,
22
+ 'management': 0,
23
+ 'leadership': 0,
24
+ 'communication': 0,
25
+ 'sales': 0
26
+ }, index=[0])
27
+ model = rf_fullstk
28
+ elif model_name == 'Product Engineering':
29
+ new_data = pd.DataFrame({
30
+ 'degree_p': degree_p,
31
+ 'internship': internship,
32
+ 'DSA': 0,
33
+ 'java': 0,
34
+ 'management': management,
35
+ 'leadership': leadership,
36
+ 'communication': 0,
37
+ 'sales': 0
38
+ }, index=[0])
39
+ model = rf_prodengg
40
+ elif model_name == 'Marketing':
41
+ new_data = pd.DataFrame({
42
+ 'degree_p': degree_p,
43
+ 'internship': internship,
44
+ 'DSA': 0,
45
+ 'java': 0,
46
+ 'management': 0,
47
+ 'leadership': 0,
48
+ 'communication': communication,
49
+ 'sales': sales
50
+ }, index=[0])
51
+ model = rf_mkt
52
 
53
+ prediction = model.predict(new_data)
54
+ probability = model.predict_proba(new_data)[0][1]
 
 
 
 
 
 
 
 
55
 
56
+ if prediction == 1:
57
+ result = 'Placed'
58
+ probability_message = f"You will be placed with a probability of {probability:.2f}"
59
+ else:
60
+ result = 'Not Placed'
61
+ probability_message = ""
 
 
 
 
62
 
63
+ return result, probability_message
 
 
 
 
 
 
 
64
 
65
+ # Create Gradio interface
66
+ inputs = [
67
  gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
68
  gr.inputs.Radio(label='Internship', choices=[0, 1]),
69
+ gr.inputs.Radio(label='Data Structures & Algorithms', choices=[0, 1]),
70
+ gr.inputs.Radio(label='Java', choices=[0, 1]),
71
  gr.inputs.Radio(label='Management Skills', choices=[0, 1]),
72
+ gr.inputs.Radio(label='Leadership Skills', choices=[0, 1]),
73
+ gr.inputs.Radio(label='Communication Skills', choices=[0, 1]),
74
+ gr.inputs.Radio(label='Sales Skills', choices=[0, 1]),
75
+ gr.inputs.Dropdown(label='Model Name', choices=['Full Stack', 'Product Engineering', 'Marketing'])
76
  ]
 
77
 
78
+ outputs = [
79
+ gr.outputs.Textbox(label='Placement Result'),
80
+ gr.outputs.Textbox(label='Placement Probability')
 
 
81
  ]
 
82
 
83
+ app = gr.Interface(
84
+ fn=predict_placed,
85
+ inputs=inputs,
86
+ outputs=outputs,
87
+ title='Placement Prediction',
88
+ description='Predict placement outcome based on given inputs',
89
+ allow_flagging=False
90
+ )
91
+
92
+ # Run the app
93
+ if __name__ == '__main__':
94
+ app.run()