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()