harshiv commited on
Commit
bce6d07
1 Parent(s): 78099f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -47
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 the trained models
7
- rf_fullstk = joblib.load('rf_hacathon_fullstk.pkl')
8
- rf_prodengg = joblib.load('rf_hacathon_prodengg.pkl')
9
- rf_mkt = joblib.load('rf_hacathon_mkt.pkl')
 
 
 
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
- # Predict placement using the respective model
26
- if management == 1 and leadership == 0:
27
- p = rf_prodengg.predict(new_data)[0]
28
- prob = rf_prodengg.predict_proba(new_data)[0][1]
29
- elif DSA == 1 and java == 0:
30
- p = rf_fullstk.predict(new_data)[0]
31
- prob = rf_fullstk.predict_proba(new_data)[0][1]
32
- elif communication == 0 and sales == 1:
33
- p = rf_mkt.predict(new_data)[0]
34
- prob = rf_mkt.predict_proba(new_data)[0][1]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  else:
36
- p = 0
37
- prob = 0
38
 
39
- if p == 1:
40
- result = f'Placed\nYou will be placed with a probability of {prob:.2f}'
41
  else:
42
- result = 'Not Placed'
43
- return result
44
 
45
- # Create the Gradio interface
46
  iface = gr.Interface(
47
  fn=predict_placement,
48
  inputs=[
49
- gr.inputs.Slider(label='Degree Percentage', key='degree_p', minimum=0, maximum=100, default=75, step=1),
50
- gr.inputs.Checkbox(label='Internship', default=True, key='internship'),
51
- gr.inputs.Checkbox(label='DSA', default=True, key='DSA'),
52
- gr.inputs.Checkbox(label='Java', default=False, key='java'),
53
- gr.inputs.Checkbox(label='Management', default=False, key='management'),
54
- gr.inputs.Checkbox(label='Leadership', default=False, key='leadership'),
55
- gr.inputs.Checkbox(label='Communication', default=False, key='communication'),
56
- gr.inputs.Checkbox(label='Sales', default=False, key='sales')
 
 
57
  ],
58
- outputs=gr.outputs.Textbox(label='Placement Prediction')
 
 
 
59
  )
60
 
61
- # Run the Gradio app
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)