import pickle from sklearn.linear_model import LogisticRegression import gradio as gr import numpy as np with open('logreg_model.pkl', "rb") as file: 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"
Admission Prediction: {prediction}
" result += f"
Probability: {prediction_probability:.2f}" result += f"
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()