import gradio as gr import numpy as np from joblib import dump, load # Load the model from disk loaded_logistic_regression_model = load("logistic_regression_model.joblib") print("Model loaded successfully") def predict_survival(Pclass, Sex, Age, SibSp, Parch, Fare, HasCabin, Embarked): # Convert inputs to the correct format Sex = 1 if Sex == 'male' else 0 HasCabin = 0 if HasCabin == 'No' else 1 Embarked = {'S': 2, 'C': 0, 'Q': 1}.get(Embarked, 2) # Create a numpy array from the inputs input_data = np.array([[Pclass, Sex, Age, SibSp, Parch, Fare, HasCabin, Embarked]]) # Use the model to make a prediction prediction = loaded_logistic_regression_model.predict(input_data) # Convert the prediction to a human-readable result result = "Survived" if prediction[0] == 1 else "Did Not Survive" return result # Define the Gradio interface 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." ) # Launch the interface iface.launch()