placementrep / api.py
harshiv's picture
Update api.py
8a64eea
import numpy as np
import pandas as pd
import gradio as gr
import pickle
# Load trained models
with open('rf_hacathon_fullstk.pkl', 'rb') as f1:
rf_fullstk = pickle.load(f1)
with open('rf_hacathon_prodengg.pkl', 'rb') as f2:
rf_prodengg = pickle.load(f2)
with open('rf_hacathon_mkt.pkl', 'rb') as f3:
rf_mkt = pickle.load(f3)
# Define input and output functions for Gradio
def predict_placement(option, degree_p, internship, DSA, java, management,
leadership, communication, sales):
if option == "Fullstack":
new_data = pd.DataFrame(
{
'degree_p': degree_p,
'internship': internship,
'DSA': DSA,
'java': java,
},
index=[0])
prediction = rf_fullstk.predict(new_data)
probability = rf_fullstk.predict_proba(new_data)[0][1]
elif option == "Marketing":
new_data = pd.DataFrame(
{
'degree_p': degree_p,
'internship': internship,
'management': management,
'leadership': leadership,
},
index=[0])
prediction = rf_mkt.predict(new_data)
probability = rf_mkt.predict_proba(new_data)[0][1]
elif option == "Production Engineer":
new_data = pd.DataFrame(
{
'degree_p': degree_p,
'internship': internship,
'communication': communication,
'sales': sales,
},
index=[0])
prediction = rf_prodengg.predict(new_data)
probability = rf_prodengg.predict_proba(new_data)[0][1]
else:
return "Invalid option"
if prediction == 1:
return f"{probability:.2f}"
else:
return f"{probability:.2f}"
# Create Gradio interface
iface = gr.Interface(
fn=predict_placement,
inputs=[
gr.inputs.Dropdown(["Fullstack", "Marketing", "Production Engineer"],
label="Select Option"),
gr.inputs.Number(label="Degree Percentage"),
gr.inputs.Number(label="Internship"),
gr.inputs.Checkbox(label="DSA"),
gr.inputs.Checkbox(label="Java"),
gr.inputs.Checkbox(label="Management"),
gr.inputs.Checkbox(label="Leadership"),
gr.inputs.Checkbox(label="Communication"),
gr.inputs.Checkbox(label="Sales"),
],
outputs=gr.outputs.Textbox(label="Placement Prediction"),
title="Placement Prediction",
description=
"Predict the chances of placement for different job roles using machine learning models.",
)
# Launch Gradio app
iface.launch(share=True)