Upload 3 files
Browse files- app.py +56 -0
- requirements.txt +5 -0
- trained_model.joblib +3 -0
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
import numpy as np
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Get the current file directory
|
7 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
8 |
+
|
9 |
+
# Load the trained model from the same directory
|
10 |
+
model_path = os.path.join(current_dir, "trained_model.joblib")
|
11 |
+
model = joblib.load(model_path)
|
12 |
+
|
13 |
+
# Define the prediction function
|
14 |
+
def predict_department(CSC101_total, CSC201_total, CSC203_total, CSC205_total, CSC102_total,
|
15 |
+
MAT202_total, MAT203_total, MAT103_total, CSC206_total, MAN101_total,
|
16 |
+
SWE201_total, SWE301_total, SWE303_total, CNE202_total, CNE203_total,
|
17 |
+
CNE304_total, CSC301_total, CNE302_total, CSC309_total, CSC302_total,
|
18 |
+
CSC303_total, CNE308_total):
|
19 |
+
|
20 |
+
try:
|
21 |
+
# Convert the input data to a numpy array
|
22 |
+
input_data = np.array([[CSC101_total, CSC201_total, CSC203_total, CSC205_total,
|
23 |
+
CSC102_total, MAT202_total, MAT203_total, MAT103_total,
|
24 |
+
CSC206_total, MAN101_total, SWE201_total, SWE301_total,
|
25 |
+
SWE303_total, CNE202_total, CNE203_total, CNE304_total,
|
26 |
+
CSC301_total, CNE302_total, CSC309_total, CSC302_total,
|
27 |
+
CSC303_total, CNE308_total]])
|
28 |
+
|
29 |
+
# Make the prediction
|
30 |
+
prediction = model.predict(input_data)
|
31 |
+
|
32 |
+
# Map the prediction to department name
|
33 |
+
department_mapping = {0: 'Swe', 1: 'Cs', 2: 'Cne', 3: 'Ai'}
|
34 |
+
predicted_department = department_mapping[prediction[0]]
|
35 |
+
|
36 |
+
return predicted_department
|
37 |
+
|
38 |
+
except Exception as e:
|
39 |
+
return str(e)
|
40 |
+
|
41 |
+
# Define the Gradio interface
|
42 |
+
input_labels = ["CSC101_total", "CSC201_total", "CSC203_total", "CSC205_total", "CSC102_total",
|
43 |
+
"MAT202_total", "MAT203_total", "MAT103_total", "CSC206_total", "MAN101_total",
|
44 |
+
"SWE201_total", "SWE301_total", "SWE303_total", "CNE202_total", "CNE203_total",
|
45 |
+
"CNE304_total", "CSC301_total", "CNE302_total", "CSC309_total", "CSC302_total",
|
46 |
+
"CSC303_total", "CNE308_total"]
|
47 |
+
|
48 |
+
inputs = [gr.inputs.Number(label=label) for label in input_labels]
|
49 |
+
output = gr.outputs.Textbox(label="Predicted Department")
|
50 |
+
|
51 |
+
# Create the Gradio app
|
52 |
+
app = gr.Interface(fn=predict_department, inputs=inputs, outputs=output, title="Department Predictor")
|
53 |
+
|
54 |
+
# Launch the app
|
55 |
+
if __name__ == "__main__":
|
56 |
+
app.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
joblib
|
3 |
+
numpy
|
4 |
+
starlette
|
5 |
+
scikit-learn
|
trained_model.joblib
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:877b7efded504342b6401a5a1d1dfec178503293384b9fe743f5ac0e275a5898
|
3 |
+
size 2407
|