import gradio as gr import joblib import numpy as np import os # Get the current file directory current_dir = os.path.dirname(os.path.abspath(__file__)) # Load the trained model from the same directory model_path = os.path.join(current_dir, "trained_model.joblib") model = joblib.load(model_path) # Define the prediction function 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: # Convert the input data to a numpy array 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]]) # Make the prediction prediction = model.predict(input_data) # Map the prediction to department name 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) # Define the Gradio interface 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") # Create the Gradio app app = gr.Interface(fn=predict_department, inputs=inputs, outputs=output, title="Department Predictor") # Launch the app if __name__ == "__main__": app.launch()