Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,62 +1,82 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import joblib
|
3 |
import pickle
|
4 |
-
import pandas as pd
|
5 |
|
6 |
-
# Load
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
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 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
else:
|
36 |
-
|
37 |
-
prob = 0
|
38 |
|
39 |
-
if
|
40 |
-
|
41 |
else:
|
42 |
-
|
43 |
-
|
44 |
|
45 |
-
# Create
|
46 |
iface = gr.Interface(
|
47 |
fn=predict_placement,
|
48 |
inputs=[
|
49 |
-
gr.inputs.
|
50 |
-
|
51 |
-
gr.inputs.
|
52 |
-
gr.inputs.
|
53 |
-
gr.inputs.Checkbox(label=
|
54 |
-
gr.inputs.Checkbox(label=
|
55 |
-
gr.inputs.Checkbox(label=
|
56 |
-
gr.inputs.Checkbox(label=
|
|
|
|
|
57 |
],
|
58 |
-
outputs=gr.outputs.Textbox(label=
|
|
|
|
|
|
|
59 |
)
|
60 |
|
61 |
-
#
|
62 |
-
iface.launch()
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
import gradio as gr
|
|
|
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 |
|
15 |
+
# Define input and output functions for Gradio
|
16 |
+
def predict_placement(option, degree_p, internship, DSA, java, management,
|
17 |
+
leadership, communication, sales):
|
18 |
+
if option == "Fullstack":
|
19 |
+
new_data = pd.DataFrame(
|
20 |
+
{
|
21 |
+
'degree_p': degree_p,
|
22 |
+
'internship': internship,
|
23 |
+
'DSA': DSA,
|
24 |
+
'java': java,
|
25 |
+
},
|
26 |
+
index=[0])
|
27 |
+
prediction = rf_fullstk.predict(new_data)
|
28 |
+
probability = rf_fullstk.predict_proba(new_data)[0][1]
|
29 |
+
elif option == "Marketing":
|
30 |
+
new_data = pd.DataFrame(
|
31 |
+
{
|
32 |
+
'degree_p': degree_p,
|
33 |
+
'internship': internship,
|
34 |
+
'management': management,
|
35 |
+
'leadership': leadership,
|
36 |
+
},
|
37 |
+
index=[0])
|
38 |
+
prediction = rf_prodengg.predict(new_data)
|
39 |
+
probability = rf_prodengg.predict_proba(new_data)[0][1]
|
40 |
+
elif option == "Production Engineer":
|
41 |
+
new_data = pd.DataFrame(
|
42 |
+
{
|
43 |
+
'degree_p': degree_p,
|
44 |
+
'internship': internship,
|
45 |
+
'communication': communication,
|
46 |
+
'sales': sales,
|
47 |
+
},
|
48 |
+
index=[0])
|
49 |
+
prediction = rf_mkt.predict(new_data)
|
50 |
+
probability = rf_mkt.predict_proba(new_data)[0][1]
|
51 |
else:
|
52 |
+
return "Invalid option"
|
|
|
53 |
|
54 |
+
if prediction == 1:
|
55 |
+
return f"Placed\nYou will be placed with a probability of {probability:.2f}"
|
56 |
else:
|
57 |
+
return "Not Placed"
|
58 |
+
|
59 |
|
60 |
+
# Create Gradio interface
|
61 |
iface = gr.Interface(
|
62 |
fn=predict_placement,
|
63 |
inputs=[
|
64 |
+
gr.inputs.Dropdown(["Fullstack", "Marketing", "Production Engineer"],
|
65 |
+
label="Select Option"),
|
66 |
+
gr.inputs.Number(label="Degree Percentage"),
|
67 |
+
gr.inputs.Number(label="Internship"),
|
68 |
+
gr.inputs.Checkbox(label="DSA"),
|
69 |
+
gr.inputs.Checkbox(label="Java"),
|
70 |
+
gr.inputs.Checkbox(label="Management"),
|
71 |
+
gr.inputs.Checkbox(label="Leadership"),
|
72 |
+
gr.inputs.Checkbox(label="Communication"),
|
73 |
+
gr.inputs.Checkbox(label="Sales"),
|
74 |
],
|
75 |
+
outputs=gr.outputs.Textbox(label="Placement Prediction"),
|
76 |
+
title="Placement Prediction",
|
77 |
+
description=
|
78 |
+
"Predict the chances of placement for different job roles using machine learning models.",
|
79 |
)
|
80 |
|
81 |
+
# Launch Gradio app
|
82 |
+
iface.launch(share=True)
|