File size: 1,243 Bytes
55f664e
c48f883
 
b565f0a
c48f883
 
b565f0a
c48f883
 
 
 
b565f0a
c48f883
 
b565f0a
c48f883
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pickle
import pandas as pd

# Load the trained model
model_path = "tuned_model.pkl"

def load_model():
    """Load the model from the pickle file."""
    with open(model_path, "rb") as file:
        return pickle.load(file)

# Prediction function
def predict_with_model(*inputs):
    try:
        model = load_model()  # Load the model dynamically
        # Create a DataFrame for prediction
        input_data = pd.DataFrame([inputs], columns=features)
        # Make prediction
        prediction = model.predict(input_data)
        return f"Prediction: {'Risk of Heart Failure' if prediction[0] == 1 else 'No Risk'}"
    except Exception as e:
        return f"Error during prediction: {str(e)}"

# Features derived from the CSV file
features = ["Feature1", "Feature2", "Feature3"]  # Replace with actual feature names

# Create input sliders
input_sliders = [gr.Slider(0, 100, label=feature) for feature in features]

# Define Gradio interface
iface = gr.Interface(
    fn=predict_with_model,
    inputs=input_sliders,
    outputs="text",
    title="Heart Failure Prediction App",
    description="Adjust the sliders to simulate feature values and predict heart failure risk.",
)

# Launch the app
iface.launch()