File size: 2,678 Bytes
2b3c741
 
8a64eea
 
2b3c741
8a64eea
 
 
 
 
 
 
2b3c741
 
8a64eea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b3c741
8a64eea
 
 
 
 
 
 
 
 
 
 
2b3c741
8a64eea
 
2b3c741
8a64eea
 
 
 
2b3c741
 
8a64eea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b3c741
8a64eea
 
1
2
3
4
5
6
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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)