|
|
| import gradio as gr |
| import numpy as np |
| from joblib import dump, load |
| |
| loaded_logistic_regression_model = load("logistic_regression_model.joblib") |
|
|
| print("Model loaded successfully") |
|
|
|
|
|
|
| def predict_survival(Pclass, Sex, Age, SibSp, Parch, Fare, HasCabin, Embarked): |
| |
| Sex = 1 if Sex == 'male' else 0 |
| HasCabin = 0 if HasCabin == 'No' else 1 |
| Embarked = {'S': 2, 'C': 0, 'Q': 1}.get(Embarked, 2) |
| |
| |
| input_data = np.array([[Pclass, Sex, Age, SibSp, Parch, Fare, HasCabin, Embarked]]) |
| |
| |
| prediction = loaded_logistic_regression_model.predict(input_data) |
| |
| |
| result = "Survived" if prediction[0] == 1 else "Did Not Survive" |
| return result |
|
|
| |
| iface = gr.Interface( |
| fn=predict_survival, |
| inputs=[ |
| gr.Dropdown(choices=[1, 2, 3], label="Pclass"), |
| gr.Radio(choices=["male", "female"], label="Sex"), |
| gr.Number(label="Age"), |
| gr.Number(label="SibSp"), |
| gr.Number(label="Parch"), |
| gr.Number(label="Fare"), |
| gr.Radio(choices=["Yes", "No"], label="Has Cabin"), |
| gr.Dropdown(choices=["S", "C", "Q"], label="Embarked"), |
| ], |
| outputs="text", |
| title="Titanic Survival Prediction", |
| description="Predict whether a passenger on the Titanic would have survived." |
| ) |
|
|
| |
| iface.launch() |
|
|