Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,73 +1,94 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import pandas as pd
|
4 |
-
import
|
5 |
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
10 |
|
11 |
-
# Define prediction
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
-
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
'
|
39 |
-
|
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 |
-
|
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 |
-
|
|
|
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 |
-
|
63 |
-
gr.
|
64 |
-
gr.
|
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 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|