Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pickle
|
| 2 |
+
from sklearn.linear_model import LogisticRegression
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
with open('logreg_model.pkl', "rb") as file:
|
| 7 |
+
loaded_model = pickle.load(file)
|
| 8 |
+
|
| 9 |
+
def predict_admission(gre_score, toefl_score, university_rating, sop, lor, cgpa, research, threshold=0.5):
|
| 10 |
+
# Convert 'Yes'/'No' to 1/0 for the 'Research' field
|
| 11 |
+
research = 1 if research == "Yes" else 0
|
| 12 |
+
|
| 13 |
+
# Create an input array from the provided values
|
| 14 |
+
input_data = np.array([[1, gre_score, toefl_score, university_rating, sop, lor, cgpa, research]]) # Added a 1 for the intercept
|
| 15 |
+
|
| 16 |
+
# Make a prediction
|
| 17 |
+
prediction_probability = loaded_model.predict(input_data)[0]
|
| 18 |
+
prediction = 'Admit' if prediction_probability >= threshold else 'No Admit'
|
| 19 |
+
|
| 20 |
+
# Custom formatting for output
|
| 21 |
+
prediction_color = "green" if prediction == 'Admit' else "red"
|
| 22 |
+
result = f"<div style='font-size: 24px; color: {prediction_color}; font-weight: bold; font-family: Arial Black;'>Admission Prediction: {prediction}</div>"
|
| 23 |
+
result += f"<br>Probability: {prediction_probability:.2f}"
|
| 24 |
+
result += f"<br>Threshold Used: {threshold}"
|
| 25 |
+
|
| 26 |
+
return result
|
| 27 |
+
|
| 28 |
+
# Define the Gradio interface
|
| 29 |
+
iface = gr.Interface(
|
| 30 |
+
fn=predict_admission,
|
| 31 |
+
inputs=[
|
| 32 |
+
gr.Number(label="GRE Score"), # Set maximum GRE score
|
| 33 |
+
gr.Number(label="TOEFL Score"),
|
| 34 |
+
gr.Slider(minimum=1, maximum=5, label="University Rating"),
|
| 35 |
+
gr.Slider(minimum=1, maximum=5, label="SOP"),
|
| 36 |
+
gr.Slider(minimum=1, maximum=5, label="LOR"),
|
| 37 |
+
gr.Number(label="CGPA"),
|
| 38 |
+
gr.Radio(choices=["Yes", "No"], label="Research", value="No"),
|
| 39 |
+
gr.Slider(minimum=0, maximum=1, step=0.01, value=0.5, label="Threshold")
|
| 40 |
+
],
|
| 41 |
+
outputs=gr.HTML(label="Prediction"),
|
| 42 |
+
allow_flagging="never"
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
iface.launch()
|