|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
import os |
|
|
|
|
|
current_dir = os.path.dirname(os.path.abspath(__file__)) |
|
|
|
|
|
model_path = os.path.join(current_dir, "trained_model.joblib") |
|
model = joblib.load(model_path) |
|
|
|
|
|
def predict_department(CSC101_total, CSC201_total, CSC203_total, CSC205_total, CSC102_total, |
|
MAT202_total, MAT203_total, MAT103_total, CSC206_total, MAN101_total, |
|
SWE201_total, SWE301_total, SWE303_total, CNE202_total, CNE203_total, |
|
CNE304_total, CSC301_total, CNE302_total, CSC309_total, CSC302_total, |
|
CSC303_total, CNE308_total): |
|
|
|
try: |
|
|
|
input_data = np.array([[CSC101_total, CSC201_total, CSC203_total, CSC205_total, |
|
CSC102_total, MAT202_total, MAT203_total, MAT103_total, |
|
CSC206_total, MAN101_total, SWE201_total, SWE301_total, |
|
SWE303_total, CNE202_total, CNE203_total, CNE304_total, |
|
CSC301_total, CNE302_total, CSC309_total, CSC302_total, |
|
CSC303_total, CNE308_total]]) |
|
|
|
|
|
prediction = model.predict(input_data) |
|
|
|
|
|
department_mapping = {0: 'Swe', 1: 'Cs', 2: 'Cne', 3: 'Ai'} |
|
predicted_department = department_mapping[prediction[0]] |
|
|
|
return predicted_department |
|
|
|
except Exception as e: |
|
return str(e) |
|
|
|
|
|
input_labels = ["CSC101_total", "CSC201_total", "CSC203_total", "CSC205_total", "CSC102_total", |
|
"MAT202_total", "MAT203_total", "MAT103_total", "CSC206_total", "MAN101_total", |
|
"SWE201_total", "SWE301_total", "SWE303_total", "CNE202_total", "CNE203_total", |
|
"CNE304_total", "CSC301_total", "CNE302_total", "CSC309_total", "CSC302_total", |
|
"CSC303_total", "CNE308_total"] |
|
|
|
inputs = [gr.inputs.Number(label=label) for label in input_labels] |
|
output = gr.outputs.Textbox(label="Predicted Department") |
|
|
|
|
|
app = gr.Interface(fn=predict_department, inputs=inputs, outputs=output, title="Department Predictor") |
|
|
|
|
|
if __name__ == "__main__": |
|
app.launch() |
|
|