Spaces:
Sleeping
Sleeping
File size: 1,289 Bytes
c202cfd 55f664e c202cfd 55f664e c202cfd 55f664e c202cfd 55f664e c202cfd 55f664e c202cfd 55f664e c202cfd 55f664e c202cfd |
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 |
import gradio as gr
import joblib
import json
import numpy as np
# Load the trained model
model = joblib.load('trained_model_selected.pkl')
# Load feature names
with open('selected_features.json', 'r') as f:
feature_names = json.load(f)
# Define prediction function
def predict_heart_failure(*args):
"""
Predict heart failure likelihood based on input features.
Args:
*args: Input values for each feature.
Returns:
str: Prediction result.
str: Prediction probability as a percentage.
"""
input_data = np.array(args).reshape(1, -1)
prediction = model.predict(input_data)
probability = model.predict_proba(input_data)
result = "Likely" if prediction[0] == 1 else "Unlikely"
return result, f"{probability[0][1] * 100:.2f}%"
# Create Gradio interface
inputs = [gr.inputs.Number(label=feature) for feature in feature_names]
outputs = [
gr.outputs.Textbox(label="Prediction"),
gr.outputs.Textbox(label="Probability (%)")
]
app = gr.Interface(
fn=predict_heart_failure,
inputs=inputs,
outputs=outputs,
title="Heart Failure Prediction",
description="Enter the values for the features to predict the likelihood of heart failure."
)
# Launch the app
if __name__ == "__main__":
app.launch()
|