File size: 1,862 Bytes
7d5b0ac
05d6323
7d5b0ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

#https://huggingface.co/spaces/meenon/AdmissionPrediction



import pickle
from sklearn.linear_model import LogisticRegression
import gradio as gr
import numpy as np

with open('logreg_model.pkl', "rb") as file:
    loaded_model = pickle.load(file)
    
def predict_admission(gre_score, toefl_score, university_rating, sop, lor, cgpa, research, threshold=0.5):
    # Convert 'Yes'/'No' to 1/0 for the 'Research' field
    research = 1 if research == "Yes" else 0

    # Create an input array from the provided values
    input_data = np.array([[1, gre_score, toefl_score, university_rating, sop, lor, cgpa, research]])  # Added a 1 for the intercept

    # Make a prediction
    prediction_probability = loaded_model.predict(input_data)[0]
    prediction = 'Admit' if prediction_probability >= threshold else 'No Admit'

    # Custom formatting for output
    prediction_color = "green" if prediction == 'Admit' else "red"
    result = f"<div style='font-size: 24px; color: {prediction_color}; font-weight: bold; font-family: Arial Black;'>Admission Prediction: {prediction}</div>"
    result += f"<br>Probability: {prediction_probability:.2f}"
    result += f"<br>Threshold Used: {threshold}"

    return result

# Define the Gradio interface
iface = gr.Interface(
    fn=predict_admission,
    inputs=[
        gr.Number(label="GRE Score"),  # Set maximum GRE score
        gr.Number(label="TOEFL Score"),
        gr.Slider(minimum=1, maximum=5, label="University Rating"),
        gr.Slider(minimum=1, maximum=5, label="SOP"),
        gr.Slider(minimum=1, maximum=5, label="LOR"),
        gr.Number(label="CGPA"),
        gr.Radio(choices=["Yes", "No"], label="Research", value="No"),
        gr.Slider(minimum=0, maximum=1, step=0.01, value=0.5, label="Threshold")
    ],
    outputs=gr.HTML(label="Prediction"),
    allow_flagging="never"
)

iface.launch()