Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,94 +1,62 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import pandas as pd
|
4 |
import pickle
|
|
|
5 |
|
6 |
-
# Load trained models
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
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
|
57 |
-
result = 'Placed'
|
58 |
-
probability_message = f"You will be placed with a probability of {probability:.2f}"
|
59 |
else:
|
60 |
result = 'Not Placed'
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
inputs
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
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 |
-
|
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()
|
|