File size: 2,470 Bytes
58826cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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()