Ujeshhh commited on
Commit
fac512e
Β·
verified Β·
1 Parent(s): 8ad387d
Files changed (1) hide show
  1. app.py +92 -0
app.py ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import pickle
4
+ import pandas as pd
5
+ from sklearn.preprocessing import StandardScaler
6
+ from sklearn.linear_model import LogisticRegression, Perceptron
7
+ from sklearn.model_selection import train_test_split
8
+ from sklearn.metrics import accuracy_score
9
+
10
+ # Load or train models
11
+ try:
12
+ with open("scaler.pkl", "rb") as scaler_file:
13
+ scaler = pickle.load(scaler_file)
14
+
15
+ with open("logistic_regression.pkl", "rb") as model_file:
16
+ logistic_regression = pickle.load(model_file)
17
+
18
+ with open("perceptron.pkl", "rb") as model_file:
19
+ perceptron = pickle.load(model_file)
20
+
21
+ except FileNotFoundError:
22
+ print("Training models...")
23
+ df = pd.read_excel("Student-Employability-Datasets.xlsx", sheet_name="Data")
24
+ X = df.iloc[:, 1:-2].values
25
+ y = (df["CLASS"] == "Employable").astype(int)
26
+
27
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
28
+
29
+ scaler = StandardScaler()
30
+ X_train_scaled = scaler.fit_transform(X_train)
31
+ X_test_scaled = scaler.transform(X_test)
32
+
33
+ logistic_regression = LogisticRegression(random_state=42)
34
+ logistic_regression.fit(X_train_scaled, y_train)
35
+
36
+ perceptron = Perceptron(random_state=42)
37
+ perceptron.fit(X_train_scaled, y_train)
38
+
39
+ with open("scaler.pkl", "wb") as scaler_file:
40
+ pickle.dump(scaler, scaler_file)
41
+ with open("logistic_regression.pkl", "wb") as model_file:
42
+ pickle.dump(logistic_regression, model_file)
43
+ with open("perceptron.pkl", "wb") as model_file:
44
+ pickle.dump(perceptron, model_file)
45
+
46
+ # Prediction function
47
+ def predict_employability(name, ga, mos, pc, ma, sc, api, cs, model_choice):
48
+ if not name:
49
+ name = "The candidate"
50
+
51
+ input_data = np.array([[ga, mos, pc, ma, sc, api, cs]])
52
+ input_scaled = scaler.transform(input_data)
53
+
54
+ if model_choice == "Logistic Regression":
55
+ prediction = logistic_regression.predict(input_scaled)
56
+ else:
57
+ prediction = perceptron.predict(input_scaled)
58
+
59
+ if prediction[0] == 1:
60
+ return f"{name} is Employable 😊"
61
+ else:
62
+ return f"{name} is Less Employable - Work Hard! πŸ’ͺ"
63
+
64
+ # Gradio UI
65
+ with gr.Blocks() as app:
66
+ gr.Markdown("# Employability Evaluation πŸš€")
67
+ with gr.Row():
68
+ with gr.Column():
69
+ name = gr.Textbox(label="Name")
70
+ ga = gr.Slider(1, 5, step=1, label="General Appearance")
71
+ mos = gr.Slider(1, 5, step=1, label="Manner of Speaking")
72
+ pc = gr.Slider(1, 5, step=1, label="Physical Condition")
73
+ ma = gr.Slider(1, 5, step=1, label="Mental Alertness")
74
+ sc = gr.Slider(1, 5, step=1, label="Self Confidence")
75
+ api = gr.Slider(1, 5, step=1, label="Ability to Present Ideas")
76
+ cs = gr.Slider(1, 5, step=1, label="Communication Skills")
77
+ model_choice = gr.Radio(["Logistic Regression", "Perceptron"], label="Select Model")
78
+
79
+ predict_btn = gr.Button("Get Evaluation")
80
+
81
+ with gr.Column():
82
+ result_output = gr.Textbox(label="Employability Prediction")
83
+
84
+ # Button Click Event
85
+ predict_btn.click(
86
+ fn=predict_employability,
87
+ inputs=[name, ga, mos, pc, ma, sc, api, cs, model_choice],
88
+ outputs=[result_output]
89
+ )
90
+
91
+ # Launch the app
92
+ app.launch(share=True) give me the module name and the requirements.txt