File size: 2,329 Bytes
6ff936b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import joblib
import gradio as gr

# Load the saved model
gbc = joblib.load('diabetes_model.pkl')  

def prediction(a, b, c, d, e, f, g, h):
    try:
        # Create a DataFrame for the new input
        new_data = [[a, b, c, d, e, f, g, h]]

        # Make a prediction
        result = gbc.predict(new_data)

        # Print the inputs
        input_data = {
            "Pregnancies": a,
            "Glucose": b,
            "BloodPressure": c,
            "SkinThickness": d,
            "Insulin": e,
            "BMI": f,
            "DiabetesPedigreeFunction": g,
            "Age": h,
        }

        print("User Input:", input_data)  # Print inputs to the console

        # Determine the prediction message
        if result[0] == 0:
            prediction_message = "Based on your results, you are not diabetic. Maintain a healthy lifestyle and regular check-ups."
        else:
            prediction_message = "Your results indicate that you are diabetic. Please consult with a healthcare professional for further guidance and management."

        # Return both the prediction and the image URL
        return prediction_message, image_url
    except Exception as e:
        return f"Error: {str(e)}", None  # Return None for the image in case of error

# Example values
example_inputs = [6, 148.0, 72.0, 35.0, 79.799479, 33.6, 0.627, 50]

# Image URL (replace this with a direct image URL)
image_url = "pngtree-world-diabetes-day-raising-awareness-for-a-healthier-future-png-image_14138135.png"

# Create the Gradio interface with a soft theme
app = gr.Interface(
    fn=prediction,
    inputs=[
        gr.Number(label="Pregnancies", value=example_inputs[0]),
        gr.Number(label="Glucose", value=example_inputs[1]),
        gr.Number(label="BloodPressure", value=example_inputs[2]),
        gr.Number(label="SkinThickness", value=example_inputs[3]),
        gr.Number(label="Insulin", value=example_inputs[4]),
        gr.Number(label="BMI", value=example_inputs[5]),
        gr.Number(label="DiabetesPedigreeFunction", value=example_inputs[6]),
        gr.Number(label="Age", value=example_inputs[7])
    ],
    outputs=[gr.Text(label="Prediction"), gr.Image(value=image_url, label="Image", show_label=True)],
    title="Diabetes Prediction",
    theme=gr.themes.Soft()
)

# Launch the app
app.launch()