-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiabetes_project.py
More file actions
55 lines (47 loc) · 1.63 KB
/
Copy pathdiabetes_project.py
File metadata and controls
55 lines (47 loc) · 1.63 KB
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
# -*- coding: utf-8 -*-
"""app.py
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1ryMEIbhOIiyQDhLvzCXtBpTmBQ3vWrTq
"""
import gradio as gr
import pickle
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Load the trained model
with open("model3.pkl", "rb") as f:
model = pickle.load(f)
# Prediction function
def predict_diabetes(pregnancies, glucose, bp, skin, insulin, bmi, dpf, age):
input_data = np.array([[pregnancies, glucose, bp, skin, insulin, bmi, dpf, age]])
prediction = model.predict(input_data)[0]
# Create Seaborn plot
plt.clf()
plt.figure(figsize=(4, 3))
sns.barplot(x=["Diabetes Risk Prediction"], y=[prediction], palette="mako")
plt.title("Model Output")
plt.ylabel("Prediction (0 = No, 1 = Yes)")
plot_path = "prediction_plot.png"
plt.savefig(plot_path)
plt.close()
return int(prediction), plot_path
# Gradio Interface
gr.Interface(
fn=predict_diabetes,
inputs=[
gr.Slider(0, 20, step=1, label="Pregnancies"),
gr.Slider(0, 200, label="Glucose"),
gr.Slider(0, 150, label="Blood Pressure"),
gr.Slider(0, 100, label="Skin Thickness"),
gr.Slider(0, 900, label="Insulin"),
gr.Slider(10.0, 70.0, step=0.1, label="BMI"),
gr.Slider(0.0, 2.5, step=0.01, label="Diabetes Pedigree Function"),
gr.Slider(10, 100, label="Age")
],
outputs=[
gr.Textbox(label="Prediction (0 = No Diabetes, 1 = Diabetes)"),
gr.Image(type="filepath", label="Prediction Plot")
],
title="Diabetes Prediction Based on Health Data"
).launch()