Spaces:
Runtime error
Runtime error
import gradio as gr | |
import joblib | |
import pickle | |
import pandas as pd | |
# Load the trained models | |
rf_fullstk = joblib.load('rf_hacathon_fullstk.pkl') | |
rf_prodengg = joblib.load('rf_hacathon_prodengg.pkl') | |
rf_mkt = joblib.load('rf_hacathon_mkt.pkl') | |
# Define the prediction function | |
def predict_placement(degree_p, internship, DSA, java, management, leadership, communication, sales): | |
# Create a new data frame from the input | |
new_data = pd.DataFrame({ | |
'degree_p': degree_p, | |
'internship': internship, | |
'DSA': DSA, | |
'java': java, | |
'management': management, | |
'leadership': leadership, | |
'communication': communication, | |
'sales': sales | |
}, index=[0]) | |
# Predict placement using the respective model | |
if management == 1 and leadership == 0: | |
p = rf_prodengg.predict(new_data)[0] | |
prob = rf_prodengg.predict_proba(new_data)[0][1] | |
elif DSA == 1 and java == 0: | |
p = rf_fullstk.predict(new_data)[0] | |
prob = rf_fullstk.predict_proba(new_data)[0][1] | |
elif communication == 0 and sales == 1: | |
p = rf_mkt.predict(new_data)[0] | |
prob = rf_mkt.predict_proba(new_data)[0][1] | |
else: | |
p = 0 | |
prob = 0 | |
if p == 1: | |
result = f'Placed\nYou will be placed with a probability of {prob:.2f}' | |
else: | |
result = 'Not Placed' | |
return result | |
# Create the Gradio interface | |
iface = gr.Interface( | |
fn=predict_placement, | |
inputs=[ | |
gr.inputs.Slider(label='Degree Percentage', minimum=0, maximum=100, default=75, step=1, key='degree_p'), | |
gr.inputs.Checkbox(label='Internship', default=True, key='internship'), | |
gr.inputs.Checkbox(label='DSA', default=True, key='DSA'), | |
gr.inputs.Checkbox(label='Java', default=False, key='java'), | |
gr.inputs.Checkbox(label='Management', default=False, key='management'), | |
gr.inputs.Checkbox(label='Leadership', default=False, key='leadership'), | |
gr.inputs.Checkbox(label='Communication', default=False, key='communication'), | |
gr.inputs.Checkbox(label='Sales', default=False, key='sales') | |
], | |
outputs=gr.outputs.Textbox(label='Placement Prediction') | |
) | |
# Run the Gradio app | |
iface.launch() | |