harshiv commited on
Commit
1d799b9
1 Parent(s): 0f08203

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -86
app.py CHANGED
@@ -1,94 +1,62 @@
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'),
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()
 
1
  import gradio as gr
2
+ import joblib
 
3
  import pickle
4
+ import pandas as pd
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 the prediction function
12
+ def predict_placement(degree_p, internship, DSA, java, management, leadership, communication, sales):
13
+ # Create a new data frame from the input
14
+ new_data = pd.DataFrame({
15
+ 'degree_p': degree_p,
16
+ 'internship': internship,
17
+ 'DSA': DSA,
18
+ 'java': java,
19
+ 'management': management,
20
+ 'leadership': leadership,
21
+ 'communication': communication,
22
+ 'sales': sales
23
+ }, index=[0])
24
+
25
+ # Predict placement using the respective model
26
+ if management == 1 and leadership == 0:
27
+ p = rf_prodengg.predict(new_data)[0]
28
+ prob = rf_prodengg.predict_proba(new_data)[0][1]
29
+ elif DSA == 1 and java == 0:
30
+ p = rf_fullstk.predict(new_data)[0]
31
+ prob = rf_fullstk.predict_proba(new_data)[0][1]
32
+ elif communication == 0 and sales == 1:
33
+ p = rf_mkt.predict(new_data)[0]
34
+ prob = rf_mkt.predict_proba(new_data)[0][1]
35
+ else:
36
+ p = 0
37
+ prob = 0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
+ if p == 1:
40
+ result = f'Placed\nYou will be placed with a probability of {prob:.2f}'
 
41
  else:
42
  result = 'Not Placed'
43
+ return result
44
+
45
+ # Create the Gradio interface
46
+ iface = gr.Interface(
47
+ fn=predict_placement,
48
+ inputs=[
49
+ gr.inputs.Slider(label='Degree Percentage', minimum=0, maximum=100, default=75, step=1, key='degree_p'),
50
+ gr.inputs.Checkbox(label='Internship', default=True, key='internship'),
51
+ gr.inputs.Checkbox(label='DSA', default=True, key='DSA'),
52
+ gr.inputs.Checkbox(label='Java', default=False, key='java'),
53
+ gr.inputs.Checkbox(label='Management', default=False, key='management'),
54
+ gr.inputs.Checkbox(label='Leadership', default=False, key='leadership'),
55
+ gr.inputs.Checkbox(label='Communication', default=False, key='communication'),
56
+ gr.inputs.Checkbox(label='Sales', default=False, key='sales')
57
+ ],
58
+ outputs=gr.outputs.Textbox(label='Placement Prediction')
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  )
60
 
61
+ # Run the Gradio app
62
+ iface.launch()