harshiv commited on
Commit
e6b2bd9
1 Parent(s): 363ca0a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -58
app.py CHANGED
@@ -1,60 +1,73 @@
1
- # Import necessary libraries
2
- import pandas as pd
3
- from sklearn.model_selection import train_test_split
4
- from sklearn.ensemble import RandomForestClassifier
5
- from sklearn.metrics import accuracy_score
6
- from sklearn.pipeline import Pipeline
7
- from sklearn.preprocessing import StandardScaler
8
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Load the CSV data into a pandas DataFrame
11
- data = pd.read_csv('dataset.csv')
12
-
13
- # Split the data into features (X) and labels (y)
14
- X = data.iloc[:, :-1] # All columns except the last one
15
- y = data.iloc[:, -1] # Last column (placed or not)
16
-
17
- # Split the data into training and testing sets
18
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
19
-
20
- # Create a pipeline with a Random Forest Classifier
21
- pipeline = Pipeline([
22
- ('scaler', StandardScaler()), # Standardize features
23
- ('classifier', RandomForestClassifier()) # Random Forest Classifier
24
- ])
25
-
26
- # Fit the pipeline to the training data
27
- pipeline.fit(X_train, y_train)
28
-
29
- # Make predictions on the testing data
30
- y_pred = pipeline.predict(X_test)
31
-
32
- # Calculate accuracy of the model
33
- accuracy = accuracy_score(y_test, y_pred)
34
- print('Accuracy:', accuracy)
35
-
36
- # Define the input and output types for Gradio
37
- input_type = 'csv'
38
- output_type = 'label'
39
-
40
- # Define the function to make predictions using the trained model
41
- def predict_placement(Internships, CGPA, HistoryOfBacklogs):
42
- # Create a DataFrame from the input data
43
- input_df = pd.DataFrame({'Internships': [Internships], 'CGPA': [CGPA], 'HistoryOfBacklogs': [HistoryOfBacklogs]})
44
-
45
- # Make a prediction using the trained model
46
- prediction = pipeline.predict(input_df)[0]
47
-
48
- # Return the predicted label
49
- return 'Placed' if prediction else 'Not Placed'
50
-
51
- interface = gr.Interface(
52
- fn=predict_placement,
53
- inputs=["number", "number", "number"],
54
- outputs="text",
55
- title="Student Placement Prediction",
56
- description="Predict whether a student will be placed in a job based on their internships, CGPA, and history of backlogs."
57
- )
58
-
59
- # Launch the Gradio interface
60
- interface.launch()
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import pandas as pd
4
+ import joblib
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 prediction functions for each model
12
+ def predict_fullstk(degree_p, internship, DSA, java):
13
+ new_data = pd.DataFrame({
14
+ 'degree_p': degree_p,
15
+ 'internship': internship,
16
+ 'DSA': DSA,
17
+ 'java': java,
18
+ }, index=[0])
19
+ prediction = rf_fullstk.predict(new_data)[0]
20
+ probability = rf_fullstk.predict_proba(new_data)[0][1]
21
+ return 'Placed' if prediction == 1 else 'Not Placed', probability
22
+
23
+ def predict_prodengg(degree_p, internship, management, leadership):
24
+ new_data = pd.DataFrame({
25
+ 'degree_p': degree_p,
26
+ 'internship': internship,
27
+ 'management': management,
28
+ 'leadership': leadership,
29
+ }, index=[0])
30
+ prediction = rf_prodengg.predict(new_data)[0]
31
+ probability = rf_prodengg.predict_proba(new_data)[0][1]
32
+ return 'Placed' if prediction == 1 else 'Not Placed', probability
33
+
34
+ def predict_mkt(degree_p, internship, communication, sales):
35
+ new_data = pd.DataFrame({
36
+ 'degree_p': degree_p,
37
+ 'internship': internship,
38
+ 'communication': communication,
39
+ 'sales': sales,
40
+ }, index=[0])
41
+ prediction = rf_mkt.predict(new_data)[0]
42
+ probability = rf_mkt.predict_proba(new_data)[0][1]
43
+ return 'Placed' if prediction == 1 else 'Not Placed', probability
44
+
45
+ # Create input and output components for each model
46
+ fullstk_inputs = [
47
+ gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
48
+ gr.inputs.Radio(label='Internship', choices=[0, 1]),
49
+ gr.inputs.Radio(label='DSA', choices=[0, 1]),
50
+ gr.inputs.Radio(label='Java', choices=[0, 1])
51
+ ]
52
+ fullstk_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
53
+
54
+ prodengg_inputs = [
55
+ gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
56
+ gr.inputs.Radio(label='Internship', choices=[0, 1]),
57
+ gr.inputs.Radio(label='Management Skills', choices=[0, 1]),
58
+ gr.inputs.Radio(label='Leadership Skills', choices=[0, 1])
59
+ ]
60
+ prodengg_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
61
+
62
+ mkt_inputs = [
63
+ gr.inputs.Number(label='Degree Percentage', min_value=0, max_value=100),
64
+ gr.inputs.Radio(label='Internship', choices=[0, 1]),
65
+ gr.inputs.Radio(label='Communication Skills', choices=[0, 1]),
66
+ gr.inputs.Radio(label='Sales Skills', choices=[0, 1])
67
+ ]
68
+ mkt_output = gr.outputs.Label(num_top_classes=2, label='Placement Status')
69
 
70
+ # Create the Gradio app
71
+ fullstk_interface = gr.Interface(
72
+ fn=predict_fullstk,
73
+ inputs=fullstk